0

We have developed an asp.net web application using jquery.We have put all the logic on javascript files where we dynamically created html.eg RecentItemContents += "This store has no items listed yet!"; I have to localize "This store has no items listed yet".What could be the best idea to do this.

santrue
  • 1
  • 1
  • My first impulse is `RecentItemContents += noItemsListedMsg;` and then define `noItemsListedMsg` (and any other message constants) somewhere central (perhaps in a separate JS file). My second impulse is to do essentially the same thing with server-side constants... – nnnnnn Feb 11 '12 at 09:11
  • The only thing you actually needed was to read the links that was suggested while you were typing, eg. [this one](http://stackoverflow.com/questions/104022/localize-strings-in-javascript). Please read the links from "Related" section on the right. I am sure you will find the answers. – Paweł Dyda Feb 11 '12 at 22:22

2 Answers2

0

I've done that in the past my just registering an array (which are associative) server-side. Then i just use the relevant array entry. Off the too of my head ...

RecentItemContents += stringValues["NoItems"];

and server side ...

clientScript.RegisterArray("StringValues", ....);

disclaimer: i cannot remember the exact syntax server-side.

Antony Scott
  • 21,690
  • 12
  • 62
  • 94
0

The most flexible solution is to convert all your string messages into function calls. For eg: "welcome, have a good day" should be replaced by a function call welcomeMessage(). Ok why it's better than a variable or storing it in a map is that, once they are methods, it means no limits and you can customize it to any extent. You can make it lazily load data or whatever. You can even make it behave like variables by simply returning the string.

You can group them into an object and specify universal properties for them. For example, say each logical unit of messages has its i18n data in a separate xml file. You can make that object parse the xml and each of the method calls returns data from the parsed xml data.

Navneeth G
  • 7,255
  • 1
  • 15
  • 18