text: This is your resource to discuss support topics with your peers, and learn from each other.
  09-28-2013 11:19 AM
  Solved! Go to Solution.
  09-28-2013 11:33 AM
  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?
  09-28-2013 12:06 PM
  These two links should tell you everything you need to know...
  09-29-2013 09:16 AM
  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?
  09-29-2013 10:02 AM
  What is the problem exactly?
  Are you not seeing the text or that you are expecting a translation of the word?
  09-29-2013 11:42 AM - edited 09-29-2013 11:49 AM
  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_p
  Translator); // Initiate, load and install the application translation files. QString locale_string = QLocale().name(); QString file_name = QString("persistentobjects_%1").arg(locale_string)Translator); // 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_; if (m_pTranslator->load(file_name, "app/native/qm")) { QCoreApplication::instance()->installTranslator(m_ pTranslator); } }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!
  10-01-2013 07:29 AM
  actually, i was hoping some way in which the IDE automatically does the conversion part for us. Anything such?
  10-01-2013 07:39 AM - edited 10-01-2013 07:40 AM
  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.
  10-01-2013 07:44 AM
  @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.
  10-01-2013 10:28 AM
  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.