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
Titoeuf
Posts: 15
Registered: ‎07-12-2012
My Device: BlackBerry Z10 Limited Edition
My Carrier: Virgin Mobile Canada
Accepted Solution

Dynamic translation with Retranslate

Hi there,

 

I am trying to implement dynamic translation in my app using Retranslate (http://developer.blackberry.com/cascades/reference/bb__cascades__qmlretranslate.html)

 

My translations already work when changing the locale in the device and rebooting the app but I want to be able to change the language directly from my app's settings and that it applies dynamicly to the interface.

 

I do exactly as in the exemple :

 

void MyApp::changeLanguage(const QString &lang){
	QTranslator translator;
	if(translator.load("myapp_" + lang + ".qm", "app/native/qm")){
		Application::instance()->installTranslator(&translator);
		qDebug() << "Translated in " << lang;
	}
	else
		qDebug() << "Failed to translate";
}

 I also added the  "Retranslate.onLanguageChanged" suffix to my labels in qml.

 

From the console I can see that the translator loads correctly as it enters the if. But the text stays in the current language no matter what.

Am I missing a step?

 

Thanks!

Please use plain text.
Developer
Titoeuf
Posts: 15
Registered: ‎07-12-2012
My Device: BlackBerry Z10 Limited Edition
My Carrier: Virgin Mobile Canada

Re: Dynamic translation with Retranslate

Anyone can help me on this?

 

I still haven't found a solution, but will update if I ever find one... Gotta say I moved on other features of my app, putting this one aside for the time being.

Please use plain text.
Developer
jalue
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: Dynamic translation with Retranslate

Hey there..  Perhaps this thread will help you solve your problem..  The solution was provided by ekke..

 

http://supportforums.blackberry.com/t5/Cascades-Development/Translate-dynamically/td-p/1969625

Please use plain text.
Developer
Titoeuf
Posts: 15
Registered: ‎07-12-2012
My Device: BlackBerry Z10 Limited Edition
My Carrier: Virgin Mobile Canada

Re: Dynamic translation with Retranslate

Thanks for the reply!

 

I had already tumbled upon this thread before posting here. At that time I looked into OpenDataSpace code and tests things for hours...

 

Now I re-read that thread and saw that line :


simon_hain wrote:
[...]i used a local variable for the translator, and after the method completed it went out of scope.

That was exactly my problem!!! I was using a local variable.

Decalring the variable global solved the problem. Thanks a lot!

Please use plain text.
Developer
jalue
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: Dynamic translation with Retranslate

It's good that you solved your problem, but you should set your post as the solution though :smileyhappy: 

Please use plain text.