00001 #include "config.h"
00002
00003 #include "i18n.h"
00004 #include <locale.h>
00005
00006 #include <stdio.h>
00007 #include <string.h>
00008
00009 struct _testcase {
00010 char *locale;
00011 char *untranslated;
00012 char *expected;
00013 };
00014
00015 typedef struct _testcase testcase;
00016
00017
00018 static testcase testcases[] = {
00019 { "de_DE.UTF-8",
00020 N_("[DO_NOT_TRANSLATE_THIS_MARKER]"),
00021 "[DO_NOT_TRANSLATE_THIS_MARKER_de]" },
00022 { "C",
00023 N_("[DO_NOT_TRANSLATE_THIS_MARKER]"),
00024 N_("[DO_NOT_TRANSLATE_THIS_MARKER]") },
00025 };
00026
00027 int main(int argc, char *argv[])
00028 {
00029 char *localedir;
00030 int i;
00031
00032 if (argc != 2) {
00033 puts("Syntax: test-nls <localedir>\n");
00034 return 1;
00035 }
00036
00037 localedir = argv[1];
00038
00039 do {
00040 const char *newloc = setlocale(LC_ALL, NULL);
00041 printf("Default locale: %s\n", newloc);
00042 } while (0);
00043
00044
00045 for (i=0; i < sizeof(testcases)/sizeof(testcases[0]); i++) {
00046 char *locale = testcases[i].locale;
00047 char *untranslated = testcases[i].untranslated;
00048 char *expected = testcases[i].expected;
00049 char *translation;
00050
00051 if (1) {
00052 printf("setlocale(\"%s\")\n", locale);
00053 const char *actual_locale = setlocale(LC_MESSAGES, locale);
00054 if (actual_locale == NULL) {
00055 fprintf(stderr, "Error: Cannot set locale to %s.\n", locale);
00056 return 4;
00057 }
00058 printf("new locale: %s\n", actual_locale);
00059 }
00060
00061 if (1) {
00062 const char *basedir = bindtextdomain(GETTEXT_PACKAGE, localedir);
00063 printf("message basedir: %s\n", basedir);
00064 }
00065
00066 if (1) {
00067 const char *domain = textdomain(GETTEXT_PACKAGE);
00068 printf("message domain: %s\n", domain);
00069 }
00070
00071 if (1) {
00072 const char *codeset = bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
00073 printf("message codeset: %s\n", codeset);
00074 }
00075
00076 puts("before translation");
00077 translation = gettext(untranslated);
00078 puts("after translation");
00079
00080 if (strcmp(expected, translation) != 0) {
00081 fprintf(stderr,
00082 "locale: %s\n"
00083 "localedir: %s\n"
00084 "untranslated: %s\n"
00085 "expected: %s\n"
00086 "translation: %s\n"
00087 "Error: translation != expected\n",
00088 locale,
00089 localedir,
00090 untranslated,
00091 expected,
00092 translation);
00093
00094 return 1;
00095 } else {
00096 fprintf(stderr,
00097 "expected: %s\n"
00098 "translation: %s\n"
00099 "Match!\n",
00100 expected,
00101 translation);
00102 }
00103 }
00104 return 0;
00105 }