32QQmlSourceLocation ProxyTranslator::sourceLocationFromInformation(
const TranslationBindingInformation &translationBindingInformation)
34 return QQmlSourceLocation(translationBindingInformation.compilationUnit->fileName(),
35 translationBindingInformation.line,
36 translationBindingInformation.column);
40void ProxyTranslator::setLanguage(
const QUrl &context,
const QLocale &locale)
43 m_currentUILanguages = locale.uiLanguages().join(QLatin1Char(
' '));
45 m_qtTranslator.reset(
new QTranslator());
46 if (!m_qtTranslator->load(locale, QLatin1String(
"qt"), QLatin1String(
"_"),
47 QLibraryInfo::path(QLibraryInfo::TranslationsPath))) {
48 m_qtTranslator.reset();
51 m_qmlTranslator.reset(
new QTranslator(
this));
52 if (!m_qmlTranslator->load(locale, QLatin1String(
"qml"), QLatin1String(
"_"),
53 context.toLocalFile() + QLatin1String(
"/i18n"))) {
54 m_qmlTranslator.reset();
58 for (QQmlEngine *engine : std::as_const(m_engines))
59 engine->setUiLanguage(locale.bcp47Name());
62 QCoreApplication::removeTranslator(
this);
63 QCoreApplication::installTranslator(
this);
65 for (QQmlEngine *engine : std::as_const(m_engines)) {
68 engine->retranslate();
70 engine->retranslate();
72 emit languageChanged(locale);
75QString ProxyTranslator::translate(
const char *context,
const char *sourceText,
const char *disambiguation,
int n)
const
80 if (result.isNull() && m_qtTranslator)
81 result = m_qtTranslator->translate(context, sourceText, disambiguation, n);
82 if (result.isNull() && m_qmlTranslator)
83 result = m_qmlTranslator->translate(context, sourceText, disambiguation, n);
84 m_translationFound = !(result.isNull() || result.isEmpty() || result == sourceText);