List of usage examples for java.util Locale setDefault
public static synchronized void setDefault(Locale newLocale)
From source file:io.apiman.manager.test.es.ESMetricsAccessorTest.java
@AfterClass @Ignore/*from www .j a v a2 s . com*/ public static void teardown() { System.out.println("----------- Stopping the ES node."); node.stop(); System.out.println("----------- All done."); Locale.setDefault(locale); }
From source file:net.bible.android.BibleApplication.java
/** If locale is overridden then need to set the locale again on any configuration change; see following link * http://stackoverflow.com/questions/2264874/android-changing-locale-within-the-app-itself *//*from w ww .ja v a 2s . co m*/ @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (overrideLocale != null) { if (!overrideLocale.getLanguage().equals(newConfig.locale.getLanguage())) { Log.d(TAG, "re-applying changed Locale"); Locale.setDefault(overrideLocale); Configuration config = new Configuration(); config.locale = overrideLocale; getResources().updateConfiguration(config, getResources().getDisplayMetrics()); } } }
From source file:org.videolan.vlc.VLCApp.java
public void onCreate() { // Are we using advanced debugging - locale? mSettings = PreferenceManager.getDefaultSharedPreferences(context); String p = mSettings.getString("set_locale", ""); if (!p.equals("")) { Locale locale;/*from w ww.j a va2 s.c om*/ // workaround due to region code if (p.equals("zh-TW")) { locale = Locale.TRADITIONAL_CHINESE; } else if (p.startsWith("zh")) { locale = Locale.CHINA; } else if (p.equals("pt-BR")) { locale = new Locale("pt", "BR"); } else if (p.equals("bn-IN") || p.startsWith("bn")) { locale = new Locale("bn", "IN"); } else { /** * Avoid a crash of * java.lang.AssertionError: couldn't initialize LocaleData for locale * if the user enters nonsensical region codes. */ if (p.contains("-")) p = p.substring(0, p.indexOf('-')); locale = new Locale(p); } Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); } // Initialize the database soon enough to avoid any race condition and crash // MediaDatabase.getInstance(); // Prepare cache folder constants AudioUtil.prepareCacheFolder(context); sTV = AndroidDevices.isAndroidTv() || !AndroidDevices.hasTsp(); Dialog.setCallbacks(VLCInstance.get(), mDialogCallbacks); // Disable remote control receiver on Fire TV. if (!AndroidDevices.hasTsp()) AndroidDevices.setRemoteControlReceiverEnabled(false); }
From source file:ch.ralscha.extdirectspring_itest.UserInitBinderServiceTest.java
@Test public void testPostWithDate() throws IOException { Locale.setDefault(Locale.ENGLISH); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("extTID", "2")); formparams.add(new BasicNameValuePair("extAction", "userServiceInitBinderService")); formparams.add(new BasicNameValuePair("extMethod", "updateUser")); formparams.add(new BasicNameValuePair("extType", "rpc")); formparams.add(new BasicNameValuePair("extUpload", "false")); formparams.add(new BasicNameValuePair("name", "Bacon")); formparams.add(new BasicNameValuePair("firstName", "Kevin")); formparams.add(new BasicNameValuePair("email", "kevin@test.com")); formparams.add(new BasicNameValuePair("age", "45")); formparams.add(new BasicNameValuePair("flag", "true")); formparams.add(new BasicNameValuePair("dateOfBirth", "21.12.1966")); UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formparams, "UTF-8"); this.post.setEntity(postEntity); CloseableHttpResponse response = this.client.execute(this.post); try {//from w w w . j a v a 2 s . com HttpEntity entity = response.getEntity(); assertThat(entity).isNotNull(); String responseString = EntityUtils.toString(entity); Map<String, Object> rootAsMap = this.mapper.readValue(responseString, Map.class); assertThat(rootAsMap).hasSize(5); assertThat(rootAsMap.get("method")).isEqualTo("updateUser"); assertThat(rootAsMap.get("type")).isEqualTo("rpc"); assertThat(rootAsMap.get("action")).isEqualTo("userServiceInitBinderService"); assertThat(rootAsMap.get("tid")).isEqualTo(2); Map<String, Object> result = (Map<String, Object>) rootAsMap.get("result"); assertThat(result).hasSize(7); assertThat(result.get("name")).isEqualTo("Bacon"); assertThat(result.get("firstName")).isEqualTo("Kevin"); assertThat(result.get("age")).isEqualTo(45); assertThat(result.get("email")).isEqualTo("kevin@test.com"); assertThat(result.get("flag")).isEqualTo(Boolean.TRUE); assertThat(result.get("dateOfBirth")).isEqualTo("1966-12-21"); assertThat(result.get("success")).isEqualTo(Boolean.TRUE); } finally { IOUtils.closeQuietly(response); } }
From source file:net.sourceforge.pmd.ant.PMDTaskTest.java
@Test public void testFormatterEncodingWithXML() throws Exception { Locale.setDefault(Locale.FRENCH); setDefaultCharset("cp1252"); executeTarget("testFormatterEncodingWithXML"); String report = FileUtils.readFileToString(currentTempFile(), "UTF-8"); assertTrue(report.contains("unusedVariableWithmlaut")); }
From source file:eu.focusnet.app.util.ApplicationHelper.java
/** * Load the proper language based on the value found in the {@link AppContentInstance} * and modify the current {@link Configuration}. This method must be called when appropriate, * but will impact all the rest of the life of the application. It does not impact the UI * directly but is typically called from an Activity's on Resume() method, or just before * redirecting to another Activity./*from w w w .ja v a 2 s . c o m*/ */ public static void changeLanguage(String language) { Locale targetLocale = ApplicationHelper.getDefaultLocale(); if (ApplicationHelper.getSupportedLanguages().contains(language)) { // ok targetLocale = new Locale(language); } else { // perhaps we have a cousin locale (e.g. fr if fr_CH was requested)? // // FIXME FIXME FIXME // that is not optimal. We change the language but also the l10n // For Switzerland, for example, we may prefer to keep the fr_CH locale // (so that Date/number formatting is like we do in CH), but only change the // language to French or German // -> would be solved if we could define a parent translation set in our translation // sets, e.g. fr_CH is child of fr, but we still set fr_CH as an app locale, and // therefore we will have good formatting without having to translate everything // again in French. // alternate solution: symlinks on the filesystem. UNIX-only. Pattern p = Pattern.compile("^([a-z]{2})_.*"); Matcher m = p.matcher(language); if (m.matches()) { targetLocale = new Locale(m.group(1)); } else { FocusApplication.reportError(new FocusNotImplementedException( "Non fatal: Attempting to initialize an application content with unsupported language |" + language + "|")); } } // set the language Locale.setDefault(targetLocale); Configuration config = new Configuration(); config.locale = targetLocale; getApplicationContext().getResources().updateConfiguration(config, getApplicationContext().getResources().getDisplayMetrics()); }
From source file:ro.nextreports.server.web.language.LanguageManager.java
public Locale getLocale(String languageProperty) { Locale locale = new Locale(getLanguage(languageProperty), getCountry(languageProperty)); Locale.setDefault(locale); return locale; }
From source file:org.jcurl.demo.tactics.JCurlShotPlanner.java
public static void main(final String[] args) { // for debugging reasons only: Locale.setDefault(Locale.CANADA); launch(JCurlShotPlanner.class, args); }
From source file:org.videolan.vlc.VLCApplication.java
@Override public void onCreate() { super.onCreate(); // Are we using advanced debugging - locale? mSettings = PreferenceManager.getDefaultSharedPreferences(this); String p = mSettings.getString("set_locale", ""); if (!p.equals("")) { Locale locale;// w w w . j av a 2 s . c o m // workaround due to region code if (p.equals("zh-TW")) { locale = Locale.TRADITIONAL_CHINESE; } else if (p.startsWith("zh")) { locale = Locale.CHINA; } else if (p.equals("pt-BR")) { locale = new Locale("pt", "BR"); } else if (p.equals("bn-IN") || p.startsWith("bn")) { locale = new Locale("bn", "IN"); } else { /** * Avoid a crash of * java.lang.AssertionError: couldn't initialize LocaleData for locale * if the user enters nonsensical region codes. */ if (p.contains("-")) p = p.substring(0, p.indexOf('-')); locale = new Locale(p); } Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getResources().updateConfiguration(config, getResources().getDisplayMetrics()); } instance = this; // Initialize the database soon enough to avoid any race condition and crash MediaDatabase.getInstance(); // Prepare cache folder constants AudioUtil.prepareCacheFolder(this); sTV = AndroidDevices.isAndroidTv() || !AndroidDevices.hasTsp(); if (!VLCInstance.testCompatibleCPU(this)) return; Dialog.setCallbacks(VLCInstance.get(), mDialogCallbacks); // Disable remote control receiver on Fire TV. if (!AndroidDevices.hasTsp()) AndroidDevices.setRemoteControlReceiverEnabled(false); if (Permissions.canReadStorage()) discoverStorages(getMLInstance()); }
From source file:com.astamuse.asta4d.web.test.dispatch.RequestDispatcherTest.java
@BeforeClass public void setConf() { Locale.setDefault(Locale.ROOT); Configuration.setConfiguration(configuration); }