wbauer added a comment.
In https://phabricator.kde.org/D9793#189494, @safaalfulaij wrote: > I went through Qt code, as Qt applications are opened with my language correctly where KF ones (those with QM) don't. I tested with your ar_BH locale meanwhile, and it is fixed too, i.e. LANGUAGE="ar_BH" didn't work either, and both LANG="ar_BH.UTF-8"/LANGUAGE="" and LANGUAGE="ar_BH" do work now. > The whole issue is that we have each locale's translations in a separate folder (`ar/LC_MESSAGES`, `en/LC_MESSAGES`, `de/LC_MESSAGES`, etc.) Why is this an issue? There's no difference really in loading ar/LC_MESSAGES/xxx.qm and LC_MESSAGES/xxx_ar.qm (or something like that), i.e. you would have the same problem if all translations would be in the same folder. > Qt uses internally `find_translation` <https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qtranslator.cpp#n631> which goes through a list of guesses to find the correct language, according to the LANGUAGE preferences and the locale itself. > Maybe we can borrow that code and utilize it, that would be much better. The only relevant differences I can see is that it replaces all occurences of '-' with '_' (which is necessary only because it gets the languages from QLocale::uiLanguages()), and that it doesn't cut off at the first '_', but creates entries cut off at every one. (i.e. "de_XX_YY" would yield "de_XX_YY", "de_XX" and "de" to try, IIUIC) I could do something similar, i.e. lookup translations in a while loop and cut off at the right-most '_' if a lookup fails until it succeeds. The current code does get the locale/language from Qt anyway. (it calls QLocale::system(), which does respect LANG and LANGUAGE ) It probably would also be a good idea to get a list of languages via QLocale::uiLanguages() instead like that find_translation() function does (that would also support things like LANGUAGE="de:ar"). But that's unrelated to this fix IMHO. REPOSITORY R240 Extra CMake Modules REVISION DETAIL https://phabricator.kde.org/D9793 To: wbauer, #frameworks Cc: safaalfulaij, #build_system