From 6711b6f9602a7b90dbfb5ee5ee276a1d9b91d81b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Tue, 17 Sep 2024 15:39:19 +0200 Subject: [PATCH] Add test for language passthrough in wxTranslations Explicitly test that wxTranslations will use a language it doesn't recognize if the OS asks for it and it is available. See 44c24f12ee (Fix GetPreferredUILanguage() on macOS, 2024-09-09) and the discussion in #24804. Closes #24818. --- build/cmake/tests/base/CMakeLists.txt | 2 ++ src/common/uilocale.cpp | 2 -- tests/Makefile.in | 17 +++++++++++++++-- tests/intl/intltest.cpp | 17 ++++++++++++++++- tests/intl/xart-dothraki/internat.mo | Bin 0 -> 302 bytes tests/intl/xart-dothraki/internat.po | 18 ++++++++++++++++++ tests/makefile.gcc | 8 ++++++-- tests/makefile.vc | 6 +++++- tests/test.bkl | 1 + 9 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 tests/intl/xart-dothraki/internat.mo create mode 100644 tests/intl/xart-dothraki/internat.po diff --git a/build/cmake/tests/base/CMakeLists.txt b/build/cmake/tests/base/CMakeLists.txt index 9fb576c1d6..db9c2aa5a8 100644 --- a/build/cmake/tests/base/CMakeLists.txt +++ b/build/cmake/tests/base/CMakeLists.txt @@ -112,6 +112,8 @@ set(TEST_DATA intl/fr/internat.po intl/ja/internat.mo intl/ja/internat.po + intl/xart-dothraki/internat.mo + intl/xart-dothraki/internat.po horse.bmp horse.png horse.xpm diff --git a/src/common/uilocale.cpp b/src/common/uilocale.cpp index 126757a326..e30e0c44d9 100644 --- a/src/common/uilocale.cpp +++ b/src/common/uilocale.cpp @@ -767,13 +767,11 @@ wxVector wxUILocale::GetPreferredUILanguages() if ( ident.IsEmpty() ) { wxLogTrace(TRACE_I18N, "Invalid language code '%s' in WXLANGUAGE", tok); - continue; } if ( !wxUILocale::FindLanguageInfo(ident.GetLanguage()) ) { wxLogTrace(TRACE_I18N, "Unknown language in '%s' in WXLANGUAGE", tok); - continue; } preferred.push_back(ident.GetTag()); diff --git a/tests/Makefile.in b/tests/Makefile.in index 3530c0ee9b..d8275f1a14 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -467,7 +467,7 @@ COND_MONOLITHIC_1___WXLIB_MONO_p = \ ### Targets: ### -all: test$(EXEEXT) $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_gui_bundle___depname) $(__test_allheaders___depname) $(__test_allheaders_bundle___depname) data data-image-sample data-images en_GB fr ja +all: test$(EXEEXT) $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_gui_bundle___depname) $(__test_allheaders___depname) $(__test_allheaders_bundle___depname) data data-image-sample data-images en_GB fr ja xart-dothraki install: @@ -643,6 +643,18 @@ ja: esac; \ done +xart-dothraki: + @mkdir -p ./intl/xart-dothraki + @for f in internat.po internat.mo; do \ + if test ! -f ./intl/xart-dothraki/$$f -a ! -d ./intl/xart-dothraki/$$f ; \ + then x=yep ; \ + else x=`find $(srcdir)/intl/xart-dothraki/$$f -newer ./intl/xart-dothraki/$$f -print` ; \ + fi; \ + case "$$x" in ?*) \ + cp -pRf $(srcdir)/intl/xart-dothraki/$$f ./intl/xart-dothraki ;; \ + esac; \ + done + test_test_rc.o: $(srcdir)/../tests/test.rc $(TEST_ODEP) $(WINDRES) -i$< -o$@ --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_10) $(__DEBUG_DEFINE_p_10) $(__EXCEPTIONS_DEFINE_p_10) $(__RTTI_DEFINE_p_10) $(__THREAD_DEFINE_p_10) --include-dir $(srcdir) $(__DLLFLAG_p_10) --define wxUSE_GUI=0 --include-dir $(top_srcdir)/samples $(__RCDEFDIR_p) --include-dir $(top_srcdir)/include --include-dir $(top_srcdir)/3rdparty/catch/single_include @@ -1301,4 +1313,5 @@ failtest_allheaders: @IF_GNU_MAKE@-include ./.deps/*.d .PHONY: all install uninstall clean distclean test_gui_bundle \ - test_allheaders_bundle data data-image-sample data-images en_GB fr ja + test_allheaders_bundle data data-image-sample data-images en_GB fr ja \ + xart-dothraki diff --git a/tests/intl/intltest.cpp b/tests/intl/intltest.cpp index 6d480404b2..d67afd608f 100644 --- a/tests/intl/intltest.cpp +++ b/tests/intl/intltest.cpp @@ -254,12 +254,13 @@ TEST_CASE("wxTranslations::AddCatalog", "[translations]") SECTION("All") { auto available = trans.GetAvailableTranslations(domain); - REQUIRE( available.size() == 3 ); + REQUIRE( available.size() == 4 ); available.Sort(); CHECK( available[0] == "en_GB" ); CHECK( available[1] == "fr" ); CHECK( available[2] == "ja" ); + CHECK( available[3] == "xart-dothraki" ); } SECTION("French") @@ -342,6 +343,20 @@ TEST_CASE("wxTranslations::GetBestTranslation", "[translations]") CHECK( trans.GetBestTranslation(domain) == "fr" ); CHECK( trans.GetBestAvailableTranslation(domain) == "fr" ); } + + SECTION("PassthroughUnknown") + { + // Check that even a language not known to wx (in this case, made up) + // will be correctly served if it is known to the OS and has available + // translation. + // + // Notice that this would normally be x-art-dothraki, but we + // intentionally use an incorrect code to be future-proof and + // explicitly test for unrecognized passthrough even if wx starts fully + // understanding language tags. + wxSetEnv("WXLANGUAGE", "xart-dothraki:en:fr"); + CHECK( trans.GetBestTranslation(domain) == "xart-dothraki" ); + } } // This test can be used to check how GetBestTranslation() and diff --git a/tests/intl/xart-dothraki/internat.mo b/tests/intl/xart-dothraki/internat.mo new file mode 100644 index 0000000000000000000000000000000000000000..2089093322d5880fd80311f590b8192489c7e705 GIT binary patch literal 302 zcmYj~K}*9x5QQsx+M{O=D|k?JbhA~68*))wDYO_QdX+UDV*rq3!-y(3Z>TmheQu&C+NHNG bjGbQuBdJ^2kn2pY&-{?&elC-vObmVjAQn;R literal 0 HcmV?d00001 diff --git a/tests/intl/xart-dothraki/internat.po b/tests/intl/xart-dothraki/internat.po new file mode 100644 index 0000000000..1bdced1767 --- /dev/null +++ b/tests/intl/xart-dothraki/internat.po @@ -0,0 +1,18 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: \n" +"POT-Creation-Date: 2003-10-04 23:10+0200\n" +"PO-Revision-Date: 2024-02-13 13:25+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: en_GB\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 3d361cfa2a..715712ae76 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -514,7 +514,7 @@ $(OBJS): ### Targets: ### -all: $(OBJS)\test.exe $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_allheaders___depname) data data-image-sample data-images en_GB fr ja +all: $(OBJS)\test.exe $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_allheaders___depname) data data-image-sample data-images en_GB fr ja xart-dothraki clean: -if exist $(OBJS)\*.o del $(OBJS)\*.o @@ -586,6 +586,10 @@ ja: if not exist $(OBJS)\intl\ja mkdir $(OBJS)\intl\ja for %%f in (internat.po internat.mo) do if not exist $(OBJS)\intl\ja\%%f copy .\intl\ja\%%f $(OBJS)\intl\ja +xart-dothraki: + if not exist $(OBJS)\intl\xart-dothraki mkdir $(OBJS)\intl\xart-dothraki + for %%f in (internat.po internat.mo) do if not exist $(OBJS)\intl\xart-dothraki\%%f copy .\intl\xart-dothraki\%%f $(OBJS)\intl\xart-dothraki + $(OBJS)\test_test_rc.o: ./../tests/test.rc $(WINDRES) -i$< -o$@ --define __WXMSW__ $(__WXUNIV_DEFINE_p_10) $(__DEBUG_DEFINE_p_10) $(__NDEBUG_DEFINE_p_10) $(__EXCEPTIONS_DEFINE_p_10) $(__RTTI_DEFINE_p_10) $(__THREAD_DEFINE_p_10) --include-dir $(SETUPHDIR) --include-dir ./../include $(__CAIRO_INCLUDEDIR_p) --include-dir . $(__DLLFLAG_p_10) --define wxUSE_GUI=0 --include-dir ./../samples --include-dir ./../3rdparty/catch/single_include @@ -1213,7 +1217,7 @@ $(OBJS)\test_allheaders_allheaders.o: ./allheaders.cpp $(OBJS)\test_allheaders_testableframe.o: ./testableframe.cpp $(CXX) -c -o $@ $(TEST_ALLHEADERS_CXXFLAGS) $(CPPDEPS) $< -.PHONY: all clean data data-image-sample data-images en_GB fr ja +.PHONY: all clean data data-image-sample data-images en_GB fr ja xart-dothraki SHELL := $(COMSPEC) diff --git a/tests/makefile.vc b/tests/makefile.vc index b5f9fc6a36..c7a9a2ad7b 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -808,7 +808,7 @@ $(OBJS): ### Targets: ### -all: $(OBJS)\test.exe $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_allheaders___depname) data data-image-sample data-images en_GB fr ja +all: $(OBJS)\test.exe $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_allheaders___depname) data data-image-sample data-images en_GB fr ja xart-dothraki clean: -if exist $(OBJS)\*.obj del $(OBJS)\*.obj @@ -887,6 +887,10 @@ ja: if not exist $(OBJS)\intl\ja mkdir $(OBJS)\intl\ja for %f in (internat.po internat.mo) do if not exist $(OBJS)\intl\ja\%f copy .\intl\ja\%f $(OBJS)\intl\ja +xart-dothraki: + if not exist $(OBJS)\intl\xart-dothraki mkdir $(OBJS)\intl\xart-dothraki + for %f in (internat.po internat.mo) do if not exist $(OBJS)\intl\xart-dothraki\%f copy .\intl\xart-dothraki\%f $(OBJS)\intl\xart-dothraki + $(OBJS)\test_test.res: .\..\tests\test.rc rc /fo$@ /d WIN32 $(____DEBUGRUNTIME_2) /d _CRT_SECURE_NO_DEPRECATE=1 /d _CRT_NON_CONFORMING_SWPRINTFS=1 /d _SCL_SECURE_NO_WARNINGS=1 $(__NO_VC_CRTDBG_p_10) $(__TARGET_CPU_COMPFLAG_p_10) /d __WXMSW__ $(__WXUNIV_DEFINE_p_10) $(__DEBUG_DEFINE_p_10) $(__NDEBUG_DEFINE_p_10) $(__EXCEPTIONS_DEFINE_p_10) $(__RTTI_DEFINE_p_10) $(__THREAD_DEFINE_p_10) /i $(SETUPHDIR) /i .\..\include $(____CAIRO_INCLUDEDIR_FILENAMES_2) /i . $(__DLLFLAG_p_10) /d _CONSOLE /d wxUSE_GUI=0 /i .\..\samples /i .\..\3rdparty\catch\single_include .\..\tests\test.rc diff --git a/tests/test.bkl b/tests/test.bkl index 9319287167..977a92d73e 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -443,6 +443,7 @@ +