


Components that inherit from _AbstractChoice_ (such as _DropDownChoice_, _CheckBoxMultipleChoice_ and _RadioChoice_) must override method _localizeDisplayValues_ and make it return true to localize the values displayed for their choices. By default this method return false so values are displayed as they are. Once localization is activated we can use display values as key for our localized string resources. In project LocalizedChoicesExample we have a drop-down list that displays four colors (green, red, blue, and yellow) which are localized in three languages (English, German and Italian). The current locale can be changed with another drop-down menu (in a similar fashion to project _LocalizedGreetings_). The code of the home page and the relative bundles are the following:

Java code:

[source,java]
----
public HomePage(final PageParameters parameters) {
	super(parameters);

	List<Locale> locales = Arrays.asList(Locale.ENGLISH, Locale.ITALIAN, Locale.GERMAN);
	List<String> colors = Arrays.asList("green", "red", "blue", "yellow");
		
	final DropDownChoice<Locale> changeLocale = new DropDownChoice<Locale>("changeLocale", 
                                                    new Model<Locale>(), locales);
		
	StatelessForm form = new StatelessForm("form"){
		@Override
		protected void onSubmit() {
			Session.get().setLocale(changeLocale.getModelObject());
		}
	};		
		
	DropDownChoice<String> selectColor = new DropDownChoice<String>("selectColor", new 
                                                            Model<String>(), colors){
		@Override
		protected boolean localizeDisplayValues() {
			return true;
		}
	};
		
	form.add(selectColor);
	add(form.add(changeLocale));
    }
----

Default bundle (English):

[source,java]
----
selectColor.null=Select a color
green=Green
red=Red
blue=Blue
yellow=Yellow
----

German bundle:

[source,java]
----
selectColor.null=Wählen Sie eine Farbe
green=Grün
red=Rot
blue=Blau
yellow=Gelb
----

Italian bundle:

[source,java]
----
selectColor.null=Scegli un colore
green=Verde
red=Rosso
blue=Blu
yellow=Giallo
----

Along with the localized versions of colors names, in the bundles above we can also find a custom value for the placeholder text (“Select a color ”) used for null value. The resource key for this resource is 'null' or '<component id>.null' if we want to make it component-specific.

