List of usage examples for java.util Locale setDefault
public static synchronized void setDefault(Locale newLocale)
From source file:com.linkbubble.util.Util.java
static public void setLocale(Context context, String code) { Locale locale = new Locale(code); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale;/*from w w w .j a va 2 s .co m*/ context.getApplicationContext().getResources().updateConfiguration(config, null); }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
public void testDateSerializationInCollection() throws Exception { Type listOfDates = new TypeToken<List<Date>>() { }.getType();//from ww w .j av a 2 s. c o m TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); Locale defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.US); try { //Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); List<Date> dates = Arrays.asList(new Date(0)); String json = oson.setDateFormat("yyyy-MM-dd").toJson(dates, listOfDates); assertEquals("[\"1970-01-01\"]", json); assertEquals(0L, oson.<List<Date>>fromJson("[\"1970-01-01\"]", listOfDates).get(0).getTime()); } finally { TimeZone.setDefault(defaultTimeZone); Locale.setDefault(defaultLocale); } }
From source file:com.gargoylesoftware.htmlunit.WebTestCase.java
/** * Prepare the environment./*from w w w . j ava 2 s . com*/ * Rhino has localized error message... for instance for French */ @BeforeClass public static void beforeClass() { Locale.setDefault(Locale.US); }
From source file:com.sanbo.moveonapp.TabsActivity.java
public void changeLang(TypeLanguage myLang) { if (myLang.toString().equalsIgnoreCase("")) return;//w ww . j a v a 2 s . com myLocale = new Locale(myLang.toString()); saveLocale(myLang); Locale.setDefault(myLocale); android.content.res.Configuration config = new android.content.res.Configuration(); config.locale = myLocale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); // on change language if (PublicTransport.getInstance().isChangedLanguage(myLang)) { // change text in Buttons updateTexts(); // update Menu invalidateOptionsMenu(); // update listMessage if (PublicTransport.getInstance().refreshListAllMessages()) { new UpdateBackgroundTask().execute("SOMETHING"); mlistAdapter.updateResults(PublicTransport.getInstance().getListAllMessages()); } } }
From source file:org.apache.hadoop.yarn.util.TestFSDownload.java
@Test(timeout = 10000) public void testDownloadArchiveZipWithTurkishLocale() throws IOException, URISyntaxException, InterruptedException { Locale defaultLocale = Locale.getDefault(); // Set to Turkish Locale turkishLocale = new Locale("tr", "TR"); Locale.setDefault(turkishLocale); downloadWithFileType(TEST_FILE_TYPE.ZIP); // Set the locale back to original default locale Locale.setDefault(defaultLocale); }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
public void testTimestampSerialization() throws Exception { TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); Locale defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.US); try {//ww w. j a v a2 s .com Timestamp timestamp = new Timestamp(0L); //Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); String json = oson.setDateFormat("yyyy-MM-dd").toJson(timestamp, Timestamp.class); assertEquals("1970-01-01", json); assertEquals(0, oson.fromJson("\"1970-01-01\"", Timestamp.class).getTime()); } finally { TimeZone.setDefault(defaultTimeZone); Locale.setDefault(defaultLocale); } }
From source file:com.gargoylesoftware.htmlunit.WebTestCase.java
/** * Restore the environment. */ @AfterClass public static void afterClass() { Locale.setDefault(SAVE_LOCALE); }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
public void testSqlDateSerialization() throws Exception { TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); Locale defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.US); try {/* ww w .j ava2 s . co m*/ java.sql.Date sqlDate = new java.sql.Date(0L); //Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); String json = oson.setDateFormat("yyyy-MM-dd").toJson(sqlDate, Timestamp.class); assertEquals("1970-01-01", json); assertEquals(0, oson.fromJson("\"1970-01-01\"", java.sql.Date.class).getTime()); } finally { TimeZone.setDefault(defaultTimeZone); Locale.setDefault(defaultLocale); } }
From source file:org.parosproxy.paros.Constant.java
private void initializeFilesAndDirectories() { FileCopier copier = new FileCopier(); File f = null;/*from ww w.ja va 2 s . c om*/ Logger log = null; // default to use application directory 'log' System.setProperty(SYSTEM_PAROS_USER_LOG, "log"); // Set up the version from the manifest PROGRAM_VERSION = getVersionFromManifest(); PROGRAM_TITLE = PROGRAM_NAME + " " + PROGRAM_VERSION; if (zapHome == null) { zapHome = getDefaultHomeDirectory(true); } zapHome = getAbsolutePath(zapHome); f = new File(zapHome); FILE_CONFIG = zapHome + FILE_CONFIG; FOLDER_SESSION = zapHome + FOLDER_SESSION; DBNAME_UNTITLED = zapHome + DBNAME_UNTITLED; ACCEPTED_LICENSE = zapHome + ACCEPTED_LICENSE; DIRBUSTER_CUSTOM_DIR = zapHome + DIRBUSTER_DIR; FUZZER_DIR = zapHome + FUZZER_DIR; FOLDER_LOCAL_PLUGIN = zapHome + FOLDER_LOCAL_PLUGIN; try { System.setProperty(SYSTEM_PAROS_USER_LOG, zapHome); if (!f.isDirectory()) { if (!f.mkdir()) { // ZAP: report failure to create directory System.out.println("Failed to create directory " + f.getAbsolutePath()); } } // Setup the logging File logFile = new File(zapHome + "/log4j.properties"); if (!logFile.exists()) { copier.copy(new File(zapInstall, "xml/log4j.properties"), logFile); } System.setProperty("log4j.configuration", logFile.getAbsolutePath()); PropertyConfigurator.configure(logFile.getAbsolutePath()); log = Logger.getLogger(Constant.class); f = new File(FILE_CONFIG); if (!f.isFile()) { File oldf; if (isDevBuild() || isDailyBuild()) { // try standard location oldf = new File(getDefaultHomeDirectory(false) + FILE_SEPARATOR + FILE_CONFIG_NAME); } else { // try old location oldf = new File(zapHome + FILE_SEPARATOR + "zap" + FILE_SEPARATOR + FILE_CONFIG_NAME); } if (oldf.exists() && Paths.get(zapHome).equals(Paths.get(getDefaultHomeDirectory(true)))) { // Dont copy old configs if they've specified a non std directory log.info("Copying defaults from " + oldf.getAbsolutePath() + " to " + FILE_CONFIG); copier.copy(oldf, f); } else { log.info("Copying defaults from " + getPathDefaultConfigFile() + " to " + FILE_CONFIG); copier.copy(getPathDefaultConfigFile().toFile(), f); } } f = new File(FOLDER_SESSION); if (!f.isDirectory()) { log.info("Creating directory " + FOLDER_SESSION); if (!f.mkdir()) { // ZAP: report failure to create directory System.out.println("Failed to create directory " + f.getAbsolutePath()); } } f = new File(DIRBUSTER_CUSTOM_DIR); if (!f.isDirectory()) { log.info("Creating directory " + DIRBUSTER_CUSTOM_DIR); if (!f.mkdir()) { // ZAP: report failure to create directory System.out.println("Failed to create directory " + f.getAbsolutePath()); } } f = new File(FUZZER_DIR); if (!f.isDirectory()) { log.info("Creating directory " + FUZZER_DIR); if (!f.mkdir()) { // ZAP: report failure to create directory System.out.println("Failed to create directory " + f.getAbsolutePath()); } } f = new File(FOLDER_LOCAL_PLUGIN); if (!f.isDirectory()) { log.info("Creating directory " + FOLDER_LOCAL_PLUGIN); if (!f.mkdir()) { // ZAP: report failure to create directory System.out.println("Failed to create directory " + f.getAbsolutePath()); } } } catch (Exception e) { System.err.println("Unable to initialize home directory! " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } // Upgrade actions try { try { // ZAP: Changed to use ZapXmlConfiguration, to enforce the same character encoding when reading/writing configurations. XMLConfiguration config = new ZapXmlConfiguration(FILE_CONFIG); config.setAutoSave(false); long ver = config.getLong("version"); if (ver == VERSION_TAG) { // Nothing to do } else if (isDevBuild() || isDailyBuild()) { // Nothing to do } else { // Backup the old one log.info("Backing up config file to " + FILE_CONFIG + ".bak"); f = new File(FILE_CONFIG); try { copier.copy(f, new File(FILE_CONFIG + ".bak")); } catch (IOException e) { String msg = "Failed to backup config file " + FILE_CONFIG + " to " + FILE_CONFIG + ".bak " + e.getMessage(); System.err.println(msg); log.error(msg, e); } if (ver == V_PAROS_TAG) { upgradeFrom1_1_0(config); upgradeFrom1_2_0(config); } if (ver <= V_1_0_0_TAG) { // Nothing to do } if (ver <= V_1_1_0_TAG) { upgradeFrom1_1_0(config); } if (ver <= V_1_2_0_TAG) { upgradeFrom1_2_0(config); } if (ver <= V_1_2_1_TAG) { // Nothing to do } if (ver <= V_1_3_0_TAG) { // Nothing to do } if (ver <= V_1_3_1_TAG) { // Nothing to do } if (ver <= V_1_4_1_TAG) { upgradeFrom1_4_1(config); } if (ver <= V_2_0_0_TAG) { upgradeFrom2_0_0(config); } if (ver <= V_2_1_0_TAG) { // Nothing to do } if (ver <= V_2_2_0_TAG) { upgradeFrom2_2_0(config); } if (ver <= V_2_3_1_TAG) { upgradeFrom2_3_1(config); } log.info("Upgraded from " + ver); // Update the version config.setProperty("version", VERSION_TAG); config.save(); } } catch (ConfigurationException | ConversionException | NoSuchElementException e) { // if there is any error in config file (eg config file not exist, corrupted), // overwrite previous configuration file // ZAP: changed to use the correct file copier.copy(getPathDefaultConfigFile().toFile(), new File(FILE_CONFIG)); } } catch (Exception e) { System.err.println("Unable to upgrade config file " + FILE_CONFIG + " " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } // ZAP: Init i18n String lang; Locale locale = Locale.ENGLISH; try { // Select the correct locale // ZAP: Changed to use ZapXmlConfiguration, to enforce the same character encoding when reading/writing configurations. XMLConfiguration config = new ZapXmlConfiguration(FILE_CONFIG); config.setAutoSave(false); lang = config.getString(OptionsParamView.LOCALE, OptionsParamView.DEFAULT_LOCALE); if (lang.length() == 0) { lang = OptionsParamView.DEFAULT_LOCALE; } String[] langArray = lang.split("_"); locale = new Locale(langArray[0], langArray[1]); } catch (Exception e) { System.out.println("Failed to initialise locale " + e); } Locale.setDefault(locale); messages = new I18N(locale); }
From source file:net.pms.configuration.PmsConfiguration.java
/** * Constructor that will initialize the PMS configuration. * * @param loadFile Set to true to attempt to load the PMS configuration * file from the profile path. Set to false to skip * loading.//w w w .j ava2 s . c om * @throws org.apache.commons.configuration.ConfigurationException */ public PmsConfiguration(boolean loadFile) throws ConfigurationException { configuration = new PropertiesConfiguration(); configurationReader = new ConfigurationReader(configuration, true); // true: log configuration.setListDelimiter((char) 0); if (loadFile) { File pmsConfFile = new File(PROFILE_PATH); if (pmsConfFile.isFile()) { if (FileUtil.isFileReadable(pmsConfFile)) { configuration.load(PROFILE_PATH); } else { logger.warn("Can't load {}", PROFILE_PATH); } } else if (SKEL_PROFILE_PATH != null) { File pmsSkelConfFile = new File(SKEL_PROFILE_PATH); if (pmsSkelConfFile.isFile()) { if (FileUtil.isFileReadable(pmsSkelConfFile)) { // Load defaults from skel file, save them later to PROFILE_PATH configuration.load(pmsSkelConfFile); logger.info("Default configuration loaded from " + SKEL_PROFILE_PATH); } else { logger.warn("Can't load {}", SKEL_PROFILE_PATH); } } } } configuration.setPath(PROFILE_PATH); tempFolder = new TempFolder(getString(KEY_TEMP_FOLDER_PATH, null)); programPaths = createProgramPathsChain(configuration); Locale.setDefault(new Locale(getLanguage())); // Set DEFAULT_AVI_SYNTH_SCRIPT according to language DEFAULT_AVI_SYNTH_SCRIPT = "<movie>\n<sub>\n"; long usableMemory = (Runtime.getRuntime().maxMemory() / 1048576) - BUFFER_MEMORY_FACTOR; if (usableMemory > MAX_MAX_MEMORY_DEFAULT_SIZE) { MAX_MAX_MEMORY_BUFFER_SIZE = (int) usableMemory; } }