33QQmlSourceLocation ProxyTranslator::sourceLocationFromInformation(
const TranslationBindingInformation &translationBindingInformation)
35 return QQmlSourceLocation(translationBindingInformation.compilationUnit->fileName(),
36 translationBindingInformation.line,
37 translationBindingInformation.column);
41void ProxyTranslator::setLanguage(
const QUrl &context,
const QLocale &locale)
44 m_currentUILanguages = locale.uiLanguages().join(QLatin1Char(
' '));
46 m_qtTranslator.reset(
new QTranslator());
47 const QStringList qtPaths = QLibraryInfo::paths(QLibraryInfo::TranslationsPath);
49 for (
const QString &path : qtPaths) {
50 ok = m_qtTranslator->load(locale, QLatin1String(
"qt"), QLatin1String(
"_"), path);
55 m_qtTranslator.reset();
57 m_qmlTranslator.reset(
new QTranslator(
this));
58 if (!m_qmlTranslator->load(locale, QLatin1String(
"qml"), QLatin1String(
"_"),
59 context.toLocalFile() + QLatin1String(
"/i18n"))) {
60 m_qmlTranslator.reset();
64 for (QQmlEngine *engine : std::as_const(m_engines))
65 engine->setUiLanguage(locale.bcp47Name());
68 QCoreApplication::removeTranslator(
this);
69 QCoreApplication::installTranslator(
this);
71 for (QQmlEngine *engine : std::as_const(m_engines)) {
74 engine->retranslate();
76 engine->retranslate();
78 emit languageChanged(locale);
81QString ProxyTranslator::translate(
const char *context,
const char *sourceText,
const char *disambiguation,
int n)
const
86 if (result.isNull() && m_qtTranslator)
87 result = m_qtTranslator->translate(context, sourceText, disambiguation, n);
88 if (result.isNull() && m_qmlTranslator)
89 result = m_qmlTranslator->translate(context, sourceText, disambiguation, n);
90 m_translationFound = !(result.isNull() || result.isEmpty() || result == sourceText);