我们正在使用作为一个新的帮助文件系统。但是,由于我们有一个国际客户群,我们希望以不同的语言启动Qt助手。
从下面的代码片段中可以看到,使用生成的QHC文件启动助手根本不是一个问题。
QProcess a_process;
QStringList a_args;
a_args << "-collectionFile";
a_args << S_HELPFILE_PATH;
a_args << "-enableRemoteControl";
QFile a_assistantExe( S_ASSISTANT_PATH );
if ( a_assistantExe.exists() )
{
a_process.start( S_ASSISTANT_PATH, a_args );
if ( !a_process.waitForStarted() )
return;
}但是,我们如何以不同的语言启动Qt助手呢?即使在互联网上搜索了很长时间之后,我还是没有找到这样的方法。
发布于 2017-07-20 09:46:40
如果您检查Qt (main.cpp)的源代码,您会发现它总是使用系统区域设置:
void setupTranslations()
{
TRACE_OBJ
const QString& locale = QLocale::system().name();
const QString &resourceDir
= QLibraryInfo::location(QLibraryInfo::TranslationsPath);
setupTranslation(QLatin1String("assistant_") + locale, resourceDir);
setupTranslation(QLatin1String("qt_") + locale, resourceDir);
setupTranslation(QLatin1String("qt_help_") + locale, resourceDir);
}要覆盖系统区域设置,只需在启动进程之前设置lang环境变量:
if ( a_assistantExe.exists() )
{
QProcessEnvironment env;
env.insert("lang", "de"); // replace with your current locale
a_process.setProcessEnvironment(env);
a_process.start( S_ASSISTANT_PATH, a_args );
if ( !a_process.waitForStarted() )
return;
}它不仅将改变Qt本身的语言,而且还将使用来自您的.qhc文件的相应翻译版本(<file language="de"></file>,<text language="de"></text>,.)
https://stackoverflow.com/questions/45209840
复制相似问题