Page 1 of 1

i18n message in specific language

PostPosted: Tue Nov 07, 2017 12:14 pm
by gk1441607435
I need to get an i18n message in an other language than the language of the logged-in user.

I was looking for a function like this

Code: Select all
i18n.getI18NMessage(i18nKey, langCode);
var textInFrech = i18n.getI18NMessage('my.18n.text', 'fr');


but there was nothing like this.

Of course I could set the user language and switch back after I got my message

Code: Select all
i18n.setLocale('fr', 'FR');
var textInFrech = i18n.getI18NMessage('my.18n.text', 'fr');
i18n.setLocale('en', 'US');


but I don't want to do this. If something went wrong the user is lost in a french programm :shock:

Has anyone an other idea, how to get the message for a specific language?


Thanks Gregory

Re: i18n message in specific language

PostPosted: Tue Nov 07, 2017 4:35 pm
by mboegem
Hi Gregory,

it's exactly the way you describe, but I could understand your concern.

Since all the messages are in a table (once deployed) you could just query the value.
Something like this:
Code: Select all
SELECT COALESCE(l.message_value, d.message_value)
FROM my_message_table d
LEFT JOIN my_message_table l ON d.message_key = l.message_key AND l.message_language = ?
WHERE d.message_key = ? AND d.message_language IS NULL


Just create a global/scope function that takes the parameters you want (key + language) and let it return the value.

In developer however, this is more an issue, because the i18n entries are stored in a workspace file.
You could get around this by syncing the workspace file to the table (right click the i18n files node in the solution explorer and choose 'write to db'

Hope this helps

Re: i18n message in specific language

PostPosted: Tue Nov 07, 2017 6:08 pm
by patrick
Having a language parameter to the getMessage() method would mean that all language values would have to be downloaded (at least in the smart client). So querying the table directly is the best solution indeed.

Re: i18n message in specific language

PostPosted: Wed Nov 08, 2017 9:11 am
by gk1441607435
Hi all

Thank you Patrick for explaining why there is no function to retrieve a specific language. I aggree.

I think in future I will use the example of Marc to get my language text. At the moment we have that problem only in a few parts of our software. It could be done hardcoded. But if it happens more often, we should write a reusable function to get specific languages direcly from the table.

Thank you Marc
Thank you Patrick

You helped me a lot

Gregory