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 if (!m_qtTranslator->load(locale, QLatin1String(
"qt"), QLatin1String(
"_"),
48 QLibraryInfo::path(QLibraryInfo::TranslationsPath))) {
49 m_qtTranslator.reset();
52 m_qmlTranslator.reset(
new QTranslator(
this));
53 if (!m_qmlTranslator->load(locale, QLatin1String(
"qml"), QLatin1String(
"_"),
54 context.toLocalFile() + QLatin1String(
"/i18n"))) {
55 m_qmlTranslator.reset();
59 for (QQmlEngine *engine : std::as_const(m_engines))
60 engine->setUiLanguage(locale.bcp47Name());
63 QCoreApplication::removeTranslator(
this);
64 QCoreApplication::installTranslator(
this);
66 for (QQmlEngine *engine : std::as_const(m_engines)) {
69 engine->retranslate();
71 engine->retranslate();
73 emit languageChanged(locale);
76QString ProxyTranslator::translate(
const char *context,
const char *sourceText,
const char *disambiguation,
int n)
const
81 if (result.isNull() && m_qtTranslator)
82 result = m_qtTranslator->translate(context, sourceText, disambiguation, n);
83 if (result.isNull() && m_qmlTranslator)
84 result = m_qmlTranslator->translate(context, sourceText, disambiguation, n);
85 m_translationFound = !(result.isNull() || result.isEmpty() || result == sourceText);