We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当前,我们默认会根据系统的 locale 加载翻译,实际使用的是 locale 的 name:
bool DGuiApplicationHelper::loadTranslator(const QString &fileName, const QList<QString> &translateDirs, const QList<QLocale> &localeFallback) { ... for (const auto &locale : localeFallback) { QStringList translateFilenames {QString("%1_%2").arg(fileName).arg(locale.name())};
但这个做法会导致用户的 LANGUAGE 环境变量所设置的 fallback 列表失效。例如用户可能希望优先看到简体中文,如果不存在则看到繁体中文,再否则看到日语,而当前的实现完全不会理会这种偏好设置。
Qt 提供了一个接口来获取这个偏好列表(QLocale::uiLanguages()),但实际,我们只需要使用 QTranslator::load() 传入参数为 QLocale 的重载(bool QTranslator::load(const QLocale &locale, const QString &filename, const QString &prefix = QString(), const QString &directory = QString(), const QString &suffix = QString()))即可使 Qt 主动完成此行为。
QLocale::uiLanguages()
QTranslator::load()
bool QTranslator::load(const QLocale &locale, const QString &filename, const QString &prefix = QString(), const QString &directory = QString(), const QString &suffix = QString())
我们应当调整我们的 loadTranslator() 默认行为,使我们的行为默认尊重用户的语言偏好列表。
不相关
任意应用中使用现有 loadTranslator() 即可复现。测试前需指定 LANGUAGE 环境变量。
我们只使用了用户系统 locale 所对应的语言展示应用程序语言
当 LANGUAGE 偏好列表存在时,我们应当遵守用户的 LANGUAGE 所设的偏好列表
有两个额外的事情可能需要确认:
QList<QLocale>
The text was updated successfully, but these errors were encountered:
No branches or pull requests
SUMMARY | 问题概要
当前,我们默认会根据系统的 locale 加载翻译,实际使用的是 locale 的 name:
但这个做法会导致用户的 LANGUAGE 环境变量所设置的 fallback 列表失效。例如用户可能希望优先看到简体中文,如果不存在则看到繁体中文,再否则看到日语,而当前的实现完全不会理会这种偏好设置。
Qt 提供了一个接口来获取这个偏好列表(
QLocale::uiLanguages()
),但实际,我们只需要使用QTranslator::load()
传入参数为 QLocale 的重载(bool QTranslator::load(const QLocale &locale, const QString &filename, const QString &prefix = QString(), const QString &directory = QString(), const QString &suffix = QString())
)即可使 Qt 主动完成此行为。我们应当调整我们的 loadTranslator() 默认行为,使我们的行为默认尊重用户的语言偏好列表。
DTK and OS VERSIONS | DTK&系统版本信息
不相关
Minimal Reproducible Case Code | 最小复现案例代码
任意应用中使用现有 loadTranslator() 即可复现。测试前需指定 LANGUAGE 环境变量。
OBSERVED RESULT | 观察到的结果
我们只使用了用户系统 locale 所对应的语言展示应用程序语言
EXPECTED RESULT | 期望的结果
当 LANGUAGE 偏好列表存在时,我们应当遵守用户的 LANGUAGE 所设的偏好列表
ADDITIONAL INFORMATION | 额外补充
有两个额外的事情可能需要确认:
QList<QLocale>
参数存在的目的和这个 issue 提及的 uiLanguage() 本意应该重叠了,看看后续是否要调整 API?The text was updated successfully, but these errors were encountered: