Example usage for java.util Locale setDefault

List of usage examples for java.util Locale setDefault

Introduction

In this page you can find the example usage for java.util Locale setDefault.

Prototype

public static synchronized void setDefault(Locale newLocale) 

Source Link

Document

Sets the default locale for this instance of the Java Virtual Machine.

Usage

From source file:InternalFrame.InternalFrameproject.java

/**
 * Creates new form New//ww  w  . j a  v  a2s .c o m
 */
public InternalFrameproject() {
    initComponents();
    Locale.setDefault(new Locale("en", "US"));
}

From source file:org.totschnig.myexpenses.MyApplication.java

public void setLanguage(Locale locale) {
    if (!Locale.getDefault().equals(locale)) {
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;//from  ww w.  ja va  2 s.  c o  m
        config.fontScale = getResources().getConfiguration().fontScale;
        getResources().updateConfiguration(config, getResources().getDisplayMetrics());
    }
}

From source file:ro.ciubex.keepscreenlock.MainApplication.java

/**
 * Initialize the application locale.
 */
public void initLocale() {
    mLocale = getLocaleSharedPreferences();
    Locale.setDefault(mLocale);
}

From source file:org.jfree.data.time.WeekTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *///  w ww .  j av a 2s  . c o m
@Test
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Week w = new Week(3, 1970);
    assertEquals(946800000L, w.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.jfree.data.time.SecondTest.java

/**
 * Some checks for the getEnd() method./* ww  w  .  j  a v a2  s  .  c  o m*/
 */
@Test
public void testGetEnd() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55);
    cal.set(Calendar.MILLISECOND, 999);
    Second s = new Second(55, 47, 3, 16, 1, 2006);
    assertEquals(cal.getTime(), s.getEnd());
    Locale.setDefault(saved);
}

From source file:org.jfree.data.time.MinuteTest.java

/**
 * Some checks for the getEnd() method.//from  www  .j a va 2s  . c  om
 */
@Test
public void testGetEnd() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome"));
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 3, 47, 59);
    cal.set(Calendar.MILLISECOND, 999);
    Minute m = new Minute(47, 3, 16, 1, 2006);
    assertEquals(cal.getTime(), m.getEnd());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.jfree.data.time.junit.MonthTest.java

/**
 * Some checks for the getLastMillisecond() method.
 *//*from   ww w.j av  a2 s .  c  om*/
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Month m = new Month(3, 1970);
    assertEquals(7772399999L, m.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.jfree.data.time.junit.DayTest.java

/**
 * Some checks for the getLastMillisecond() method.
 *//*from  w w w .  ja  v a  2s  . c o m*/
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Day d = new Day(1, 1, 1970);
    assertEquals(82799999L, d.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:com.frameworkset.platform.cms.driver.i18n.CmsLocaleManager.java

/**
 * Sets the default locale of the Java VM to <code>{@link Locale#ENGLISH}</code> if the 
 * current default has any other language then English set.<p>
 *
 * This is required because otherwise the default (English) resource bundles 
 * would not be displayed for the English locale if a translated default locale exists.<p>
 * /* ww w .  jav  a2  s  .  c o  m*/
 * Here's an example of how this issues shows up:
 * On a German server, the default locale usually is <code>{@link Locale#GERMAN}</code>.
 * All English translations for OpenCms are located in the "default" message files, for example 
 * <code>com.frameworkset.platform.cms.driver.i18n.message.properties</code>. If the German localization is installed, it will be
 * located in <code>com.frameworkset.platform.cms.driver.i18n.message_de.properties</code>. If user has English selected
 * as his locale, the default Java lookup mechanism first tries to find 
 * <code>com.frameworkset.platform.cms.driver.i18n.message_en.properties</code>. However, this file does not exist, since the
 * English localization is kept in the default file. Next, the Java lookup mechanism tries to find the servers
 * default locale, which in this example is German. Since there is a German message file, the Java lookup mechanism
 * is finished and uses this German localization, not the default file. Therefore the 
 * user get the German localization, not the English one.
 * Setting the default locale explicitly to English avoids this issue.<p>
 */
private static void setDefaultLocale() {

    // set the default locale to english
    // this is required because otherwise the default (english) resource bundles 
    // would not be displayed for the english locale if a translated locale exists

    Locale oldLocale = Locale.getDefault();
    if (!(Locale.ENGLISH.getLanguage().equals(oldLocale.getLanguage()))) {
        // default language is not English
        try {
            Locale.setDefault(Locale.ENGLISH);
            //                if (CmsLog.INIT.isInfoEnabled()) {
            //                    CmsLog.INIT.info(Messages.get().getBundle().key(
            //                        Messages.INIT_I18N_DEFAULT_LOCALE_2,
            //                        Locale.ENGLISH,
            //                        oldLocale));
            //                }
        } catch (Exception e) {
            // any Exception: the locale has not been changed, so there may be issues with the English
            // localization but OpenCms will run in general
            //                CmsLog.INIT.error(Messages.get().getBundle().key(
            //                    Messages.LOG_UNABLE_TO_SET_DEFAULT_LOCALE_2,
            //                    Locale.ENGLISH,
            //                    oldLocale), e);
        }
    } else {
        //            if (CmsLog.INIT.isInfoEnabled()) {
        //                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_I18N_KEEPING_DEFAULT_LOCALE_1, oldLocale));
        //            }
    }

    // initialize the static member with the new default 
    m_defaultLocale = Locale.getDefault();
}

From source file:divya.myvision.TessActivity.java

public void setLang(String lang) {
    Locale locale;/*  ww  w. j a  v a  2  s  .co m*/
    if (lang.equals("Spanish")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                Locale locSpanish = new Locale("spa", "MEX");
                tts.setLanguage(locSpanish);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("spa", "MEX");
    }

    else if (lang.equals("French")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.FRENCH);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("fr");
    } else if (lang.equals("Japanese")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.JAPANESE);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("ja");
    } else if (lang.equals("Chinese")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.CHINESE);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("zh");
    } else if (lang.equals("German")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.GERMAN);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("de");
    } else if (lang.equals("Italian")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.ITALIAN);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("it");
    } else if (lang.equals("Korean")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.KOREAN);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("ko");
    } else if (lang.equals("Hindi")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                Locale locHindhi = new Locale("hi");
                tts.setLanguage(locHindhi);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("hi");
    } else if (lang.equals("Russian")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                Locale locHindhi = new Locale("ru");
                tts.setLanguage(locHindhi);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("ru");
    } else {
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.US);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("en");
    }
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.setLocale(locale);
    this.getApplicationContext().getResources().updateConfiguration(config, null);

}