简体   繁体   English

QTranslator检查

[英]QTranslator checking

How to check which file with translation was loaded ? 如何检查哪个文件已翻译? (Current loaded translation) I load translation in main.c and I would like to check in MainWindow Class which translation was loaded. (当前已加载的翻译)我在main.c中加载了翻译,我想在MainWindow类中检查加载了哪个翻译。

I don't think you can do it, using Qt's methods. 我认为您无法使用Qt的方法来做到这一点。

The best way of doing it would be to write a wrapper around QTranslator and store all loaded translation files in it (you can load more than one translation file at a time). 最好的方法是在QTranslator周围编写一个包装器,并将所有已加载的翻译文件存储在其中(您一次可以加载多个翻译文件)。

Much worse, but easier way is to use a fake translation. 更糟糕但更简单的方法是使用伪翻译。 Something like this: 像这样:

const QString check = tr("lang");
if (check == "en") {
    // it's english
} else if (check == "fr") {
    // it's french
}
...

According to Internationalization with Qt , you anyway get the system locale to load the appropriate translation file. 根据带有Qt的Internationalization ,无论如何,您都会获得系统区域设置以加载适当的转换文件。 Just check the value of the locale string: 只需检查语言环境字符串的值即可:

#include <QLocale>

QString locale = QLocale::system().name();

For example, for English, it is "en", for German - "de". 例如,对于英语,它是“ en”,对于德语,它是“ de”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM