I’ve decided, that the new web site will support at least two languages: English and German. That’s because I have a little knowledge of both of theses languages. Developing for these two languages is nearly the same as developing for n languages (it’s not, but we assume this for now). So how do I support more than one language?

Synformation supports I18N in many ways. In fact, there are so many ways, that it can be confusing at times when you have to choose one of them for a specific project. A so called content object in synformation is an object that normally has its content (e.g. binary data like pictures, text) and all the meta-data that comes with it (e.g. date, language, valid-until, relationship to other objects) to describe it further. These content objects are normally used for articles, documents, user generated comments, etc. That’s why they have this name.

If I write an article for the web site, I will translate it into the other language and publish it. To decide which article has to be shown (the english or the german one), I can filter the articles by using a meta datum called language. In fact, this will work even if there is no corresponding german article for an english one, because the content used within one page will be filtered without considering the existence of a translated version (e.g. show the first 10 english articles in category Java starting today ordered by date published descending and having activated equals true, and belonging to at least one of the user groups where the current user belongs to). So content can be filtered for one language by simply selecting the appropriate language. When I want to, I can define a relationship between the english and the german article by setting a relationship of type is translation of between two articles. Using this relationship I can easily find corresponding articles in other languages. When we look at another content type (user comments for articles), it’s quite clear that a specific comment will exist for only one language. Ok, the content part was quite easy to solve.

What other language specific resources do we have? We’ll look at a Post comment form for now. There is a little text explaining what you can do, there are some input fields and their labels, and there is a button with some text to post the comment. In case something goes wrong, it would be nice to have a message in the same language explaining what to do and providing a way out. Java offers resource bundles to store language specific resources, but you have to have one file for each language. This makes translation of these language specific resources a little harder than necessary. I want to have one file (or in my case content object) with all the different languages. With some preprocessing I could build the resource bundles from this content object, but I will go with a JSON object. It has a technical name for the resource and an array with one element for each language, e.g.

"FORM-COMMENT-SUBMIT": ["send", "Senden"]

This approach will be used only for simple text resources without any markup. For more complex text objects (like terms of use with headings and other semantic markup) I’ll use full blown content objects.

By the way, synformation can execute logic embedded within these text resources and content objects. Sometimes, it’s pretty handy to be able to write something like this:

Copyright 2002-<%% print
new java.text.SimpleDateFormat("yyyy").format(getNow()); %>

Of course, this can be a security issue. Imagine that someone commenting on an article is able to embed arbitrary logic within a comment. This is where user groups and the rights management comes into play. But this would be a completely different topic.

I hope you’ve got a feeling for how I plan to tackle I18N with this project. And maybe you have some better ideas. I would really like to hear about them.

0 comments… add one

Leave a Comment