Here you can find the source of setLocale(final Locale l)
Parameter | Description |
---|---|
l | The new default locale |
public static void setLocale(final Locale l)
//package com.java2s; /*// w w w. j a v a 2s. co m * jGnash, a personal finance application * Copyright (C) 2001-2019 Craig Cavanaugh * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Locale; import java.util.ResourceBundle; import java.util.prefs.Preferences; public class Main { /** * key for locale preference */ private static final String LOCALE = "locale"; /** * Historical path to the preference root */ private static final String PREFERENCE_NODE = "/jgnash/util/Resource"; private static ResourceBundle resourceBundle; /** * Sets the new default locale. This must be called if overridden. * * @param l The new default locale */ public static void setLocale(final Locale l) { Locale.setDefault(l); final Preferences p = Preferences.userRoot().node(PREFERENCE_NODE); p.put(LOCALE, encodeLocale(l)); resourceBundle = null; // force a reload the resource bundle } private static String encodeLocale(final Locale locale) { final StringBuilder buf = new StringBuilder(); buf.append(locale.getLanguage()); if (!locale.getCountry().equals("")) { buf.append('.'); buf.append(locale.getCountry()); if (!locale.getVariant().equals("")) { buf.append('.'); buf.append(locale.getVariant()); } } return buf.toString(); } }