translate prompt (and alert) message triggered in client script

undefined1
Tera Contributor

hey, I'm new to scripting and wanted to ask about this as I haven't found any advice. and while writing my question I found the solution so maybe this will help somebody in future.

My original post:

I have a prompt in client script in the widget. this should be asked in respective language as my users are speaking German and English.

I tried different setups with getMessage function and prompt with variable instead of the text but nothing works.

I ended up with this temp solution which is ugly but working. would like to change it to something proper...

var lang = g_lang;
var reason;
if(lang == 'de'){
reason = prompt('German question');
} else {
reason = prompt('English question');
}

Now the solution:

add English and German message in sys_ui_message with key of your choice eg 'My Msg'

in client script in widget after c is defined like:

var c = this;

define your message like:

c.customMsg = "${My Msg}";

then you can trigger prompt or alert like:

var answer = prompt(c.customMsg);
if (answer) {
$scope.data.your_variable = answer;
etc...

or simply :

alert(c.customMsg);

 

not sure if this is the right way but it worked for me. hopefully this will help somebody in future. 

if you have some better solution or if this is not good a practice please comment.

 

 

 

 

5 REPLIES 5

Technically I think ${} is not expected to be used on client side.
If you want to make sure things work in the future, then I'd use gs.getMessage on server side.
Server side is anyway rendered before client, so you'll always have the translation available.