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.
This commit is contained in:
Václav Slavík
2024-09-20 17:52:46 +02:00
committed by Vadim Zeitlin
parent 6418bc261d
commit 6711b6f960
9 changed files with 63 additions and 8 deletions
+2
View File
@@ -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
-2
View File
@@ -767,13 +767,11 @@ wxVector<wxString> 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());
+15 -2
View File
@@ -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
+16 -1
View File
@@ -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
Binary file not shown.
+18
View File
@@ -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 <EMAIL@ADDRESS>, 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"
+6 -2
View File
@@ -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)
+5 -1
View File
@@ -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
+1
View File
@@ -443,6 +443,7 @@
<wx-data id="en_GB" template="catalog"/>
<wx-data id="fr" template="catalog"/>
<wx-data id="ja" template="catalog"/>
<wx-data id="xart-dothraki" template="catalog"/>
<fragment format="autoconf">