34QQmlSourceLocation ProxyTranslator::sourceLocationFromInformation(
const TranslationBindingInformation &translationBindingInformation)
36 return QQmlSourceLocation(translationBindingInformation.compilationUnit->fileName(),
37 translationBindingInformation.line,
38 translationBindingInformation.column);
42void ProxyTranslator::setLanguage(
const QUrl &context,
const QLocale &locale)
45 m_currentUILanguages = locale.uiLanguages().join(QLatin1Char(
' '));
47 m_qtTranslator.reset(
new QTranslator());
48 const QStringList qtPaths = QLibraryInfo::paths(QLibraryInfo::TranslationsPath);
50 for (
const QString &path : qtPaths) {
51 ok = m_qtTranslator->load(locale, QLatin1String(
"qt"), QLatin1String(
"_"), path);
56 m_qtTranslator.reset();
58 m_qmlTranslator.reset(
new QTranslator(
this));
59 if (!m_qmlTranslator->load(locale, QLatin1String(
"qml"), QLatin1String(
"_"),
60 QQmlFile::urlToLocalFileOrQrc(context)
61 + QLatin1String(
"/i18n"))) {
62 m_qmlTranslator.reset();
66 for (QQmlEngine *engine : std::as_const(m_engines))
67 engine->setUiLanguage(locale.bcp47Name());
70 QCoreApplication::removeTranslator(
this);
71 QCoreApplication::installTranslator(
this);
73 for (QQmlEngine *engine : std::as_const(m_engines)) {
76 engine->retranslate();
78 engine->retranslate();
80 emit languageChanged(locale);
83QString ProxyTranslator::translate(
const char *context,
const char *sourceText,
const char *disambiguation,
int n)
const
88 if (result.isNull() && m_qtTranslator)
89 result = m_qtTranslator->translate(context, sourceText, disambiguation, n);
90 if (result.isNull() && m_qmlTranslator)
91 result = m_qmlTranslator->translate(context, sourceText, disambiguation, n);
92 m_translationFound = !(result.isNull() || result.isEmpty() || result == sourceText);