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: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Create a localized ListView

[ Edited ]

Okay found a way to make dynamic text work, with the use of the macro QT_NR_NOOP;

 

 QString FriendlyConversation::greeting(int type)
 {
     static const char *greeting_strings[] = {
         QT_TR_NOOP("Hello"),
         QT_TR_NOOP("Goodbye")
     };
     return tr(greeting_strings[type]);
 }

 This will collect the strings for you, avoiding the need to manually edit the .ts file.

 

However this still doesn't help you with text in XML files as you'd need to duplicate the data again within the source code.

 


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

Re: Create a localized ListView

[ Edited ]

oh, I see our conversation is getting a bit involved, but thanks for participation anyway.

 

>>"Sorry but the only other language I can work in is Japanese and BB10 doesn't support it, my girlfriend speaks French and Hindi but she's not here and wouldn't be interested in what we are doing anyway. :smileyvery-happy:"

Smiley Happy))))

 

I will try to play with it a little bit. Just I will say this once more: I think the only way that

a translation entry will be created in the .ts file is by adding a keyword (e.g., tr("helloworld")) in the source code.

I think you can't add a random keyword in the .ts file and add a translation to it, if the keyword is

not specified in the source code.

 

About your solution using QT_NR_NOOP, it uses C++ still right? What if I want to do it in QML?

 

Anyway, I will brief you why/how I came to this problem. I have a ListView which has a XML Data Model,

but I also want ListView items to be translatable. So, if I can create a ListView in QML by specifying

datamodel from sourcecode (e.g., manually adding QStrings), then I think I will not have the same problem anymore.
 For example I found this: http://developer.blackberry.com/cascades/documentation/ui/lists/arraydatamodel.html - but I can't see how I can add "headers" using this data model, maybe you know? (I could open a separate thread on it, but if you could help here, would be also nice Smiley Happy).

 

 ant btw. by duplicated data items you mean that duplicates will be created: one in XML file and another in source code?

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Create a localized ListView

I've lost the page I got that from now, if I find it again I'll post the link, I don't remember seeing a QML option no.

 

I'm pretty sure currently only GroupDataModel allows headers.

 

Yes duplicated data means having to put the dynamic text in the source code as well so the IDE can pick it up to put it in the .ts file.

 

 


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Create a localized ListView

Found it,

 

http://developer.blackberry.com/cascades/reference/internationalization.html

 

and as I thought no QML option.

 


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

Re: Create a localized ListView

[ Edited ]

>>I'm pretty sure currently only GroupDataModel allows headers.

 

This is really strange. We know GroupDataModel automatically

sorts data (based on headers - right?), what if I want headers

in my ListView - but no sorting? What to do in this case?

I may implement my ListView in C++ too, but the issue I mentioned

above I think I will encounter there too.

 

This makes me think, that XML is the only *viable* data model

if one wants to achieve what I want?

 

With XML I could add headers as I want, but my data in the

XML can also come from run time, is it ok to use XML

as a data model if my data comes at run time? (I've read

somewhere that XML could be used as a data model,

when the ListView data is static - does not come at run time

-- would this be true?).

 

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Create a localized ListView

[ Edited ]

You can hack the other models to approximate headings but that's for another thread as we are rapidly going off topic now. Smiley Happy

 

Close this thread off by marking one of the posts as a solution and start another one about datamodels. I'll join you there.  Smiley Happy

 


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

Re: Create a localized ListView

Ok, but to sum up, did we come to these conclusions ? Smiley Happy))

 

- if you are using QML, and XML as data model for a ListView there is no

easy way to add translation to your app? (the only one being the hack approach

by creating duplicate entries which we mentioned, and which I didn't test yet.

hmm.. This seems strange quite some limitation).

 

- If I want to have a ListView which has unsorted headers - also what

to do in this case? Seems ArrayDataModel and GroupDataModel would not work.

 

Ok, I will do as you suggest.

 

>> "I'll join you there"
See you laters.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Create a localized ListView

Don't forget option 3 which I think is easy;

 

Just check for the local language and select a different XML file for that language.

 

 


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

Re: Create a localized ListView

[ Edited ]

 >>"Just check for the local language and select a different XML file for that language."

 

Yes, that sounds nice. But can I use XML as a DataModel even if data comes on run time?

 

 I was thinking how to use XML approach still because it defeats the problem

I have with unsorted headers - using XML I can create unsorted headers in a ListView

(hopefully, I can use XML as a DataModel in ListView in C++ too?).

 

The only problem that remains with XML is translation - but maybe opton 3 will do the work.

I think I could even tolerate duplicates (as in some cases data is not big in XML file), given that duplicats + this QTR_TR_NOOP approach will work:

 

 QString FriendlyConversation::greeting(int type)
 {
     static const char *greeting_strings[] = {
         QT_TR_NOOP("Hello"),
         QT_TR_NOOP("Goodbye")
     };
     return tr(greeting_strings[type]);
 }

 

 

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Create a localized ListView

It really depends on what you mean by 'comes on run time' do you mean from an external source?

If so then that is no problem.

 


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

Developer of stokLocker, Sympatico and Super Sentences.