Welcome!

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

Reply
Developer
Posts: 16,524
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
Accepted Solution

Translate dynamically

The i8n sample shows how you update your UI (by calling setText again, basically)

http://blackberry.github.com/Qt-Cascades-Examples-Private/qt-examples/docs/html/tools-i18n.html

 

But what is the signal (global event) you have to connect to trigger this?

The sample application triggers a signal by user interaction, but i would like to adjust my language when the language system settings are changed.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 16,524
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Translate dynamically

I have found
https://developer.blackberry.com/cascades/reference/bb__cascades__qmlretranslate.html


API to locale handler:
 In a QML-defined UI, if you're only required to update text properties, the Retranslate class represents a simpler way of providing dynamic updates.

It does not seem to work though.
This is the code:

Label {
text: qsTr("Please enter your credentials") + Retranslate.onLanguageChanged
}

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 1,629
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Translate dynamically

I'm doing this amd also dynamically changing language from inside the app

 

look at OpenDataSpace

 

have you connected the signal / slot ?

connect(m_LocaleHandler, SIGNAL(systemLanguageChanged()), this,
			SLOT(localeChanged()));

 and then.....

void OpenDataSpace::localeChanged() {
	updateLocale(QLocale().name());
}

 and...

....
Application::instance()->removeTranslator(m_translator);
			Application::instance()->installTranslator(m_translator);
.....

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 16,524
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Translate dynamically

Thanks, i wanted to check out your application anyhow, good opportunity to do that!

My issue was a classic c++ beginner error, i used a local variable for the translator, and after the method completed it went out of scope.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 1,629
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Translate dynamically


simon_hain wrote:
Thanks, i wanted to check out your application anyhow, good opportunity to do that!

My issue was a classic c++ beginner error, i used a local variable for the translator, and after the method completed it went out of scope.

great to hear that it works for you

 

BTW: I cannot count all the C++ beginner errors I did and I'm doing ;-)

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 407
Registered: ‎06-03-2010
My Device: Z10 Red

Re: Translate dynamically

Thanks ekke!

 

Your application made me understand that we can use only one QTranslator, we have to load the "qm" files with only one instance of QTranslator in all the app.

In fact removeTranslator is even not needed.

 

Does not work:

Application::instance()->removeTranslator(oldTranslator);
Application::instance()->installTranslator( newTranslator );

 

Does Work:

Application::instance()->installTranslator(oldTranslator);