Skip to content
  • 0 Votes
    4 Posts
    1k Views
    O

    @SGaist thanks. I'll try it there.

  • 1 Votes
    5 Posts
    2k Views
    ekkescornerE

    @SGaist generation of qm files works if at first lupdate was run manually.
    so the part of creation of ts files from
    https://wiki.qt.io/Automating_generation_of_qm_files
    doesn't work as expected

  • 0 Votes
    2 Posts
    1k Views
    P

    Solution:

    inside main.cpp after creating the application object add the following line: QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); inside .pro file add the following line: CODECFORTR = UTF-8
  • 0 Votes
    7 Posts
    2k Views
    E

    Thank you, I will.

    For the time being I am gonna move the label text into source code.

    Cheers for you help!

  • Inverse lupdate

    Unsolved General and Desktop
    1
    0 Votes
    1 Posts
    507 Views
    No one has replied
  • 0 Votes
    3 Posts
    2k Views
    I

    I just replied to you in stackoverflow, your solution is right, I copied my answer too:

    I created a Translator class to organize and load translations, I have a QVariantMap that holds language name and file name, then when I create my Translator I have to provide the source directory since that is a requirement to load translations, my class also takes care of storing in QSettings last language used.

    Now, to answer your question, you can always translate the exact same way as if it was a regular application, on your project file you will have to add something like this:

    1 - List all your possible translations

    TRANSLATIONS = \ translation_sp.ts \ translation_fr.ts

    2 - Run lupdate to generate the actual translation files

    lupdate project.pro

    3 - Run lrelease

    Translate with linguist and create the actual translations, this will generate translation_sp.qm and translation_fr.qm

    4 - Deploy translations with your plugin

    Once you have the qm files deploy them with your plugin, ideally you could standardize the naming, maybe always using plugin_XX.qm

    5 - Load plugin translation in application

    To do this you will have to know the path to the translation file and the filename, so if your plugin is installed in the Qt default directories and you standardized the translation filenames this should be simple

    qTranslator.load("plugin_XX.qm", "PATH_TO_TRANSLATION_FILE") app->installTranslator(qtTranslator);

    I simplified this in my class, here is the source code if you want to take a look

    https://raw.githubusercontent.com/Iktwo/inventory/master/src/translator.cpp
    https://raw.githubusercontent.com/Iktwo/inventory/master/src/translator.h

    And here's how you use it:

    Translator translator(app.data(), "PATH_TO_TRANSLATION"); translator.addTranslation("SP", "plugin_XX.qm"); engine.rootContext()->setContextProperty("translator", &translator);

    You can install multiple translators, so it will work for your application and your plugins, when I wrote my class I was not expecting different sources but you can modify so every time you add a translation it will take a 2 letter code for the language, the filename and the path to it.

    Hope this helps!

  • 0 Votes
    11 Posts
    8k Views
    KiwiJeffK

    @SGaist Fixed it ;)