• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Alert message translations - design question

 
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I'm working on a web application which supports multiple languages, which means alert messages to the user should be shown in the user language. This is putting me in a scenario where i cannot separate the JavaScript functions from the JSP file.
On the server, i had to do something like this when the HTML output is built

And what I tried was to add the translation string as parameters to the function, but sometimes a function may contains 2 or 3 messages and the parameter list gets too big and it is not very intuitive . Is there a better way to handle this?

Thanks,
Srikkanth
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way most people do it is you have a JS file for each language and include the one that you need.



Than in your JavaScript code you would just do



Eric
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That file can also be created programmatically; I've done it both at compile time and runtime.
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Eric. But the property files are supplied by someone else and copying the messages can be error-prone.(Since i don't know brazilian portuguese :P ). Isn't it?

Hello David,
Can you please elaborate on how to programatically create the file? Do you mean by reading the property files and creating the word
list as suggested by Eric in a JS file?

Thanks,
Srikkanth
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, or a JS file can be run through JSP.
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote: JS file can be run through JSP.



I'm sorry,but i don't get you.

Thanks,
Srikkanth
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Srikkanth Mohanasundaram wrote:Thanks Eric. But the property files are supplied by someone else and copying the messages can be error-prone.(Since i don't know brazilian portuguese :P ). Isn't it?



I did this with Portugese, Spanish, German, English, and a few other languages. I am not sure what is hard about it since you are already doing it with the jsp example you shown.

I would make it a part of your build process to build the language files from your db, text files or wherever you are holding this data. Have your build script build the js files and they can do the validation on the 3rd party generated content to make sure that it has correct syntax [not translation!]

Eric

 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:
Have your build script build the js files and they can do the validation on the 3rd party generated content to make sure that it has correct syntax [not translation!]



Okay I get it . I'm planning to do a simple file read/write operation (which would replace the translation) and create the JS files for each language.
Lesson learnt

Thanks for your help.

Srikkanth
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would do it only once at build, I would not do it on demand every time since that is a waste of server resources and user time.

Eric
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's cached.
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:I would do it only once at build, I would not do it on demand every time since that is a waste of server resources and user time.

Eric



Yup what i meant was exactly that. Next time you make a release, run that java code which will update the JS files.

Thanks,
Srikkanth
 
reply
    Bookmark Topic Watch Topic
  • New Topic