views:

1074

answers:

4

Are there any tools to assist with the internationalization of Strings within JSP files?

Most IDEs (for example, NetBeans) offer such a feature for Java code. However, in the case of NetBeans, no such feature exists for JSP files.

With gettext, for example, there is are various tools out there that assist with extracting text Strings from code. Something similar for JSP would be great!

A: 

I found this as a workaround solution to this problem. Its far from ideal, but allows you to search all Strings with an IDE. Paraphrashing the solution:

  1. JSPs compile to servlets, so find the corresponding servlet class for each JSP on your file system. In the case of Tomcat this would be the 'work' directory.
  2. Import the associated servlet .java file into the IDE, and then use the IDE's regular internationalization tool: Externalize strings... (Eclipse) / Internationalization wizard (NetBeans).
myabc
I don't have the solution to your original question I don't see how this will help. If you look at the generated servlet code you will realize that static strings are created for every html tag. That means you will internationalize a lot of meaningless strings.
Vincent Ramdhanie
A: 

This is a vey powerful product / solution to your problem: Globalyzer

I haven't used it myself, but I did a bit of research into it for a project at my previous employer. We needed to extract all Strings out of a lot of Java code and JSPs. We found that Globalyzer covered all our needs.

In the end we decided not to go for Globalyzer, but that was purely a matter of cost.

Nicolai
+1  A: 

I hope no-one minds if I bump an old question...

When faced with the same problem, I put together (a) a method for localising strings in JSPs in the Gettext style (keeping English in the source JSP) and (b) an Ant task which can find such strings in JSPs and generate a Gettext POT file.

(a) is provided by WebGettext, which provides an EL resolver for expressions such as ${messages["Hello {0}"][username]}. The resolver looks up a translation, for the requesting user's locale, and substitutes any parameters using MessageFormat.

(b) is provided by Regex2PotTask, which is a bit like xgettext but for a configurable regex expression rather than C, Java, Perl, etc, function calls such as gettext("my string").

Tennera's home page is here.

Example JSP project - see RUNNING.txt

It's all a bit rough at present, but I think the basics are all there. If someone expresses interest, I might even be motivated to document it "properly"...

seanf
A: 

Usually, you use the xgettext command to extract translatable strings from source code. It supports various languages, Java as well, but has no native support for JSP. I have found though that setting the language parameter to PHP properly parses the JSP files, as PHP and JSP have a similar syntax.

cdauth