3

i have an DOJO nls key file that have entries like

({

"name":"test",
"comma" : ", ",
"hello":"Hello",
"welcome_msg": this.name+this.comma+this.hello

})

I want to have the welcome message be "Hello, test", so basically want to use the name, comma and hello key's defined above in this value field and create the string rather than direct usage.

Is there a way of achieving the above like this.comma or ${comma}?? basically in french and other languages colon and some of spl characters will have additional space before and after, while in english only one space after...

any help in this regard will be highly appreciated.. thanks

hugomg
  • 68,213
  • 24
  • 160
  • 246
  • If you use the new, AMD style, NLS files then I think you can put whatever code you want in them. However, you should probably err on the side of simplicity, as suggested in Craig's answer. – hugomg Mar 27 '12 at 13:24

1 Answers1

2

I use dojo.replace. But I use this in the widget code and not the actual nls file.

var i18n = ...
var name = ...
dojo.replace('{0}{1} {2}', [i18n.hello, i18n.comma, name]);

BUT, I don't understand how this helps with what you are trying to accomplish. Why not leave the welcome message as

"welcome_msg": "Hello, {0}"

The nls file is per language, so any other nls file would have the appropriate punctuation and spacing that you need.

Craig Swing
  • 8,152
  • 2
  • 30
  • 43
  • I agree. As a general rule of thumb, always use string formatting instead of concatenation when it comes to NLS stuff. – hugomg Mar 27 '12 at 13:21
  • Craig, you are right, there will be a separate NLS file corresponding to the each language. I was just Curious to find out whether string concatenation works or not? – user1292547 Mar 28 '12 at 10:05