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:edu.ku.brc.specify.ui.AppBase.java

/**
 * Reads Local Preferences for the Locale setting.
 *//*from w w w.  j  av  a2s  . c o m*/
public static void adjustLocaleFromPrefs() {
    String language = AppPreferences.getLocalPrefs().get("locale.lang", null); //$NON-NLS-1$
    if (language != null) {
        String country = AppPreferences.getLocalPrefs().get("locale.country", null); //$NON-NLS-1$
        String variant = AppPreferences.getLocalPrefs().get("locale.var", null); //$NON-NLS-1$

        Locale prefLocale = new Locale(language, country, variant);

        Locale.setDefault(prefLocale);
        UIRegistry.setResourceLocale(prefLocale);
    }

    try {
        ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$

    } catch (MissingResourceException ex) {
        Locale.setDefault(Locale.ENGLISH);
        UIRegistry.setResourceLocale(Locale.ENGLISH);
    }
}

From source file:fr.landel.utils.commons.StringUtilsTest.java

/**
 * Test method for {@link StringUtils#format} .
 *///from   w  ww.  j a  v  a2  s  .  c o m
@Test
public void testFormat() {
    final Locale defaultLocale = Locale.getDefault();
    Locale.setDefault(Locale.US);

    Object[] parameters = new Object[] { "param1", "param2" };
    Object[] arguments = new Object[] { 1.025f, "arg2", "arg3" };

    assertEquals("1.025 'param1' 'param2' '1.02' 'param1' 'arg2' 'arg3'",
            StringUtils.format("%s '%s*' '%s*' '%1$.2f' '%1$s*' '%s' '%s'", parameters, arguments));

    assertEquals("1.025 'param1' 'param2' '1,02' 'param1' 'arg2' 'arg3'", StringUtils.format(Locale.FRENCH,
            "%s '%s*' '%s*' '%1$.2f' '%1$s*' '%s' '%s'", parameters, arguments));

    Locale.setDefault(defaultLocale);
}

From source file:edu.ku.brc.specify.tools.l10nios.StrLocalizerAppForiOS.java

/**
  * @param args//from  w ww. j  ava2 s.  c o m
  */
public static void main(String[] args) {
    setAppName("Specify"); //$NON-NLS-1$
    System.setProperty(AppPreferences.factoryName, "edu.ku.brc.specify.config.AppPrefsDBIOIImpl"); // Needed by AppReferences //$NON-NLS-1$

    for (String s : args) {
        String[] pairs = s.split("="); //$NON-NLS-1$
        if (pairs.length == 2) {
            if (pairs[0].startsWith("-D")) //$NON-NLS-1$
            {
                //System.err.println("["+pairs[0].substring(2, pairs[0].length())+"]["+pairs[1]+"]");
                System.setProperty(pairs[0].substring(2, pairs[0].length()), pairs[1]);
            }
        } else {
            String symbol = pairs[0].substring(2, pairs[0].length());
            //System.err.println("["+symbol+"]");
            System.setProperty(symbol, symbol);
        }
    }

    // Now check the System Properties
    String appDir = System.getProperty("appdir");
    if (StringUtils.isNotEmpty(appDir)) {
        UIRegistry.setDefaultWorkingPath(appDir);
    }

    String appdatadir = System.getProperty("appdatadir");
    if (StringUtils.isNotEmpty(appdatadir)) {
        UIRegistry.setBaseAppDataDir(appdatadir);
    }

    // Then set this
    IconManager.setApplicationClass(Specify.class);
    IconManager.loadIcons(XMLHelper.getConfigDir("icons.xml")); //$NON-NLS-1$
    //ImageIcon icon = IconManager.getIcon("AppIcon", IconManager.IconSize.Std16);

    try {
        ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$

    } catch (MissingResourceException ex) {
        Locale.setDefault(Locale.ENGLISH);
        UIRegistry.setResourceLocale(Locale.ENGLISH);
    }

    try {
        if (!System.getProperty("os.name").equals("Mac OS X")) {
            UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
            PlasticLookAndFeel.setPlasticTheme(new DesertBlue());
        }
    } catch (Exception e) {
        //whatever
    }
    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.setDirPath(UIRegistry.getAppDataDir());

    boolean doIt = false;
    if (doIt)

    {
        Charset utf8charset = Charset.forName("UTF-8");
        Charset iso88591charset = Charset.forName("ISO-8859-1");

        ByteBuffer inputBuffer = ByteBuffer.wrap(new byte[] { (byte) 0xC3, (byte) 0xA2 });

        // decode UTF-8
        CharBuffer data = utf8charset.decode(inputBuffer);

        // encode ISO-8559-1
        ByteBuffer outputBuffer = iso88591charset.encode(data);
        byte[] outputData = outputBuffer.array();
        System.out.println(new String(outputData));
        return;
    }

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                UIHelper.OSTYPE osType = UIHelper.getOSType();
                if (osType == UIHelper.OSTYPE.Windows) {
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                    PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());

                } else if (osType == UIHelper.OSTYPE.Linux) {
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                }
            } catch (Exception e) {
                log.error("Can't change L&F: ", e); //$NON-NLS-1$
            }

            JFrame frame = new JFrame(getResourceString("StrLocalizerApp.AppTitle"));
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            final StrLocalizerAppForiOS sl = new StrLocalizerAppForiOS();
            sl.addMenuBar(frame);
            frame.setContentPane(sl);
            frame.setSize(768, 1024);

            //Dimension size = frame.getPreferredSize();
            //size.height = 500;
            //frame.setSize(size);
            frame.addWindowListener(sl);
            IconManager.setApplicationClass(Specify.class);
            frame.setIconImage(IconManager.getImage(IconManager.makeIconName("SpecifyWhite32")).getImage());

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    sl.startUp();
                }
            });
        }
    });
}

