Document last updated 3 May 2001. We are very interested in feedback that would make these materials better. Feel free to write the author, Jonathan Revusky.

Further Notes on Niggle Internationalization

Using the <include .. > Directive

Freemarker (as well as other page template schemes) offers an include directive. This allows you to consolidate repeatedly used content in one place and simply <include> it when necessary. This feature is perhaps your single greatest ally when it comes to creating maintainable multilingual web sites.

Niggly Details about Templates

When you went through the example and opened the URL: http://localhost:8080/niggletut/welcome.nhtml you saw the message: Je vous souhaite la bienvenue en la langue de Descartes. So far so good, since the strings.author was localized to Descartes of "I think, therefore I am" fame.

Now, some of your more resourceful users may come to realize that they can override the locale by appending the _xx to the page filename. Try opening: http://localhost:8080/niggletut/welcome_en.nhtml and have a look. You see what I see?

I welcome you in the language of Descartes.

Hey, that's not true! Shouldn't it be the language of Shakespeare? You know, the guy who wrote the plays?! Well, that's a tough one. You see, by specifying the page template directly, the user got the English language template, but the locale was still set to France, so the externalized strings that got exposed were the ones in strings_fr.properties.

Well, I'll confess that I'm not sure what to do about this. Nobody said localization was a simple problem! One solution would be to be more sophisticated in deduceLocale() and account for this possibility.

Another issue you might have with this solution is that if you change any of the templates, you will need to restart the server for the changes to be reflected. The reason for this is that, by default, the system is finding the templates via the servlet's classloading mechanism. That's why we put the page templates in the same place that we put the .class files. There is another way to do this that allows us to change the templates while the servlet is running. You can specify a RESOURCE_BASE init-param for the servlet and that way, the system will assume that the page templates are located relative to that path. This is useful in particular when your site is under constant development. You certainly do not want to have to restart the server to see a small change reflected on a page. On the other hand, using the servlet classloader allows you to put everything, java classes and page templates in one .war archive and have everything be resolved relative to that. And that is a very attractive deployment option.