how-to

Internationalization

How to set Locale

For work with Locale class you need to use:

import java.util.Locale;

For Locale setting you can use more variant - here are two of its.

VARIANT 1

Settings from set of predefined constants.

Locale.setDefault( Locale.FRANCE );

System.out.println( Locale.getDefault() );
System.out.println( Locale.getDefault().toString() );
System.out.println( Locale.getDefault().getDisplayCountry() );
System.out.println( Locale.getDefault().getISO3Country() );
System.out.println( Locale.getDefault().getDisplayName() );

The output is:

fr_FR
fr_FR
France
FRA
français (France)

VARIANT 2

Creating new Locale by specifing language (first parameter) and country (second parameter, optionally).

Locale.setDefault( new Locale( "de", "DE" ) );

System.out.println( Locale.getDefault() );
System.out.println( Locale.getDefault().toString() );
System.out.println( Locale.getDefault().getDisplayCountry() );
System.out.println( Locale.getDefault().getISO3Country() );
System.out.println( Locale.getDefault().getDisplayName() );

The output is:

de_DE
de_DE
Deutschland
DEU
Deutsch (Deutschland)
When you omit country code,
Locale.setDefault( new Locale( "de" ) );
the output will be:
de
de


Deutsch

For listing available codes see example "How to list available Locale ?" .