From source file:fr.afcepf.atod.wine.data.parser.XmlParser.java

private static void translateProductVarietals(List<ProductVarietal> varietals,
        IDaoProductVarietal daoProductVarietal, WineService esRepository) {
    try {/*from w w w  .  j a  va2s  .  com*/
        Locale.setDefault(Locale.FRANCE);
        for (ProductVarietal productVarietal : varietals) {
            String varietalfr = "";
            String desc = productVarietal.getDescription();
            if (desc.contains("Other")) {
                if (desc.contains("Blends")) {
                    varietalfr = "Autres assemblages de vins rouges";
                } else {
                    if (desc.contains("Red")) {
                        varietalfr = "Autres types de vins rouges";
                    } else {
                        varietalfr = "Autres types de vins blancs";
                    }
                }
            } else if (desc.contains("Rhone")) {
                varietalfr = "Assemblages de vins rouges du Rhne";
            } else if (desc.contains("Vintage")) {
                varietalfr = "Millesim";
            } else {
                varietalfr = desc;
            }
            productVarietal.setDescription(varietalfr);
            daoProductVarietal.updateObj(productVarietal);
            List<Wine> list = esRepository.findByWineVarietalId(productVarietal.getId());
            for (Wine wine : list) {
                wine.getVarietal().setDescription(varietalfr);
                esRepository.save(wine);
            }
        }
        Locale.setDefault(Locale.US);
    } catch (WineException paramE) {
        // TODO Auto-generated catch block
        paramE.printStackTrace();
    }
}

From source file:org.languagetool.gui.Main.java

public static void main(String[] args) {
    if (System.getSecurityManager() == null) {
        JnaTools.setBugWorkaroundProperty();
    }/*from   ww w. j  a  v a 2  s .c  om*/
    LocalStorage localStorage = new LocalStorage();
    LocaleBean bean = localStorage.loadProperty("gui.locale", LocaleBean.class);
    if (bean != null) {
        Locale.setDefault(bean.asLocale());
    }
    Main prg = new Main(localStorage);
    if (args.length == 1 && (args[0].equals("-t") || args[0].equals("--tray"))) {
        // dock to systray on startup
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    prg.createGUI();
                    prg.setTrayMode(true);
                    prg.hideToTray();
                } catch (Exception e) {
                    Tools.showError(e);
                    System.exit(1);
                }
            }
        });
    } else if (args.length == 1 && (args[0].equals("-h") || args[0].equals("--help"))) {
        printUsage();
    } else if (args.length == 0 || args.length == 1) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    prg.createGUI();
                    prg.showGUI();
                    if (args.length == 1) {
                        prg.loadFile(new File(args[0]));
                    }
                } catch (Exception e) {
                    Tools.showError(e);
                }
            }
        });
    } else {
        printUsage();
        System.exit(1);
    }
}

From source file:us.daveread.basicquery.BasicQuery.java

/**
 * Setup the correct locale based on the user language choice. If the user
 * has chosen default, then the system language defaults are used.
 *///from   ww  w .  ja  v  a  2  s  . c om
