Skip to content
  • Initial translation language with QTranslator

    Unsolved General and Desktop qtranslator
    8
    0 Votes
    8 Posts
    216 Views
    Paul ColbyP
    Not sure if this is the issue, but worth trying... I see you're using the non-Locale overload of QTranslator::load(), which specifically says: Usually, it is better to use the QTranslator::load(const QLocale &, const QString &, const QString &, const QString &, const QString &) function instead, because it uses QLocale::uiLanguages() and not simply the locale name, which refers to the formatting of dates and numbers and not necessarily the UI language. So try using the locale-overload: https://doc.qt.io/qt-6/qtranslator.html#load-1 For example, here's how I do it in one of my projects: const QLocale locale; QTranslator appTranslator; if (appTranslator.load(locale, u"cli"_s, u"/"_s, u":/i18n"_s)) { QCoreApplication::installTranslator(&appTranslator); } ... qCDebug(lc).noquote() << "Locale:" << locale << locale.uiLanguages(); #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) // QTranslator::filePath() added in Qt 5.15. qCDebug(lc).noquote() << "App translations:" << (appTranslator.filePath().isEmpty() ? u"<none>"_s : appTranslator.filePath()); #else qCDebug(lc).noquote() << "App translations:" << (!appTranslator.isEmpty()); #endif So try something like: const QLocale locale; qDebug().noquote() << "Locale:" << locale << locale.uiLanguages(); QTranslator translator; if (translator.load(locale, ":/qt/....")) { .... } You might also try to calling QmlEngine::retranslate() after the QmlEngine construction?
  • 0 Votes
    5 Posts
    876 Views
    P
    @SGaist said in QMenu And QSqlQueryModel translation problem !: QEvent::LanguageChange @ SGaist Hi bro <3 i didn't know about QEvent::LanguageChange before really thank you, i will check it <3
  • Translated string in multiple languages

    Unsolved General and Desktop qtranslator multilingual
    8
    0 Votes
    8 Posts
    3k Views
    Pablo J. RoginaP
    @Phill parsing the language files and then storing the limited subset I need in a dictionary I don't want to convince you about my idea, but based on my experience it looks like you are heading to re-invent the wheel. A parser for .ts files? A map for "translatable string" KEY -> "translated string" VALUE? Let's see below. (I'm using Python) may be the best option I assume you're using PyQt , if so you have most of the same tools for Qt translations. See here. @mrjj There are tr()/translate() functions (with some caveats) but the idea is the same: all the strings wrapped within tr()/translate() will be copied into .ts files upon using pylupdate5 (lupdate equivalent) if I cant use the QTranslaor that is being used to translate the ui The main thing is that only one translator is used at a time by Qt to translate the UI. You can install tons of translators for the UI with qApp->installTranslator(& aTranslator) but (from Qt documentation): Multiple translation files can be installed in an application. Translations are searched for in the reverse order in which they were installed, so the most recently installed translation file is searched for translations first and the earliest translation file is searched last. The search stops as soon as a translation containing a matching string is found.
  • 0 Votes
    9 Posts
    4k Views
    kshegunovK
    @oberluz No problem, although the merit should go to @SGaist who actually sensed what the problem is. :) Cheers!
  • QTranslator ru-en && UTF-8

    Solved General and Desktop qtranslator utf-8 encoding
    7
    0 Votes
    7 Posts
    3k Views
    0
    @SGaist That is true, thanks!
  • 0 Votes
    32 Posts
    15k Views
    mrjjM
    @mbnoimi Ok, why if I can ask?
  • QTranslator

    General and Desktop qtranslator
    8
    0 Votes
    8 Posts
    3k Views
    A
    #include <QCoreApplication> ....... qApp-> Like a global pointer: QApplication* qApp
  • 0 Votes
    3 Posts
    4k Views
    SGaistS
    Hi and welcome to devnet, Glad you found out and thanks for sharing ! Since you have it working now, please update the thread title prepending [solved] so other forum users may know that a solution has been found :)
  • 0 Votes
    2 Posts
    900 Views
    SGaistS
    Hi and welcome to devnet, Can you share a minimal sample code that shows this behavior ?