aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Bauer <wbauer@tmo.at>2018-01-17 21:55:53 +0100
committerWolfgang Bauer <wbauer@tmo.at>2018-01-17 21:55:53 +0100
commit78443e0f0373c2b243d75ac37f891879df8ec08b (patch)
treea05b441e3f9dad6ea11d46eed6a6aa8fbb2bd47d
parentbf9840ade0606c4a17b1632974ae361dfd7bbf03 (diff)
downloadextra-cmake-modules-78443e0f0373c2b243d75ac37f891879df8ec08b.tar.gz
extra-cmake-modules-78443e0f0373c2b243d75ac37f891879df8ec08b.tar.bz2
Fall back to language name for translations lookup if locale name fails
For locales like de_AT, the current code only looks in share/locale/de_AT/ and share/locale/de-AT/ for translation catalogs, but not in share/locale/de/ where they most likely are. That's because bcp47Name() returns "de-AT" for de_AT (though in the case of de_DE e.g. it does return "de"). This patch additionally tries to fall back to the general language by taking the part of the locale name before the first '_'. Differential Revision: https://phabricator.kde.org/D9793
-rw-r--r--modules/ECMQmLoader.cpp.in7
-rw-r--r--tests/ECMPoQmToolsTest/check.cmake.in6
2 files changed, 11 insertions, 2 deletions
diff --git a/modules/ECMQmLoader.cpp.in b/modules/ECMQmLoader.cpp.in
index 12a2d146..f636ecc4 100644
--- a/modules/ECMQmLoader.cpp.in
+++ b/modules/ECMQmLoader.cpp.in
@@ -65,7 +65,12 @@ namespace {
QLocale locale = QLocale::system();
if (locale.name() != QStringLiteral("en")) {
if (!loadTranslation(locale.name())) {
- loadTranslation(locale.bcp47Name());
+ if (!loadTranslation(locale.bcp47Name())) {
+ const int i = locale.name().indexOf(QLatin1Char('_'));
+ if (i > 0) {
+ loadTranslation(locale.name().left(i));
+ }
+ }
}
}
}
diff --git a/tests/ECMPoQmToolsTest/check.cmake.in b/tests/ECMPoQmToolsTest/check.cmake.in
index aeef8e42..26320584 100644
--- a/tests/ECMPoQmToolsTest/check.cmake.in
+++ b/tests/ECMPoQmToolsTest/check.cmake.in
@@ -58,16 +58,20 @@ endif()
if("@CMAKE_SYSTEM_NAME@" STREQUAL "Linux")
set(exp_output_catalog_en "english text:english plural form 5")
set(exp_output_catalog_de "german text:german plural form 5")
+ # no de_AT translation -> should fall back to de
+ set(exp_output_catalog_de_AT "${exp_output_catalog_de}")
# no french translation provided -> english fallback
set(exp_output_catalog_fr "${exp_output_catalog_en}")
set(exp_output_catalog2_en "2nd english text:2nd english plural form 5")
set(exp_output_catalog2_de "2nd german text:2nd german plural form 5")
+ # no de_AT translation -> should fall back to de
+ set(exp_output_catalog2_de_AT "${exp_output_catalog2_de}")
# no french translation provided -> english fallback
set(exp_output_catalog2_fr "${exp_output_catalog2_en}")
function(check_translations name exec catalog_name)
- foreach(lang en de fr)
+ foreach(lang en de de_AT fr)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E env "XDG_DATA_DIRS=${ACTUAL_TREE}/share"
LANGUAGE=${lang} "${exec}"