Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 48
Registered: ‎08-07-2013
My Device: z10
My Carrier: blackberry

change language of app based on selected language



    in my app,i want to change the language.i used localization.it works very well,but my requirement is that.my app consists of a dropdown to select the language when certain language is selected the app has to transulate in that language.


    when i used localization i'm able to transulate by changing the settings of the device,but in my app i have to change the language with in the app itself.  please help me..


thank you

BlackBerry Development Advisor
Posts: 50
Registered: ‎09-27-2012
My Device: Passport
My Carrier: Bell

Re: change language of app based on selected language

[ Edited ]

From what you described, I think you need to listen to the language change and dynamically load the translator based on the change. There are two settings in Device>Settings>Language and Input.  Language and Region.  I am assuming that you are changing the "Language" setting to load translated UI strings for your app.


Check out the code snippet below to handle translations dynamically based on the language settings on the device.

Also, feel free to msg me if you have any questions.


In your application source code, the private section of the class should have the following:

    QTranslator translator;
    bb::cascades::LocaleHandler localeHandler;
Add the following slots as well.

// Called when the system language is changed
void ApplicationUI::onSystemLanguageChanged() {
QString locale_string = QLocale().name();     QString filename = QString( "HelloTrans_%1" ).arg( locale_string );     if (translator.load(filename, "app/native/qm")) {         QCoreApplication::instance()->installTranslator(&translator);     } } // Called when new translators are installed (for testing) // Update all your labels, text areas, etc., void ApplicationUI::onLanguageChanged() {   qDebug() << "onLanguageChanged() called";   someLabel->setText(tr("translate me")); }


And finally, put the following code in the constructor of the class to hook it all up and initialize the translator:

    QObject::connect(&localeHandler, SIGNAL(systemLanguageChanged()),
                     this, SLOT(onSystemLanguageChanged()));
    QObject::connect(&localeHandler, SIGNAL(languageChanged()),
                     this, SLOT(onLanguageChanged()));

Hope this was helpful. Happy Coding!
EK @echotown
Posts: 358
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: change language of app based on selected language

I responded to a previous quesiton on here with a step-by-step tutorial.  It seemed to help so I created a PDF of it here: https://s3-us-west-2.amazonaws.com/appstuffbmo/Localization+Tutorial.pdf


Hope it helps.