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
SuhairZain
Posts: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
Accepted Solution

how to add localization support?

Hi, I tried using tr(), including every text within it. But it doesn't work. Any idea how to do it?
Please use plain text.
Developer
greenmr
Posts: 882
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

Re: how to add localization support?

You haven't given us anything to work with. Please provide a code sample, as well as a description of what you mean by "it doesn't work". Does the compiler complain? Does it compile but you aren't getting any of your strings in your .tr file? Do you get a .tr file but when you edit it for another language/locale it is not showing up properly?

 

Are you doing this in C++ or QML? If QML you need to use qsTr() instead of tr().

 

You won't get much help with such a vague question.

 


SuhairZain wrote:
Hi, I tried using tr(), including every text within it. But it doesn't work. Any idea how to do it?





Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: how to add localization support?

These two links should tell you everything you need to know...

 

http://developer.blackberry.com/native/documentation/cascades/device_platform/internationalization/l...

 

http://developer.blackberry.com/native/reference/cascades/i18n-source-translation.html


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
SuhairZain
Posts: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B

Re: how to add localization support?

this is how i use it:

 

QString labelText;

 

labelText = tr("Click here to continue!");

 

Label myLabel;

myLabel.setText(labelText);

 

what might be wrong? Do i need to add supported languages in bar-descriptor.xml?

Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: how to add localization support?

What is the problem exactly?

 

Are you not seeing the text or that you are expecting a translation of the word?


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
bmorr
Posts: 322
Registered: ‎04-13-2013
My Device: Z10

Re: how to add localization support?

[ Edited ]

Looks like you've done all the necessary steps with regards to the QML and tr files.  But just to reiterate for others who come to this post looking for information, you need to make your text into a qstring and tell the UI to retranslate it based on whether the device's language change, whether the language or locale changed or whether just on locale change.

 

text: qsTr("I like turtles") + Retranslate + onLanguageChanged

 next you have to go into your translations folder and open your .ts files.  You will see this:

 

    <message>
        <location filename="../src/app.cpp" line="180"/>
        <source>Close</source>
        <translation type="unfinished"></translation>
    </message>

 You need to add your translation so that the UI knows what to replace the word with based on your .ts

 

    <message>
        <location filename="../src/app.cpp" line="180"/>
        <source>Close</source>
        <translation>Cerrar</translation>
    </message>

Now you just have to add some stuff to your source code:

 

Add this to your application UI.cpp:

 

#include <bb/cascades/LocaleHandler>

 

add this in your main Application UI in your cpp right after the opening bracket:

 

m_pTranslator = new QTranslator(this);
m_pLocaleHandler = new LocaleHandler(this);

 Then make a connection to the translation function you're going to create:

 

 if(!QObject::connect(m_pLocaleHandler,
SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()))) { // This is an abnormal situation! Something went wrong! // Add own code to recover here qWarning() << "Recovering from a failed connect()"; } onSystemLanguageChanged();

 create the translation function:

 

void App::onSystemLanguageChanged()
{
    QCoreApplication::instance()->removeTranslator(m_pTranslator);
    // Initiate, load and install the application translation files.
    QString locale_string = QLocale().name();
    QString file_name = QString("persistentobjects_%1").arg(locale_string);
    if (m_pTranslator->load(file_name, "app/native/qm")) {
        QCoreApplication::instance()->installTranslator(m_pTranslator);
    }
}

 now in your applicationui hpp add:

 

#include <bb/cascades/LocaleHandler>

as well as:

 

namespace cascades {
class LocaleHandler;
class Application;

under your Q_INVOKABLE stuff add:

 

private slots:
       void onSystemLanguageChanged();

 

 and add the translator:

 

QTranslator* m_pTranslator;
        	bb::cascades::LocaleHandler* m_pLocaleHandler;

 if there is already a translator (most likely) just put the bb::cascades::LocaleHandler* m_pLocaleHandler; underneath it.

 

 

This should be all.  I'm not sure if this is the textbook way to do it, but this is what worked for me based on looking at other samples and reading support posts.

 

hope it works!

Please use plain text.
Developer
SuhairZain
Posts: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B

Re: how to add localization support?

actually, i was hoping some way in which the IDE automatically does the conversion part for us. Anything such?

Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: how to add localization support?

[ Edited ]

If you mean having to avoid a translation agency and just have the phone do it then no.

The only way I could think to do this is to tie in with one of the online translation services such as Google Translate.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: how to add localization support?

@SuhairZain bmorr spend quite a fair amount of time to give you a comprehensive answer, it's good you marked it as the solution but please also click on the like button so he gets some recognition, you'll notice I also did as his answer was well constructed and obviously took time to write.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
bmorr
Posts: 322
Registered: ‎04-13-2013
My Device: Z10

Re: how to add localization support?

the ide won't translate for you automatically (otherwise all our apps would support all languages!)  Just take into account the amount of wording you will have in your app so that you can cut down on translating them.  Maybe a few phrases can sufficiently explain somethign rather than a paragraph, etc.  If you have small phrases google translate is fairly good at translating if that's your concern.  I would be cautious about using it for long phrases or paragraphes though.  IMO.

Please use plain text.