diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2021-10-15 06:49:48 +0200 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2021-12-12 16:35:48 +0100 |
commit | d65a7211d47a18a6a8533ebe524e0f69d5d12de1 (patch) | |
tree | 9c86f8aeca73166d497a23e9fba91fb1b48caaec | |
parent | 397ae74674698122b4696ac897e70de439a2d0c9 (diff) | |
download | libgphoto2-d65a7211d47a18a6a8533ebe524e0f69d5d12de1.tar.gz |
Add test-i18n.c i18n test program
-rw-r--r-- | tests/Makefile.am | 8 | ||||
-rw-r--r-- | tests/test-i18n.c | 99 |
2 files changed, 107 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index fd6b6fc04..5eef508a8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,6 +33,14 @@ INSTALL_TESTS_ENVIRONMENT = env \ AM_CPPFLAGS += -I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/libgphoto2_port +# Test i18n +check_PROGRAMS += test-i18n +test_i18n_SOURCES = test-i18n.c +test_i18n_CPPFLAGS = $(AM_CPPFLAGS) +test_i18n_CFLAGS = $(AM_CFLAGS) +test_i18n_LDADD = $(INTLLIBS) + + # Test endianness conversions TESTS += test-endian check_PROGRAMS += test-endian diff --git a/tests/test-i18n.c b/tests/test-i18n.c new file mode 100644 index 000000000..90b27a0be --- /dev/null +++ b/tests/test-i18n.c @@ -0,0 +1,99 @@ +#include "config.h" + +#include <stdio.h> + +#include <locale.h> + +#include "libgphoto2/i18n.h" + + +static +const char *const default_locale_list[] = { + "C", + "", + "en_US", + "en_US.UTF-8", + "en@quot", + "en@quot_US", + "en@quot_US.UTF-8", + "en_US@quot", + "en_US.UTF-8@quot", + "en_US@quot.UTF-8", + "de", + "de_DE", + "de_DE.UTF-8", + "fr", + "fr_FR", + "fr_FR.UTF-8" +}; + + +static +const size_t default_locale_list_count = + sizeof(default_locale_list) / sizeof(default_locale_list[0]); + + +static +void indented_print(char *indentation, char *message) +{ + if (message[0] == '\0') { + printf("%s<no translation>\n", indentation); + return; + } + printf("%s", indentation); + for (char *p=message; *p != '\0'; ++p) { + if (p[0] == '\n') { + putchar(p[0]); + if (p[1] != '\0') { + printf("%s", indentation); + } + } else { + putchar(p[0]); + } + } +} + + +static +void print_locale_list(const size_t list_count, + const char *const *list) +{ + for (size_t i=0; i<list_count; ++i) { + char *locale = setlocale(LC_ALL, list[i]); + if (locale) { + printf("Translated empty string to '%s' (%s):\n", + list[i], locale); + indented_print(" ", + dgettext(GETTEXT_PACKAGE_LIBGPHOTO2, + "")); + setlocale(LC_ALL, "C"); + } else { + printf("Skipping locale: '%s'\n", list[i]); + } + } +} + + +int main(const int argc, const char *const *argv) +{ + bindtextdomain(GETTEXT_PACKAGE_LIBGPHOTO2, LOCALEDIR); + + if (argc > 1) { + const size_t list_counter = (size_t) (argc - 1); + const char *const *list = &(argv[1]); + print_locale_list(list_counter, list); + } else { + print_locale_list(default_locale_list_count, + default_locale_list); + } + + return 0; +} + + +/* + * Local variables: + * mode:c + * c-basic-offset:8 + * End: + */ |