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

Forums

OverviewFelgo 2 Support (Qt 5) › QML dynamic translation causes app to resize

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #21752

    Marek

    Hi Felgo

    I have prepared small app to show the problem, it is visible on Android (tested on Android 7.0)

    When I do QQMlEngine->retranslate application changes its size, like a half of the screen

    before: https://github.com/frankipl/translate-test/blob/master/before_translate.png

    after: https://github.com/frankipl/translate-test/blob/master/after_translate.png

    Here is app source code

    https://github.com/frankipl/translate-test

    I’m not sure, maybe this is Qt related, or I’m doing something wrong.

    Please help

    Best,

    Marek

    #21789

    Marek

    Hi Felgo,

    Could you please take a look at this problem ?

    I have created similar application using just Qt (5.12.3) and I have no problem with dynamic translations, application does not resize.

    Code is available here: https://github.com/frankipl/translate-qt-test

    Best,

    Marek

    #21879

    Christian
    Felgo Team

    Hi Marek,

    I have just tested your example project on my device (LG V10) and an Android emulator (Android 8.0) and your problem did not occur, the app did not change size.

    Please provide more information for us: What device are you testing on? What Android OS version? Which Felgo SDK version (newest is 3.2.0 with Qt 5.12.3)?

    Also, Felgo provides another way to use re-translation, as mentioned in the docs: https://felgo.com/doc/howto-multi-language/#localize-your-app-or-game

    You can add

    + translation.language

    to a binding, which is an empty property but it causes the property binding to re-evaluate when the language changes. Then you don’t need to call the retranslate() function.

    Cheers,
    Chris

    #22123

    Marek

    Hi Christian

    Sorry for late reply. I have tested just now (I added CONFIG += c++14 and NOSTDLIB for Android) to pro file

    https://github.com/frankipl/translate-test

    Problem still exists.

    I’m testing on phone Zenfone 3 Max 5.2 with Android 7.0 I have Felgo 3.2.0-1 release 2019-08-01 NDK android-ndk-r20

    My friend was also testing this on his Felgo installation and with Android 9 and result is the same.

    When I use Felgo way to translate (you have described) and do not call retranslate then it works

    Best,

    Marek

    #22738

    Tim Schon Wieder

    Hi Marek, hi Felgo team,

    I do have the same problem. It only occurs on some devices but not others as I can see in the Google Play Pre-Launch Report. I can’t recognize any patterns in the brand or Android version (beside others, it works on an S9 with Android 8.0 and Mate 9 with 7.0 but not on an Moto Z with 7.0 nor on a Pixel 2 or 3 with 8.1 or 9.0).

    Is it somehow possible to use QQmlApplicationEngine::retranslate() anyway? If not, could you explain why not?

    Best

    Tim

    #22739

    Marek

    Hi Tim

    I don’t know the cause of the problem, I just did translations with the method described by Christian. Since then I have made 3 applications using that method and didn’t have any problems. It requires you to add translation.language property to each qsTr() but otherwise it works.

    Best,

    Marek

    #24400

    Abhilash
    #ifndef AAHARLANGUAGES_H
    #define AAHARLANGUAGES_H
    
    #include<QLocale>
    #include<QObject>
    
    class AaharLanguages : public QObject
    {
        Q_OBJECT
    public:
        AaharLanguages() {}
    
        enum AaharLangs{
            Hindi = QLocale::Hindi,
            Gujrati = QLocale::Gujarati,
            English = QLocale::English,
            Marathi = QLocale::Marathi,
            Sanskrit = QLocale::Sanskrit
        };
    
        Q_ENUM(AaharLangs)
    
        virtual ~AaharLanguages() {}
    };
    
    #endif // AAHARLANGUAGES_H
    

    C++ File

    #ifndef AAHARTRANSLATOR_H
    #define AAHARTRANSLATOR_H
    
    #include<QObject>
    #include<QApplication>
    #include<QTranslator>
    #include<AaharLanguages.h>
    
    class AaharTranslator : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QString emptyString READ getEmptyString NOTIFY emptyStringChanged)
    
    public:
        AaharTranslator(QApplication *app) { aaharApp = app; }
    
        QString getEmptyString(){ return ""; }
    
    //    virtual ~AaharTranslator() {}
    
    signals:
        void emptyStringChanged();
    
    public slots:
        void updateLanguage(int language){
            switch (language) {
            case AaharLanguages::Marathi:
                mTranslate.load("IN_Marathi",":/translator");
                aaharApp->installTranslator(&mTranslate);
                break;
            case AaharLanguages::Sanskrit:
                mTranslate.load("IN_Sanskrit",":/translator");
                aaharApp->installTranslator(&mTranslate);
                break;
            case AaharLanguages::Hindi:
                mTranslate.load("IN_Hindi",":/translator");
                aaharApp->installTranslator(&mTranslate);
                break;
            case AaharLanguages::Gujrati:
                mTranslate.load("IN_Gujrati",":/translator");
                aaharApp->installTranslator(&mTranslate);
                break;
            default:
                aaharApp->removeTranslator(&mTranslate);
                break;
            }
            emit emptyStringChanged();
        }
    
    private:
        QApplication *aaharApp;
        QTranslator mTranslate;
    };
    
    #endif // AAHARTRANSLATOR_H
    

    Add QML Registry in Main.CPP File :

     qmlRegisterType<AaharLanguages>("AaharLanguages",1,0,"AaharLanguages");
    AaharTranslator translate(&app);
     engine.rootContext ()->setContextProperty ("AaharTranslator",(QObject*)&translate);

    Now Import Languages :

    import AaharLanguages 1.0

    Then Add This type of EmptyString to every qsTr() Function :

    qsTr("<h1> Hurrey..! <br>New Update Available.</h1>")+AaharTranslator.emptyString

    this EmptyString Has Event in C++ File so whenever you change language All String will be updated.! I was facing the same problem even I have to Include 50+ Languages in my code As I belong to Incredible India. Here We have more than 2500 Major Local Languages.!

    Retranslate of QMLEngine Will change your layout and Still, I found nothing to Re-State All the Components so for now UseThis Code block.!

    Happy Coding Bandhu.!

Viewing 7 posts - 1 through 7 (of 7 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