package com.mindprod.example;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;
import static java.lang.System.*;
/**
* Display the Locale/Currency acquired in various ways.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.2 2011-10-01 add currency
* @since 2011-08-21
*/
public final class TestLocale
{
/**
* display fields of a Locale
*
* @param locale the Locale
* @param desc description of the Locale
*/
private static void showLocale( final String desc, final Locale locale )
{
out.println( desc );
out.println( "display:" + locale.getDisplayName() );
out.println( "country:" + locale.getCountry() );
out.println( "ISO3:" + locale.getISO3Country() );
out.println( "display country:" + locale.getDisplayCountry() );
out.println( "language:" + locale.getLanguage() );
out.println( "display language:" + locale.getDisplayLanguage() );
out.println( "user.country:" + System.getProperty( "user.country", "n/a" ) );
out.println( "user.language:" + System.getProperty( "user.language", "n/a" ) );
final Currency currency = Currency.getInstance( locale );
out.println( "currency code:" + currency.getCurrencyCode() );
out.println( "currency numeric code:" + currency.getNumericCode() );
NumberFormat cf = NumberFormat.getCurrencyInstance( locale );
out.println( "currency format: " + cf.format( 9.99d ) );
out.println();
}
/**
* Display current Locale
*
* @param args not used
*/
public static void main( String[] args )
{
Locale defaultLocale = Locale.getDefault();
showLocale( "D E F A U L T", defaultLocale );
Locale specifiedLocale = new Locale( "en", "US" );
showLocale( "E N U S", specifiedLocale );
Locale localeConstant = Locale.CANADA_FRENCH;
showLocale( "C A N A D A _ F R E N C H", localeConstant );
Locale.setDefault( Locale.CANADA );
Locale forcedDefault = Locale.getDefault();
showLocale( "F O R C E D C A N A D A D E F A U L T", forcedDefault );
}
}