← Back to team overview

ubuntu-touch-coreapps team mailing list archive

Re: [Clock] How to transfer translations between C++ / QML

 

Hi Bartosz,

First of all, I'd recommend checking out the Qt5 docs for that: http://doc.qt.io/qt-5/qtqml-tutorials-extending-qml-example.html ;)

Secondly, I can assure you that this won't be so hard once you have understood the concept. ;)

If you already have an existing object which holds the QMap of translations, I'd pass that one to QML instead of registering a type as it is described in the tutorial you linked to. A type would do the trick as well but it would be "too much" if you already have an object. (If that QMap is held by a type which you already access in QML, ignore this line.) Here's the docs entry: http://doc.qt.io/qt-5/qtqml-cppintegration-contextproperties.html

Then create a public method in your C++ class which returns the city name when passing the city id. Prefix the method declaration in the header file with "Q_INVOKABLE" and you'll have access to it in QML. You'll maybe also need a method which returns all possible city ids but the approach will be the same for that one (as long as the list doesn't change and you don't want to use property bindings, in which case exposing the list using a Q_PROPERTY would be needed). Check this out for a better overview: http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html ;)

Regarding the choice of a QMap, you're right that this one is much better, hence the phrase "in the worst case" in my last email. ;)

If you have any further questions, feel free to ask. :)

Cheers,
Niklas

PS: Adding the list again because it might actually help some other people as well.

Am Di, 4. Aug, 2015 um 3:12 schrieb Bartosz Kosiorek <gang65@xxxxxxxxxxxxxx>:
Hi Niklas.

My idea is to:
Instead of QList of cities, I would like to use QMap of cities:

QMap<QString, TimeZone> citiesMap;

Where TimeZone will be struct, with following fields:
  QString cityName;  //localized city name
  QString country;     //localized country name
  QTimeZone timeZone;

With using QMap, I don't need to reiterate whole container, and I will receive city data very fast.
What do you think about that idea?

I need to learn how to connect Qt/C++ and QML to properly get data from C++ code.
http://doc.qt.io/qt-4.8/qml-extending-tutorial-index.html

Best Regards
Bartosz


2015-08-03 20:57 GMT+02:00 Niklas Wenzel <nikwen.developer@xxxxxxxxx>:
Hi Bartosz,

I just came online on IRC but I couldn't find you there. That being said, it's quite difficult for me at the moment to come online at fixed times unless it's at the weekend. Therefore, I'd really prefer using email. I'm just struggling with seeing why (in the worst case) you can't use a for loop to iterate over every entry of the city list and check if its id matches the given one which you want to find out the city name for.

Cheers
Niklas

2015-08-02 23:42 GMT+02:00 Bartosz Kosiorek <gang65@xxxxxxxxxxxxxx>:
Hello Niklas.

Can we discuss about that on hangout or irc?
I would really get advice from you about that.

Best Regards
Bartosz

2015-08-02 14:00 GMT+02:00 Niklas Wenzel <nikwen.developer@xxxxxxxxx>:
Hi Bartosz,

I really tried to understand this, but I fail to see what hinders you from using the list to which I saw you have already added city IDs for retrieving the city name. What's the problem with writing a method which queries that model for the city name?

Cheers,
Niklas

2015-07-31 22:30 GMT+02:00 Bartosz Kosiorek <gang65@xxxxxxxxxxxxxx>:

Hello everyone,

In the Clock App, we maintain a list of about 250 popular/commonly used locations which have been translated to various languages. The user sees this list when opening the add-world-city page where he can choose which cities to add to the main clock page. The cities he add are stored in the user-database file.

Recently we found an issue in the Clock app that results in the added user city names not being translated when switching the system language. It became apparent that user added locations are stored in the database as translated strings. Thereby when the user switches the phone language, the previously translated strings are retrieved from the database and shown in the UI in the language previously used by the user.

Steps to reproduce the bug,
1. Assuming your phone is used with Language A, open clock app and add few locations.
2. Change phone language to B.
3. Open Clock App

What happens:
4. Notice how the added cities are shown in Language A

What is expected:
4. Previously added cities are shown in Language B

Bug report:
https://bugs.launchpad.net/ubuntu-clock-app/+bug/1477492

The location is stored with following format:

  "worldlocation":
  {
     "city": city,
     "country": country,
     "timezone": timezone
  }

In that case "city" is the stored localized name. It is causing the above issue.

My idea is to store the "cityID" instead of the localized "city". "CityID" will be untranslated universal names like "london", "berlin". I have created branch, in which I'm storing "cityId" instead of localized city names. The idea is to then use this "CityID" and then return the translated cityNames on the fly.

My question is how do I use the generic "cityID" to retrieve the translated city names from the popular city location list mentioned above? I understand the situation is a bit difficult to understand. If you have any further questions about this situation, I can try explaining in more detail.

Thanks in advance
Bartosz


--
Mailing list: https://launchpad.net/~ubuntu-touch-coreapps
Post to     : ubuntu-touch-coreapps@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~ubuntu-touch-coreapps
More help   : https://help.launchpad.net/ListHelp






References