File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Externalizing the string messages in .js files to Java property files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Externalizing the string messages in .js files to Java property files" Watch "Externalizing the string messages in .js files to Java property files" New topic

Externalizing the string messages in .js files to Java property files

Brian Fed

Joined: Feb 07, 2010
Posts: 6
We have a software maintanenace project consisting of a large enterprise java/j2ee based web application. We need to introduce Internationalization(i18n) support to this web application. This j2ee based web application uses technologies like java, oracle database, jsp, javascript, websphere v6.1 application server struts, web services, spring, xml, jms, ejb etc and this web application is mostly (oracle) database driven.

To this web application, we have to add internationalization(i18n) support for languages ike Spanish, French and later extend to other languages.

We have lot (around 50) javascripts files (.js) that are used by jsp files. Lot of string messages are hard coded in the .js files and we need to externalize these string messages to java property files and my question is how do we do that ? without impacting the application functionality. how do we externalize the hard coded string messages in .js files to java property files ? what is the optimal solution for my scenario which can reduce our development time in the process of refactoring the huge code base ?

Can you pleaes clarify ?
Maximus Moothiringus
Ranch Hand

Joined: Jun 07, 2008
Posts: 46

Hmm... I dont know about JavaScript and internationalization..

We have a discussion in the JSP forum about almost the same thing. I am sure since you are using Java/J2EE, you might be able to make use of that. Just a suggestion that you take a look at that.

-- Maximus Moothiringus
Preparing for SCJA!!
Finally figured out that giving <br/> splits the profile biography but not the signature
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Have a build process generate the files or have some process that will generate the js files and cache it.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

The server-side properties files are not available to the client, obviously. So as has been indicated, you'll need to do something on the server to create client-side resources that you can use. It can be a build-time solution, as Eric suggested, or can be an execution time, JSP-initiated solution.

In either case you'll need to take the information for the various locales and put them into JavaScript constructs. Be sure to only send the information for the user's locale (available from the request headers) -- no sense sending all the locales.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Externalizing the string messages in .js files to Java property files
It's not a secret anymore!