Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Internationalization issue

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #19364

    Carmelo

    Hello,

    I’m in trouble with translations. I write an app wit all qsTr in Italian and i want to translate my app in english and other languages.

    If i create an en_EN.qm it load successfully and app starts in English but i don’t want it. My os (Android and iOS) are in Italian but app don’t want to change lang. I try to create an it_IT.qm and a en_US instead of en_EN but it wont work.

    I have done these steps:

    • I write my app with all qsTr(“labels”) in Italian
    • I generate a en_EN.ts file in “qml/translations”
    • I released a en_EN.qml file in “qml/translations” and add it in resources.qrc
    • I run the app and all labels are now in english but my os is in Italian
    • I set translation.useSystemLanguage = true
    • After a restart and reinstall app is still in English
    • i try settings.language = ‘it_IT’ but app is still English
    • After settings.language = ‘it_IT’ console.log(settings.language) is ‘en_EN
    • If I delete en_EN and provide a it_IT.qm file and en_US.qm file, console.log(settings.language) is undefined and if i do settings.language=’whatever’, settings.language is still undefined.

    What i’m doing wrong?

    Thanks for any help.

    #19366

    Günther
    Felgo Team

    Hi,

    Did you also add, generate and release translations for your chosen language (it_IT).
    The default language is used as fallback for any other languages.

    You can find more information about localization and translation in this guide:
    https://felgo.com/doc/howto-multi-language/

    For setting the language, you can choose to either:

    • use the system language or
    • set a custom language

    This means that a custom settings.language setup only works when translation.useSystemLanguage is set to false.

    To use your translation files, please make sure to specify valid translations in the *.ts files, e.g.:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE TS>
    <TS version="2.1" language="en_US">
      <context>
        <name>Main</name>
        <message>
          <location filename="../Main.qml" line="15"/>
          <source>Hello World</source>
          <translation>Hello World</translation>
        </message>
      </context>
    </TS>

    When testing if the translations work, please also make sure to create a fresh and clean build:

    • ​Remove previous builds from your device / file system
    • Remove the shadow build directory
    • Right-click the project in Qt Creator and select “Clean”, followed by “Run qmake”
    • Generate translations with lrelease tool.
    • Build and Run your project

    Do translations then work for you?
    ​​
    ​Hope this helps!

    ​Best,
    ​Günther

    #19368

    Carmelo

    Thank you.

    useSystemLanguage = false fix it!

    I do this trick to start with OS lang:

    • On startup:
    translation.useSystemLanguage = false;
     
    if(!settings.getValue("langSettedInApp")){
       settings.language = Qt.locale().name;
    }

     

    • and in my app settings:
    settings.language = 'en_EN'; // locale chosen by user
    settings.setValue("langSettedInApp",true);

     

     

     

    #19950

    GeroldMeisinger

    How do you make this work in Felgo Live? Translations work on device and desktop but not in the simulator.

     

    GameWindowApplicationWindow
    {
        Component.onCompleted:
        {
            console.log( "GameWindowApplicationWindow.onCompleted" )
            translation.useSystemLanguage = false
            settings.language = "en_EN"
            console.log( "language is " + settings.language )
        }
    }
    

    Output is “language is”, thus settings.language is undefined?

    #19970

    Günther
    Felgo Team

    Hi Gerold,

    due to how Translations work with Qt, it is required to compile translations with the app binary. As the Felgo Live Client is a pre-built viewer for your app, it does not contain your translation binaries.

    However, you can also create your own Live Client app. This allows to compile custom C++ code or translations of your project into your own Live Client. These are then available when previewing the QML UI code with your custom Live Client.

    See here for a guide how to build your own Live Client: https://felgo.com/updates/release-2-16-1-live-code-reloading-with-custom-c-and-native-code-for-qt

     

    Best,
    Günther

Viewing 5 posts - 1 through 5 (of 5 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded