Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i18n server-side vs. client-side

Seeking some advice on two approaches to internationalization & localization. I have a web app using Spring MVC and Dojo, and I would like to support multiple languages. So, I could:

  1. Use <spring:message> to generate the appropriate text on the server side using a properties file.
  2. Use dojo/i18n to select the appropriate text on the client side using a js file.

And of course any combination of the two is also an option.

So, what are the pros and cons of each approach? When would you use one vs. the other?

like image 809
usethe4ce Avatar asked Jul 26 '12 19:07

usethe4ce


1 Answers

The combination of these two approaches is the only reasonable answer. Basically, you should try to stick to server-side, and only do client-side when it is really necessary (there is no other way, like you have some dynamically created controls).

Pros and cons? The main con of client-side string externalization is, you won't be able to translate everything correctly. That's because of context. The same English terms might be translated in a different way, depending on the context.
At the same time, you will often need to format message (add parameters to your message tag), which in regular Java you would do by calling MessageFormat.format(). Theoretically, you could do that on the client-side, but this is risky to say the least. You won't have access to original message parts (like dates, some data sources, whatever) and it might hurt translation correctness.
Formatting dates, numbers, etc. is more painful on the client-side. It is possible with Dojo or jQuery Globalize, but the results might not as good as they should be. But Spring has problem with formatting dates, anyway (lack of default local date/time designation, you may only choose from short, medium, long, full, which to me is completely useless).
Another issue might be handling plural forms (non-English). Believe, or not but languages may have more than one plural form (depending on the quantity) and because of that translations might differ. I don't think Dojo is handling it at all (however, I might be mistaken, some time has past since I evaluated it). Spring won't handle it as well, but you may build custom solution based on ICU's PluralRules (or PluralFormat if you're hard enough to learn formatting and want to kill the translators at the same time).

To cut a long story short, doing I18n correctly is far from being easy and you'll get better support on the server side.

BTW. I remember Dojo as quite "heavy", library itself was over 1MB... It might take a while to load it and your application might seem slow comparing to others... That was one of the reasons, I recommended Globalize rather than Dojo for our projects. It might not have so many features, but at least it seems lightweight.

like image 54
Paweł Dyda Avatar answered Oct 24 '22 15:10

Paweł Dyda