List of usage examples for java.util Locale getAvailableLocales
public static Locale[] getAvailableLocales()
From source file:com.processpuzzle.internalization.domain.ProcessPuzzleLocale.java
private boolean checkIfSupported(String language, String country) { Locale subjectLocale = null;// w w w . j av a 2 s .co m if (country != null) subjectLocale = new Locale(language, country); else if (language != null) subjectLocale = new Locale(language); else return false; Locale[] availableLocales = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; i++) { Locale availableLocale = availableLocales[i]; if (availableLocale.equals(subjectLocale)) return true; } return false; }
From source file:com.processpuzzle.internalization.domain.ProcessPuzzleLocale.java
private void matchCountryByJavaSupportedLocales() { Locale[] locales = Locale.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { if (locales[i].getLanguage().equals(language) && locales[i].getCountry().length() == 2) { this.country = locales[i].getCountry(); break; }//from w w w . ja va2 s . c o m } }
From source file:org.web4thejob.web.util.ZkUtil.java
private static Combobox getComboLocaleType() { Combobox localebox = new Combobox(); localebox.setReadonly(true);/*from w w w . j a v a2 s. c om*/ localebox.setWidth("65%"); List<Locale> locales = Arrays.asList(Locale.getAvailableLocales()); Collections.sort(locales, new Comparator<Locale>() { private String getDisplayName(Locale locale) { return locale.getDisplayName(CoreUtil.getUserLocale()); } @Override public int compare(Locale o1, Locale o2) { return getDisplayName(o1).compareTo(getDisplayName(o2)); } }); Comboitem comboitem = new Comboitem( "* User locale (" + CoreUtil.getUserLocale().getDisplayName(CoreUtil.getUserLocale()) + ")"); //add the user locale comboitem.setValue(CoreUtil.getUserLocale()); comboitem.setParent(localebox); comboitem = new Comboitem( "** System locale (" + Locale.getDefault().getDisplayName(CoreUtil.getUserLocale()) + ")"); //add the system locale comboitem.setValue(Locale.getDefault()); comboitem.setParent(localebox); for (Locale locale : locales) { comboitem = new Comboitem(locale.getDisplayName(CoreUtil.getUserLocale())); comboitem.setValue(locale); comboitem.setParent(localebox); } comboitem = new Comboitem(""); //add the null locale comboitem.setValue(null); comboitem.setParent(localebox); return localebox; }
From source file:paulscode.android.mupen64plusae.persistent.UserPrefs.java
/** * Instantiates a new user preferences wrapper. * //w w w . j a va 2 s .co m * @param context The application context. */ @SuppressWarnings("deprecation") @SuppressLint("InlinedApi") @TargetApi(17) public UserPrefs(Context context) { AppData appData = new AppData(context); mPreferences = PreferenceManager.getDefaultSharedPreferences(context); // Locale mLocaleCode = mPreferences.getString(KEY_LOCALE_OVERRIDE, DEFAULT_LOCALE_OVERRIDE); mLocale = TextUtils.isEmpty(mLocaleCode) ? Locale.getDefault() : createLocale(mLocaleCode); Locale[] availableLocales = Locale.getAvailableLocales(); String[] values = context.getResources().getStringArray(R.array.localeOverride_values); String[] entries = new String[values.length]; for (int i = values.length - 1; i > 0; i--) { Locale locale = createLocale(values[i]); // Get intersection of languages (available on device) and (translated for Mupen) if (ArrayUtils.contains(availableLocales, locale)) { // Get the name of the language, as written natively entries[i] = WordUtils.capitalize(locale.getDisplayName(locale)); } else { // Remove the item from the list entries = (String[]) ArrayUtils.remove(entries, i); values = (String[]) ArrayUtils.remove(values, i); } } entries[0] = context.getString(R.string.localeOverride_entrySystemDefault); mLocaleNames = entries; mLocaleCodes = values; // Files userDataDir = mPreferences.getString("pathGameSaves", ""); galleryDataDir = userDataDir + "/GalleryData"; profilesDir = userDataDir + "/Profiles"; crashLogDir = userDataDir + "/CrashLogs"; coreUserDataDir = userDataDir + "/CoreConfig/UserData"; coreUserCacheDir = userDataDir + "/CoreConfig/UserCache"; hiResTextureDir = coreUserDataDir + "/mupen64plus/hires_texture/"; // MUST match what rice assumes natively romInfoCache_cfg = galleryDataDir + "/romInfoCache.cfg"; controllerProfiles_cfg = profilesDir + "/controller.cfg"; touchscreenProfiles_cfg = profilesDir + "/touchscreen.cfg"; emulationProfiles_cfg = profilesDir + "/emulation.cfg"; customCheats_txt = profilesDir + "/customCheats.txt"; // Plug-ins audioPlugin = new Plugin(mPreferences, appData.libsDir, "audioPlugin"); // Touchscreen prefs isTouchscreenFeedbackEnabled = mPreferences.getBoolean("touchscreenFeedback", false); touchscreenRefresh = getSafeInt(mPreferences, "touchscreenRefresh", 0); touchscreenScale = ((float) mPreferences.getInt("touchscreenScale", 100)) / 100.0f; touchscreenTransparency = (255 * mPreferences.getInt("touchscreenTransparency", 100)) / 100; touchscreenSkin = appData.touchscreenSkinsDir + "/" + mPreferences.getString("touchscreenStyle", "Outline"); touchscreenAutoHold = getSafeInt(mPreferences, "touchscreenAutoHold", 0); // Xperia PLAY touchpad prefs isTouchpadEnabled = appData.hardwareInfo.isXperiaPlay && mPreferences.getBoolean("touchpadEnabled", true); isTouchpadFeedbackEnabled = mPreferences.getBoolean("touchpadFeedback", false); touchpadSkin = appData.touchpadSkinsDir + "/Xperia-Play"; ConfigFile touchpad_cfg = new ConfigFile(appData.touchpadProfiles_cfg); ConfigSection section = touchpad_cfg.get(mPreferences.getString("touchpadLayout", "")); if (section != null) touchpadProfile = new Profile(true, section); else touchpadProfile = null; // Video prefs displayOrientation = getSafeInt(mPreferences, "displayOrientation", 0); displayPosition = getSafeInt(mPreferences, "displayPosition", Gravity.CENTER_VERTICAL); int transparencyPercent = mPreferences.getInt("displayActionBarTransparency", 50); displayActionBarTransparency = (255 * transparencyPercent) / 100; displayFpsRefresh = getSafeInt(mPreferences, "displayFpsRefresh", 0); isFpsEnabled = displayFpsRefresh > 0; videoHardwareType = getSafeInt(mPreferences, "videoHardwareType", -1); videoPolygonOffset = SafeMethods.toFloat(mPreferences.getString("videoPolygonOffset", "-0.2"), -0.2f); isImmersiveModeEnabled = mPreferences.getBoolean("displayImmersiveMode", false); // Audio prefs audioSwapChannels = mPreferences.getBoolean("audioSwapChannels", false); audioSecondaryBufferSize = getSafeInt(mPreferences, "audioBufferSize", 2048); if (audioPlugin.enabled) isFramelimiterEnabled = mPreferences.getBoolean("audioSynchronize", true); else isFramelimiterEnabled = !mPreferences.getString("audioPlugin", "").equals("nospeedlimit"); // User interface modes String navMode = mPreferences.getString("navigationMode", "auto"); if (navMode.equals("bigscreen")) isBigScreenMode = true; else if (navMode.equals("standard")) isBigScreenMode = false; else isBigScreenMode = AppData.IS_OUYA_HARDWARE; // TODO: Add other systems as they enter market isActionBarAvailable = AppData.IS_HONEYCOMB && !isBigScreenMode; // Peripheral share mode isControllerShared = mPreferences.getBoolean("inputShareController", false); // Determine the key codes that should not be mapped to controls boolean volKeysMappable = mPreferences.getBoolean("inputVolumeMappable", false); List<Integer> unmappables = new ArrayList<Integer>(); unmappables.add(KeyEvent.KEYCODE_MENU); if (AppData.IS_HONEYCOMB) { // Back key is needed to show/hide the action bar in HC+ unmappables.add(KeyEvent.KEYCODE_BACK); } if (!volKeysMappable) { unmappables.add(KeyEvent.KEYCODE_VOLUME_UP); unmappables.add(KeyEvent.KEYCODE_VOLUME_DOWN); unmappables.add(KeyEvent.KEYCODE_VOLUME_MUTE); } unmappableKeyCodes = Collections.unmodifiableList(unmappables); // Determine the pixel dimensions of the rendering context and view surface { // Screen size final WindowManager windowManager = (WindowManager) context .getSystemService(android.content.Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); int stretchWidth; int stretchHeight; if (display == null) { stretchWidth = stretchHeight = 0; } else if (AppData.IS_KITKAT && isImmersiveModeEnabled) { DisplayMetrics metrics = new DisplayMetrics(); display.getRealMetrics(metrics); stretchWidth = metrics.widthPixels; stretchHeight = metrics.heightPixels; } else { stretchWidth = display.getWidth(); stretchHeight = display.getHeight(); } float aspect = 0.75f; // TODO: Handle PAL boolean isLetterboxed = ((float) stretchHeight / (float) stretchWidth) > aspect; int zoomWidth = isLetterboxed ? stretchWidth : Math.round((float) stretchHeight / aspect); int zoomHeight = isLetterboxed ? Math.round((float) stretchWidth * aspect) : stretchHeight; int cropWidth = isLetterboxed ? Math.round((float) stretchHeight / aspect) : stretchWidth; int cropHeight = isLetterboxed ? stretchHeight : Math.round((float) stretchWidth * aspect); int hResolution = getSafeInt(mPreferences, "displayResolution", 0); String scaling = mPreferences.getString("displayScaling", "zoom"); if (hResolution == 0) { // Native resolution if (scaling.equals("stretch")) { videoRenderWidth = videoSurfaceWidth = stretchWidth; videoRenderHeight = videoSurfaceHeight = stretchHeight; } else if (scaling.equals("crop")) { videoRenderWidth = videoSurfaceWidth = cropWidth; videoRenderHeight = videoSurfaceHeight = cropHeight; } else // scaling.equals( "zoom") || scaling.equals( "none" ) { videoRenderWidth = videoSurfaceWidth = zoomWidth; videoRenderHeight = videoSurfaceHeight = zoomHeight; } } else { // Non-native resolution switch (hResolution) { case 720: videoRenderWidth = 960; videoRenderHeight = 720; break; case 600: videoRenderWidth = 800; videoRenderHeight = 600; break; case 480: videoRenderWidth = 640; videoRenderHeight = 480; break; case 360: videoRenderWidth = 480; videoRenderHeight = 360; break; case 240: videoRenderWidth = 320; videoRenderHeight = 240; break; case 120: videoRenderWidth = 160; videoRenderHeight = 120; break; default: videoRenderWidth = Math.round((float) hResolution / aspect); videoRenderHeight = hResolution; break; } if (scaling.equals("zoom")) { videoSurfaceWidth = zoomWidth; videoSurfaceHeight = zoomHeight; } else if (scaling.equals("crop")) { videoSurfaceWidth = cropWidth; videoSurfaceHeight = cropHeight; } else if (scaling.equals("stretch")) { videoSurfaceWidth = stretchWidth; videoSurfaceHeight = stretchHeight; } else // scaling.equals( "none" ) { videoSurfaceWidth = videoRenderWidth; videoSurfaceHeight = videoRenderHeight; } } } }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
@Test // Check that all Locales can parse the formats we use public void testParses() throws Exception { for (final String format : new String[] { LONG_FORMAT, SHORT_FORMAT }) { for (final Locale locale : Locale.getAvailableLocales()) { for (final TimeZone tz : new TimeZone[] { NEW_YORK, REYKJAVIK, GMT }) { for (final int year : new int[] { 2003, 1940, 1868, 1867, 1, -1, -1940 }) { final Calendar cal = getEraStart(year, tz, locale); final Date centuryStart = cal.getTime(); cal.set(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 10); final Date in = cal.getTime(); final FastDateParser fdp = new FastDateParser(format, tz, locale, centuryStart); validateSdfFormatFdpParseEquality(format, locale, tz, fdp, in, year, centuryStart); }//from w w w . j a v a 2 s . co m } } } }
From source file:edu.ku.brc.specify.tools.l10nios.StrLocalizerAppForiOS.java
/** * @param hideExisting/*from w ww . j av a 2 s .co m*/ * @return */ private Locale doChooseLangLocale(final Locale hideLocale) { Vector<Locale> locales = new Vector<Locale>(); Collections.addAll(locales, Locale.getAvailableLocales()); String[] langs = { "es", "sv", "sq", "fr" }; Vector<Locale> destLocales = new Vector<Locale>(); destLocales.add(Locale.GERMAN); for (String lang : langs) { appendLocale(locales, destLocales, lang); } Vector<String> localeNames = new Vector<String>(); for (Locale l : destLocales) { localeNames.add(l.getDisplayName()); } ToggleButtonChooserDlg<String> chooser = new ToggleButtonChooserDlg<String>((Frame) null, "CHOOSE_LOCALE", localeNames, ToggleButtonChooserPanel.Type.RadioButton); chooser.setUseScrollPane(true); UIHelper.centerAndShow(chooser); if (!chooser.isCancelled()) { return destLocales.get(chooser.getSelectedIndex()); } return null; }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerDlg.java
@Override protected void applyButtonPressed() { Vector<DisplayLocale> list = new Vector<DisplayLocale>(); for (Locale locale : Locale.getAvailableLocales()) { if (StringUtils.isEmpty(locale.getCountry())) { list.add(new DisplayLocale(locale)); }/*from www. ja va 2s . com*/ } Collections.sort(list); ToggleButtonChooserDlg<DisplayLocale> dlg = new ToggleButtonChooserDlg<DisplayLocale>((Dialog) null, "CHOOSE_LOCALE", list, ToggleButtonChooserPanel.Type.RadioButton); dlg.setUseScrollPane(true); dlg.setVisible(true); if (!dlg.isCancelled()) { schemaLocPanel.localeChanged(dlg.getSelectedObject().getLocale()); setTitle(); } }
From source file:org.jahia.utils.LanguageCodeConverters.java
private static List<Locale> getAvailableLocales() { if (availableLocales == null) { List<Locale> locales = new LinkedList<>(); for (Locale l : Locale.getAvailableLocales()) { if (isSupportedLocale(l)) { locales.add(l);//from ww w.j a v a 2 s .c om } } availableLocales = Collections.unmodifiableList(locales); } return availableLocales; }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
@Test public void testTzParses() throws Exception { // Check that all Locales can parse the time formats we use for (final Locale locale : Locale.getAvailableLocales()) { final FastDateParser fdp = new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale); for (final TimeZone tz : new TimeZone[] { NEW_YORK, REYKJAVIK, GMT }) { final Calendar cal = Calendar.getInstance(tz, locale); cal.clear();/* ww w .ja v a 2 s .c om*/ cal.set(Calendar.YEAR, 2000); cal.set(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 10); final Date expected = cal.getTime(); final Date actual = fdp.parse("2000/02/10 " + tz.getDisplayName(locale)); Assert.assertEquals("tz:" + tz.getID() + " locale:" + locale.getDisplayName(), expected, actual); } } }
From source file:paulscode.android.mupen64plusae.persistent.GlobalPrefs.java
/** * Instantiates a new user preferences wrapper. * * @param context/*from w ww . j a va 2 s .co m*/ * The application context. */ public GlobalPrefs(Context context, AppData appData) { mPreferences = PreferenceManager.getDefaultSharedPreferences(context); // Locale mLocaleCode = mPreferences.getString(KEY_LOCALE_OVERRIDE, DEFAULT_LOCALE_OVERRIDE); mLocale = TextUtils.isEmpty(mLocaleCode) ? Locale.getDefault() : createLocale(mLocaleCode); final Locale[] availableLocales = Locale.getAvailableLocales(); String[] values = context.getResources().getStringArray(R.array.localeOverride_values); String[] entries = new String[values.length]; for (int i = values.length - 1; i > 0; i--) { final Locale locale = createLocale(values[i]); // Get intersection of languages (available on device) and (translated for Mupen) if (ArrayUtils.contains(availableLocales, locale)) { // Get the name of the language, as written natively entries[i] = WordUtils.capitalize(locale.getDisplayName(locale)); } else { // Remove the item from the list entries = (String[]) ArrayUtils.remove(entries, i); values = (String[]) ArrayUtils.remove(values, i); } } entries[0] = context.getString(R.string.localeOverride_entrySystemDefault); mLocaleNames = entries; mLocaleCodes = values; // Files userDataDir = mPreferences.getString("pathGameSaves", ""); galleryCacheDir = userDataDir + "/GalleryCache"; coverArtDir = galleryCacheDir + "/CoverArt"; unzippedRomsDir = galleryCacheDir + "/UnzippedRoms"; profilesDir = userDataDir + "/Profiles"; crashLogDir = userDataDir + "/CrashLogs"; coreUserDataDir = userDataDir + "/CoreConfig/UserData"; coreUserCacheDir = userDataDir + "/CoreConfig/UserCache"; hiResTextureDir = coreUserDataDir + "/mupen64plus/hires_texture/"; // MUST match what rice assumes natively textureCacheDir = coreUserCacheDir + "/mupen64plus/cache"; romInfoCache_cfg = galleryCacheDir + "/romInfoCache.cfg"; controllerProfiles_cfg = profilesDir + "/controller.cfg"; touchscreenProfiles_cfg = profilesDir + "/touchscreen.cfg"; emulationProfiles_cfg = profilesDir + "/emulation.cfg"; customCheats_txt = profilesDir + "/customCheats.txt"; touchscreenCustomSkinsDir = userDataDir + "/CustomSkins"; legacyAutoSaves = userDataDir + "/AutoSaves"; legacySlotSaves = userDataDir + "/SlotSaves"; // Plug-ins audioPlugin = new Plugin(mPreferences, appData.libsDir, "audioPlugin"); // Library prefs isRecentShown = mPreferences.getBoolean("showRecentlyPlayed", true); isFullNameShown = mPreferences.getBoolean("showFullNames", true); // Touchscreen prefs isTouchscreenFeedbackEnabled = mPreferences.getBoolean("touchscreenFeedback", false); touchscreenScale = (mPreferences.getInt("touchscreenScale", 100)) / 100.0f; touchscreenTransparency = (255 * mPreferences.getInt("touchscreenTransparency", 100)) / 100; touchscreenAutoHold = getSafeInt(mPreferences, "touchscreenAutoHold", 0); // Video prefs displayOrientation = getSafeInt(mPreferences, "displayOrientation", 0); displayPosition = getSafeInt(mPreferences, "displayPosition", Gravity.CENTER_VERTICAL); final int transparencyPercent = mPreferences.getInt("displayActionBarTransparency", 50); displayActionBarTransparency = (255 * transparencyPercent) / 100; isFpsEnabled = mPreferences.getBoolean("displayFps", false); final int selectedHardwareType = getSafeInt(mPreferences, "videoHardwareType", -1); isPolygonOffsetHackEnabled = selectedHardwareType > -2; videoHardwareType = selectedHardwareType < 0 ? appData.hardwareInfo.hardwareType : selectedHardwareType; switch (videoHardwareType) { case HardwareInfo.HARDWARE_TYPE_OMAP: videoPolygonOffset = 0.2f; break; case HardwareInfo.HARDWARE_TYPE_OMAP_2: videoPolygonOffset = -1.5f; break; case HardwareInfo.HARDWARE_TYPE_QUALCOMM: videoPolygonOffset = -0.2f; break; case HardwareInfo.HARDWARE_TYPE_IMAP: videoPolygonOffset = -0.001f; break; case HardwareInfo.HARDWARE_TYPE_TEGRA: videoPolygonOffset = -2.0f; break; case HardwareInfo.HARDWARE_TYPE_UNKNOWN: videoPolygonOffset = -1.5f; break; default: videoPolygonOffset = SafeMethods.toFloat(mPreferences.getString("videoPolygonOffset", "-1.5"), -1.5f); break; } isImmersiveModeEnabled = mPreferences.getBoolean("displayImmersiveMode", false); // Audio prefs audioSwapChannels = mPreferences.getBoolean("audioSwapChannels", false); audioSDLSecondaryBufferSize = getSafeInt(mPreferences, "audioSDLBufferSize", 2048); audioSLESSecondaryBufferSize = getSafeInt(mPreferences, "audioSLESBufferSize2", 256); audioSLESSecondaryBufferNbr = getSafeInt(mPreferences, "audioSLESBufferNbr2", 20); audioSLESSamplingRate = getSafeInt(mPreferences, "audioSLESSamplingRate", 0); if (audioPlugin.enabled) isFramelimiterEnabled = !mPreferences.getBoolean("audioSynchronize", true); else isFramelimiterEnabled = !mPreferences.getString("audioPlugin", "").equals("nospeedlimit"); // User interface modes final String navMode = mPreferences.getString("navigationMode", "auto"); if (navMode.equals("bigscreen")) isBigScreenMode = true; else if (navMode.equals("standard")) isBigScreenMode = false; else isBigScreenMode = AppData.IS_OUYA_HARDWARE || appData.isAndroidTv; // TODO: Add other systems as they enter market // Peripheral share mode isControllerShared = mPreferences.getBoolean("inputShareController", false); maxAutoSaves = mPreferences.getInt("gameAutoSaves", 5); // Determine the key codes that should not be mapped to controls final boolean volKeysMappable = mPreferences.getBoolean("inputVolumeMappable", false); final List<Integer> unmappables = new ArrayList<>(); unmappables.add(KeyEvent.KEYCODE_MENU); // Back key is needed to show/hide the action bar in HC+ unmappables.add(KeyEvent.KEYCODE_BACK); if (!volKeysMappable) { unmappables.add(KeyEvent.KEYCODE_VOLUME_UP); unmappables.add(KeyEvent.KEYCODE_VOLUME_DOWN); unmappables.add(KeyEvent.KEYCODE_VOLUME_MUTE); } unmappableKeyCodes = Collections.unmodifiableList(unmappables); // Controller profiles controllerProfile1 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE1, getControllerProfileDefault(1), GetControllerProfilesConfig(), appData.GetControllerProfilesConfig()); controllerProfile2 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE2, getControllerProfileDefault(2), GetControllerProfilesConfig(), appData.GetControllerProfilesConfig()); controllerProfile3 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE3, getControllerProfileDefault(3), GetControllerProfilesConfig(), appData.GetControllerProfilesConfig()); controllerProfile4 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE4, getControllerProfileDefault(4), GetControllerProfilesConfig(), appData.GetControllerProfilesConfig()); // Player map playerMap = new PlayerMap(mPreferences.getString(GamePrefs.PLAYER_MAP, "")); // Determine whether controller deconfliction is needed int numControllers = 0; numControllers += controllerProfile1 != null ? 1 : 0; numControllers += controllerProfile2 != null ? 1 : 0; numControllers += controllerProfile3 != null ? 1 : 0; numControllers += controllerProfile4 != null ? 1 : 0; playerMap.setEnabled(numControllers > 1 && !isControllerShared); }