> Von: Interest <interest-boun...@qt-project.org> Im Auftrag von Nicholas Yue > Gesendet: Mittwoch, 28. April 2021 18:41 > An: interest@qt-project.org > Betreff: [Interest] Locale detection of Qt application hosted via WASM > > Hi, > > I have the following code (part of a small project) which is being built both > as a standalone executable and a wasm web application. > > They both work except the locale determination. > > On my Linux console, I can set the LANGUAGE environment to de and the > executable will load the correct labels > > However, when I run it wasm web app and connect to it via a German language > OS web browser, it keeps thinking that the locale is still "C" and not "de_DE" > [...] > if (QLocale::system().name().startsWith("de_")) { > if (translator.load(":/language/.qm/cme_de.qm")) {
I don't know whether it fixes your specific problem, but using QLocale::name() / QLocale::system().name() for loading translations is an anti-pattern. There might be people that configure a certain locale because they like the date/time formats there, but still prefer another language for the UI etc. What you should use instead is QLocale::uiLanguages(). Or just pass the locale to QTranslator::load: If (translator.load(QLocale::system(), "cme", "_", ":/language/.qm") Regards Kai _______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest