Directory

← Back

i18n-aware

I18NAware internationalization approach centres on automatic propagation of language changes across components and validators.

Author

Rating

Popularity

<100

The basic idea is to define message keys and parameters for caption and values and have the respective caption and values internationalized texts automatically updated.

The helper class “I18NFactory” can be used to instantiate all your internationalizable components and validators. The main purpose of this class is to reduce coupling between your application code and I18NAware:

Example:

Window myMainWindow = I18NFactory.newWindow ( “myMainWindow.titleMessageKey” );

or

Button myButton = I18NFactory.newButton();

I18NFactory.setCaptionKey(myButton, “myButton.captionMessageKey” );

I18NFactory.setCaptionParams(myButton, param );

Your Vaadin application must instantiate the I18NAware’s I18NService using an I18NMessageProvider implementation.

The I18NAware’s I18NService is used to register the top level I18NAware elements of your application and to initiate the internationalization of all reachable captions and values.

Example:

I18NService i18NService = new I18NServiceImpl( new MessageBundle I18NMessageProvider(“messages”) );

i18NService.registerI18NAware( myMainWindow );

i18NService.setLocale( Locale.French );

Sample code

package com.opnworks.vaadin.i18n;

import java.util.Locale;

import com.opnworks.vaadin.i18n.service_impl.I18NAwareFactory;
import com.opnworks.vaadin.i18n.service_impl.I18NServiceImpl;
import com.opnworks.vaadin.i18n.service_impl.ResourceBundleI18NMessageProvider;
import com.vaadin.Application;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

/**
 * The I18NAware Demo webapp
 * 
 * @author Pedro Rodriguez
 */
public class I18NAwareDemo extends Application {

	private static final long serialVersionUID = 2326412816728518688L;

	private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;

	@Override
	public void init() {

		I18NService i18NService = new I18NServiceImpl(
				new ResourceBundleI18NMessageProvider("messages"));

		Window mainWindow = createMainWindow(i18NService);

		setMainWindow(mainWindow);

		i18NService.registerI18NAware(mainWindow);

		// Set initial language
		i18NService.setLocale(DEFAULT_LOCALE);
	}

	private Window createMainWindow(final I18NService i18NService) {

		Window mainWindow = I18NAwareFactory.newWindow("main.window.title");

		TabSheet tabSheet = I18NAwareFactory.newTabSheet();

		VerticalLayout tab1Content = I18NAwareFactory.newVerticalLayout();

		tab1Content.addComponent(I18NAwareFactory
				.newTextField("tab1.textfield.caption"));

		tab1Content.addComponent(I18NAwareFactory
				.newButton("tab1.button.caption"));

		Tab tab1 = tabSheet.addTab(tab1Content);
		I18NAwareFactory.setCaptionKey(tab1, "tab1.name");

		VerticalLayout tab2Content = I18NAwareFactory.newVerticalLayout();

		tab2Content.addComponent(I18NAwareFactory
				.newTextField("tab2.textfield.caption"));

		tab2Content.addComponent(I18NAwareFactory
				.newButton("tab2.button.caption"));

		Tab tab2 = tabSheet.addTab(tab2Content);
		I18NAwareFactory.setCaptionKey(tab2, "tab2.name");

		mainWindow.addComponent(tabSheet);

		mainWindow.addComponent(createLanguageSelector(i18NService));

		return mainWindow;
	}

	@SuppressWarnings("serial")
	private NativeSelect createLanguageSelector(final I18NService i18NService) {

		NativeSelect languageSelector = I18NAwareFactory
				.newNativeSelect("language.selector");

		languageSelector.setImmediate(true);
		languageSelector.setNullSelectionAllowed(false);

		languageSelector.addItem(Locale.ENGLISH);
		languageSelector.setItemCaption(Locale.ENGLISH, "English");

		languageSelector.addItem(Locale.FRENCH);
		languageSelector.setItemCaption(Locale.FRENCH, "Français");

		languageSelector.setValue(DEFAULT_LOCALE);

		languageSelector.addListener(new Property.ValueChangeListener() {
			public void valueChange(ValueChangeEvent event) {
				Locale locale = (Locale) (event.getProperty().getValue());
				i18NService.setLocale(locale);
			}
		});

		return languageSelector;
	}
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Still missing these components:

com.vaadin.ui.AbsoluteLayout com.vaadin.ui.Accordion com.vaadin.ui.CssLayout com.vaadin.ui.CustomLayout com.vaadin.ui.HorizontalSplitPanel com.vaadin.ui.InlineDateField com.vaadin.ui.ListSelect com.vaadin.ui.LoginForm com.vaadin.ui.MenuBar com.vaadin.ui.NativeButton com.vaadin.ui.OrderedLayout com.vaadin.ui.PasswordField com.vaadin.ui.PopupDateField com.vaadin.ui.PopupView com.vaadin.ui.RichTextArea com.vaadin.ui.Select com.vaadin.ui.Slider com.vaadin.ui.SplitPanel com.vaadin.ui.Table com.vaadin.ui.Tree com.vaadin.ui.TwinColSelect com.vaadin.ui.Upload com.vaadin.ui.VerticalSplitPanel

Released
2011-10-28
Maturity
BETA
License
Apache License 2.0

Compatibility

Framework
Vaadin 6.6+
Browser
N/A

i18n-aware - Vaadin Add-on Directory

I18NAware internationalization approach centres on automatic propagation of language changes across components and validators. i18n-aware - Vaadin Add-on Directory
The basic idea is to define message keys and parameters for caption and values and have the respective caption and values internationalized texts automatically updated. The helper class “I18NFactory” can be used to instantiate all your internationalizable components and validators. The main purpose of this class is to reduce coupling between your application code and I18NAware: Example: Window myMainWindow = I18NFactory.newWindow ( “myMainWindow.titleMessageKey” ); or Button myButton = I18NFactory.newButton(); I18NFactory.setCaptionKey(myButton, “myButton.captionMessageKey” ); I18NFactory.setCaptionParams(myButton, param ); Your Vaadin application must instantiate the I18NAware’s I18NService using an I18NMessageProvider implementation. The I18NAware’s I18NService is used to register the top level I18NAware elements of your application and to initiate the internationalization of all reachable captions and values. Example: I18NService i18NService = new I18NServiceImpl( new MessageBundle I18NMessageProvider(“messages”) ); i18NService.registerI18NAware( myMainWindow ); … i18NService.setLocale( Locale.French );
Author Homepage
Issue Tracker
Source Code
Discussion Forum

i18n-aware version 0.0.4
Still missing these components: com.vaadin.ui.AbsoluteLayout com.vaadin.ui.Accordion com.vaadin.ui.CssLayout com.vaadin.ui.CustomLayout com.vaadin.ui.HorizontalSplitPanel com.vaadin.ui.InlineDateField com.vaadin.ui.ListSelect com.vaadin.ui.LoginForm com.vaadin.ui.MenuBar com.vaadin.ui.NativeButton com.vaadin.ui.OrderedLayout com.vaadin.ui.PasswordField com.vaadin.ui.PopupDateField com.vaadin.ui.PopupView com.vaadin.ui.RichTextArea com.vaadin.ui.Select com.vaadin.ui.Slider com.vaadin.ui.SplitPanel com.vaadin.ui.Table com.vaadin.ui.Tree com.vaadin.ui.TwinColSelect com.vaadin.ui.Upload com.vaadin.ui.VerticalSplitPanel

Online