private void setupLanguage() {
    String temp;

    temp = Configuration.instance().getProperty(PROP_LANGUAGE, LANG_DEFAULT);

    if (temp.equalsIgnoreCase(LANG_DEFAULT)) {
        if (System.getProperty(PROP_SYSTEM_DEFAULTLANGUAGE) != null) {
            if (System.getProperty(PROP_SYSTEM_DEFAULTCOUNTRY) != null) {
                Locale.setDefault(new Locale(System.getProperty(PROP_SYSTEM_DEFAULTLANGUAGE),
                        System.getProperty(PROP_SYSTEM_DEFAULTCOUNTRY)));
            } else {
                Locale.setDefault(new Locale(System.getProperty(PROP_SYSTEM_DEFAULTLANGUAGE)));
            }
        }
    } else if (temp.equalsIgnoreCase(LANG_ENGLISH)) {
        Locale.setDefault(new Locale("en"));
    } else if (temp.equalsIgnoreCase(LANG_FRENCH)) {
        Locale.setDefault(new Locale("fr"));
    } else if (temp.equalsIgnoreCase(LANG_GERMAN)) {
        Locale.setDefault(new Locale("de"));
    } else if (temp.equalsIgnoreCase(LANG_ITALIAN)) {
        Locale.setDefault(new Locale("it"));
    } else if (temp.equalsIgnoreCase(LANG_PORTUGUESE)) {
        Locale.setDefault(new Locale("pt"));
    } else if (temp.equalsIgnoreCase(LANG_SPANISH)) {
        Locale.setDefault(new Locale("es"));
    }
}

From source file:net.pms.configuration.PmsConfiguration.java

/**
 * Set the preferred language for the PMS user interface.
 * @param value The ISO 639 language code.
 *///from   ww w . j av a 2s  .  c  o m
public void setLanguage(String value) {
    configuration.setProperty(KEY_LANGUAGE, value);
    Locale.setDefault(new Locale(getLanguage()));
}

From source file:im.vector.VectorApp.java

/**
 * Update the application locale.//ww  w . j  av a  2s .c o  m
 *
 * @param locale the locale
 * @param theme  the new theme
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private static void updateApplicationSettings(Locale locale, String textSize, String theme) {
    Context context = VectorApp.getInstance();

    saveApplicationLocale(locale);
    saveFontScale(textSize);
    Locale.setDefault(locale);

    Configuration config = new Configuration(context.getResources().getConfiguration());
    config.locale = locale;
    config.fontScale = getFontScaleValue();
    context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());

    ThemeUtils.setApplicationTheme(context, theme);
    PhoneNumberUtils.onLocaleUpdate();
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

@Override
public void onConfigurationChanged(final Configuration newConfig) {
    Locale.setDefault(Helpers.getLocal(this));
    super.onConfigurationChanged(newConfig);
    this.mPagerAdapter = null;
    this.isResumed = false;
    final boolean changed = (this.mViewPager == null)
            || (this.mViewPager.getCurrentItem() == getTaskFragmentPosition());
    final Task t = this.currentTask;
    try {//from w w  w  .  j a v  a2  s .c om
        draw();
    } catch (final Exception e) {
        // Currently this is meaningless because the toast is killed when
        // the app is killed. Later the error message should persist after
        // the restart
        ErrorReporter.report(ErrorType.MAINACTVITY_CRAZY_ERROR);
        Helpers.restartApp(this);
        Log.d(TAG, "imposible error", e);
        return;
    }
    if ((getListFragment() != null) && (getTasksFragment() != null) && (this.mDrawerToggle != null)) {
        getListFragment().setActivity(this);
        getTasksFragment().setActivity(this);
        if (this.mDrawerLayout != null) {
            this.mDrawerToggle.onConfigurationChanged(newConfig);
        }
        getTasksFragment().hideActionMode();
        getTaskFragment().closeActionMode();
        getListFragment().hideActionMode();
    }
    if (this.mDrawerLayout != null) {
        this.mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                setCurrentTask(t, changed);
            }
        }, 1L);
    }
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

/**
 * Loads the settings/*ww w  .ja v  a2s. c  o  m*/
 */
@SuppressLint("NewApi")
private void initConfiguration() {
    Locale.setDefault(Helpers.getLocal(this));
    MainActivity.isRTL = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
            && getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    this.currentPosition = MainActivity.getTasksFragmentPosition();
    this.mPagerAdapter = null;
    Log.d(MainActivity.TAG, "false");
    this.startIntent = getIntent();
    this.closeOnBack = false;
}