Lightweight i18n approach

Hi Everyone,

I’ve added a lightweight approach to the viritin addon
https://github.com/viritin/viritin
. It will not require using a special UI class (like the Jain I18N addon) or the registration of listeners and implementation of special interfaces (like the I18N4Vaadin addon).
It mainly consits of one Class package org.vaadin.viritin.util.VaadinLocale, which it’s initialised in your UI.init() method with a list of supported locales and the VaadinRequest so it can get the preffered Language from the browser.
When the VaadinLocale.setLocale(Locale) method it called it calls setLocale(Locale) on all current components and changes the locale for components in the future.
A demo which shows how to do this is included.

Feel free to give feetback and ask questions

Daniel

P.S.: currentliy there is one pull request waiting with some fixes

Hi,

Thank you, I was just looking into how to solve this - to me this is a great and simple solution! However, IMHO maybe the locale should be session specific as opposed to UI? If a specific user changes his language setting in one tab, let’s say, it’s also likely the user wants the same language in all other tabs/UI:s - or do I have it wrong?

it seems the pull request has already been integrated into Viritin snapshot. :slight_smile:

Best regards,
Marcus

Java 1.7 does not support the API object Locale.LanguageRange. I’m not very familiar with the Locale API but do you think there is a way to externalise or otherwise make the code Java 1.7 compatible? Otherwise, I’m seeing no conflicts with v1.7.

Best wishes,
Marcus

Hi Marcus,

it defenetliy should be session specific, because the user seleced locale is allready stored in the session. I will change it next week, so that all UI instances in the session get update.

Daniel

I will take a look at this next week. The point is that these constructs with the Locale.LanguageRange do the negotiation between the Language-Accept Header from the browser and the supported locales. But I guess someone has solved this before - I beleve someone had this problem in times where there was no java 1.8.

Daniel

Hi Marcus,

i’ve added tow fixes to my fork on github
https://github.com/dve/viritin
. Could you take a look at them before I make a pull request?

Best wishes

Daniel

Thank you Daniel,

I will for sure check out the fixes as soon as possible. I’ll be travelling this week, back on Monday.

Best regards,
Marcus

I haven’t been able to do extensive testing yet but with your changes the fork compiles for Java 7. Will report back when I get the chance to test it further!