Example to manage internationalization

Hi all,

I have to manage internationalization in my application.
Could you suggest me some examples ?
Cheers.

           Stefano

Hello Stefano,

This question is quite broad. Anyway to To start with create a resource bundle(something ApplicationResources.properties) and copy all the files to your WEB-INF/classes . Create an helper class I18Helper where you initialize the resourceBundle. when ever you have to set messages/captions for that matter anything that you wish to show to end user call the I18Helper’s static method which sends the appropriate message back that can be shown in the UI.

To give you an insight you can do something like this in your I18Helper-

    /** Resource Bundle */
    private final ResourceBundle resourceBundle;

    public I18Helper(Locale locale){
       resourceBundle = ResourceBundle.getBundle("ApplicationResources",locale);
       }

    public String getMessage(String key) {
    try{
       return  resourceBundle.getString(key);
    }catch(MissingResourceException e){
        //LOGGER.warn("Resource "+key+" was not found in the resources file");
        return key;
    }
    }

So when ever you wish to display some thing to the end user call

Button button = new Button(i18Helper.getMessage("button.caption")); where button.caption is a property in
ApplicationResources.properties
file. Make sure you initialize your I18Helper at an appropriate place(It depends totally on your application logic).

Please let me know in case of any difficulties, I will try to post some sample code on GitHub.

Thanks.

Also, you might find my blog post about internationalizing Vaadin CustomLayouts useful:
http://blog.oio.de/2013/05/07/i18n-for-vaadin-applications-using-customlayouts-and-apache-velocity/

You’ll find an example Vaadin application which is internationalized and uses Spring here:

Hi,

There’s
this basic example
by using bundles.

The Gas Diary example for Vaadin 6 is also internationalized with bundles and allows switching the UI language in the login screen. Well, between the two languages, as you can see in the
live demo here
. See for example
LoginScreen.java
.

Is there any way to get similar internationalization works direct from Vaadin Designer?

Something like I write “#{button.caption}” as caption properties in Designer, and this will be translated on rendering phase ?

Would be nice if somone got an idea if the designer could handle something like Luca Pertile mentioned above

Hi Vaadin guys,
we also need a way to internationalize declarative designs generated with the designer. Could you please provide some solution for that.

Thanks,

Timo

Hi Timo,

while I agree it’s a nice-to-have, +4 is a rather low number for this ‘issue’.

It is rather easy to use Designer / Declarative language to put a “placeholder” or even a “primary language” string in there and then, when a view is navigated to, switch those strings to their translation (iterate the component tree) using the translated counterpart e.g. from a HashMap or from a *.properties file.
PropertyUtils comes to mind, e.g. if a “Component” has a “getCaption/setCaption” then localize the caption.

However - we keep listening, it’s just there are more important and pressing issues with much more yield to the developer community that we tackle first. And then the nice-to-haves, well they might never materialize unless someone sponsors that development. Sorry to say.

Best Regards,
Enver