List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:de.alpharogroup.resourcebundle.properties.PropertiesFileExtensions.java
/** * Load the properties file from the given class object. The filename from the properties file * is the same as the simple name from the class object and it looks at the same path as the * given class object. If locale is not null than the language will be added to the filename * from the properties file.//ww w . j a v a2 s . c om * * @param clazz * the clazz * @param locale * the locale * @return the properties * @throws IOException * Signals that an I/O exception has occurred. */ public static Properties loadPropertiesFromClassObject(final Class<?> clazz, final Locale locale) throws IOException { if (null == clazz) { throw new IllegalArgumentException("Class object must not be null!!!"); } StringBuilder propertiesName = new StringBuilder(); Properties properties = null; String language = null; String filename = null; String pathAndFilename = null; File propertiesFile = null; String absoluteFilename = null; final String packagePath = PackageExtensions.getPackagePathWithSlash(clazz); final List<String> missedFiles = new ArrayList<>(); if (null != locale) { propertiesName.append(clazz.getSimpleName()); language = locale.getLanguage(); if ((null != language) && !language.isEmpty()) { propertiesName.append("_").append(language); } final String country = locale.getCountry(); if ((null != country) && !country.isEmpty()) { propertiesName.append("_").append(country); } propertiesName.append(FileExtension.PROPERTIES.getExtension()); filename = propertiesName.toString().trim(); pathAndFilename = packagePath + filename; URL url = ClassExtensions.getResource(clazz, filename); if (url != null) { absoluteFilename = url.getFile(); } else { missedFiles.add("File with filename '" + filename + "' does not exists."); } if (null != absoluteFilename) { propertiesFile = new File(absoluteFilename); } if ((null != propertiesFile) && propertiesFile.exists()) { properties = PropertiesFileExtensions.loadProperties(pathAndFilename); } else { propertiesName = new StringBuilder(); if (null != locale) { propertiesName.append(clazz.getSimpleName()); language = locale.getLanguage(); if ((null != language) && !language.isEmpty()) { propertiesName.append("_").append(language); } propertiesName.append(FileExtension.PROPERTIES.getExtension()); filename = propertiesName.toString().trim(); pathAndFilename = packagePath + filename; url = ClassExtensions.getResource(clazz, filename); if (url != null) { absoluteFilename = url.getFile(); } else { missedFiles.add("File with filename '" + filename + "' does not exists."); } if (null != absoluteFilename) { propertiesFile = new File(absoluteFilename); } if ((null != propertiesFile) && propertiesFile.exists()) { properties = PropertiesFileExtensions.loadProperties(pathAndFilename); } } } } if (null == properties) { propertiesName = new StringBuilder(); propertiesName.append(clazz.getSimpleName()).append(FileExtension.PROPERTIES.getExtension()); filename = propertiesName.toString().trim(); pathAndFilename = packagePath + filename; final URL url = ClassExtensions.getResource(clazz, filename); if (url != null) { absoluteFilename = url.getFile(); } else { properties = PropertiesFileExtensions.loadProperties(pathAndFilename); missedFiles.add("File with filename '" + filename + "' does not exists."); } if (null != absoluteFilename) { propertiesFile = new File(absoluteFilename); } if ((null != propertiesFile) && propertiesFile.exists()) { properties = PropertiesFileExtensions.loadProperties(pathAndFilename); } } return properties; }
From source file:com.phonemetra.turbo.lockclock.weather.OpenWeatherMapProvider.java
private String getLanguageCode() { Locale locale = mContext.getResources().getConfiguration().locale; String selector = locale.getLanguage() + "-" + locale.getCountry(); for (Map.Entry<String, String> entry : LANGUAGE_CODE_MAPPING.entrySet()) { if (selector.startsWith(entry.getKey())) { return entry.getValue(); }// ww w . j a v a2 s . com } return "en"; }
From source file:de.hybris.platform.acceleratorservices.web.payment.controllers.HostedOrderPageMockController.java
@ModelAttribute("currentLanguageIso") public String getCurrentLanguageIso() { final Locale currentLocale = Locale.getDefault(); return currentLocale.getCountry().toLowerCase(Locale.getDefault()); }
From source file:com.example.locale.MainActivity.java
private void showDefaultLocale() { Locale locale = Locale.getDefault(); setTitle(locale.getDisplayName());// w w w .java 2 s .c o m BitmapDrawable d = (BitmapDrawable) ImageUtil.getFlagIcon(this, locale.getCountry()); if (d != null) { final Bitmap bitmap = d.getBitmap(); mPaletteTask = new Palette.Builder(bitmap).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { mPaletteTask = null; int color = palette.getDarkVibrantColor(0); mToolbar.setBackgroundColor(color); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(getDarkerColor(color)); } } }); } }
From source file:org.eclipse.jubula.autagent.commands.AbstractStartJavaAut.java
/** * @param cmds The command List. May <b>not</b> be <code>null</code>. * @param locale The <code>Locale</code> for the AUT. * May be <code>null</code> if no locale was specified. *//*ww w. j a v a2s .c o m*/ protected void addLocale(List<String> cmds, Locale locale) { if (locale != null) { String country = locale.getCountry(); if (country != null && country.length() > 0) { cmds.add(JAVA_COUNTRY_PROPERTY + country); } String language = locale.getLanguage(); if (language != null && language.length() > 0) { cmds.add(JAVA_LANGUAGE_PROPERTY + language); } } }
From source file:com.puppycrawl.tools.checkstyle.TreeWalkerTest.java
@Test public void testCacheFileChangeInConfig() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class); final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class); treeWalkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath()); treeWalkerConfig.addChild(checkConfig); final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration"); checkerConfig.addAttribute("charset", "UTF-8"); checkerConfig.addChild(treeWalkerConfig); Checker checker = new Checker(); final Locale locale = Locale.ROOT; checker.setLocaleCountry(locale.getCountry()); checker.setLocaleLanguage(locale.getLanguage()); checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader()); checker.configure(checkerConfig);/*from w w w .j a v a 2 s. c o m*/ checker.addListener(new BriefLogger(stream)); final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath(); final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY; verify(checker, pathToEmptyFile, pathToEmptyFile, expected); // update Checker config //checker.destroy(); //checker.configure(checkerConfig); Checker otherChecker = new Checker(); otherChecker.setLocaleCountry(locale.getCountry()); otherChecker.setLocaleLanguage(locale.getLanguage()); otherChecker.setModuleClassLoader(Thread.currentThread().getContextClassLoader()); otherChecker.configure(checkerConfig); otherChecker.addListener(new BriefLogger(stream)); // here is diff with previous checker checkerConfig.addAttribute("fileExtensions", "java,javax"); // one more time on updated config verify(otherChecker, pathToEmptyFile, pathToEmptyFile, expected); }
From source file:info.magnolia.templating.elements.InitElement.java
@Override public void begin(Appendable out) throws IOException, RenderException { if (!isAdmin()) { return;/*w w w .j av a 2 s . c o m*/ } Node content = getPassedContent(); if (content == null) { content = currentContent(); } TemplateDefinition templateDefinition = getRequiredTemplateDefinition(); dialog = resolveDialog(templateDefinition); Sources src = new Sources(MgnlContext.getContextPath()); MarkupHelper helper = new MarkupHelper(out); helper.append("<!-- begin js and css added by @cms.init -->\n"); helper.append("<meta name=\"gwt:property\" content=\"locale=" + i18nContentSupport.getLocale() + "\"/>\n"); helper.append(src.getHtmlCss()); helper.append(src.getHtmlJs()); //TODO see SCRUM-1239, we will probably get rid of the init tag in 5.0 //helper.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + PAGE_EDITOR_CSS + "\"></link>\n"); //helper.append("<script type=\"text/javascript\" src=\"" + PAGE_EDITOR_JS_SOURCE + "\"></script>\n"); helper.openComment(CMS_PAGE_TAG); if (content != null) { helper.attribute(AreaDirective.CONTENT_ATTRIBUTE, getNodePath(content)); } helper.attribute("dialog", dialog); helper.attribute("preview", String.valueOf(MgnlContext.getAggregationState().isPreviewMode())); //here we provide the page editor with the available locales and their respective URI for the current page if (i18nAuthoringSupport.isEnabled() && i18nContentSupport.isEnabled() && i18nContentSupport.getLocales().size() > 1) { Content currentPage = MgnlContext.getAggregationState().getMainContent(); String currentUri = createURI(currentPage, i18nContentSupport.getLocale()); helper.attribute("currentURI", currentUri); List<String> availableLocales = new ArrayList<String>(); for (Locale locale : i18nContentSupport.getLocales()) { String uri = createURI(currentPage, locale); String label = StringUtils.capitalize(locale.getDisplayLanguage(locale)); if (StringUtils.isNotEmpty(locale.getCountry())) { label += " (" + StringUtils.capitalize(locale.getDisplayCountry()) + ")"; } availableLocales.add(label + ":" + uri); } helper.attribute("availableLocales", StringUtils.join(availableLocales, ",")); } helper.append(" -->\n"); helper.closeComment(CMS_PAGE_TAG); }
From source file:net.technicpack.launcher.lang.ResourceLoader.java
private Locale matchClosestSupportedLocale(Locale definiteLocale) { Locale bestSupportedLocale = null; int bestLocaleScore = 0; for (int i = 0; i < SUPPORTED_LOCALES.length; i++) { Locale testLocale = SUPPORTED_LOCALES[i]; int testScore = 0; if (testLocale.getLanguage().equals(definiteLocale.getLanguage())) { testScore++;// w w w.j ava2 s .co m if (testLocale.getCountry().equals(definiteLocale.getCountry())) { testScore++; if (testLocale.getVariant().equals(definiteLocale.getVariant())) { testScore++; } } } if (testScore != 0 && testScore > bestLocaleScore) { bestLocaleScore = testScore; bestSupportedLocale = testLocale; } } if (bestSupportedLocale != null) { return bestSupportedLocale; } else { return Locale.getDefault(); } }
From source file:org.echocat.jomon.runtime.i18n.ResourceBundles.java
@Nonnull public ResourceBundle getBundle(@Nullable Locale locale) throws NoSuchElementException { ResourceBundle resourceBundle = _localeToBundleCache.get(locale); if (resourceBundle == null) { final List<ResourceBundle> candidates = new ArrayList<>(10); if (locale != null && !isEmpty(locale.getLanguage()) && !isEmpty(locale.getCountry()) && !isEmpty(locale.getVariant())) { final ResourceBundle bundle = _localeToBundle .get(new Locale(locale.getLanguage(), locale.getCountry(), locale.getVariant())); if (bundle != null) { candidates.add(bundle);//from w w w.jav a2s . co m } } if (locale != null && !isEmpty(locale.getLanguage()) && !isEmpty(locale.getCountry())) { final ResourceBundle bundle = _localeToBundle .get(new Locale(locale.getLanguage(), locale.getCountry())); if (bundle != null) { candidates.add(bundle); } } if (locale != null && !isEmpty(locale.getLanguage())) { final ResourceBundle bundle = _localeToBundle.get(new Locale(locale.getLanguage())); if (bundle != null) { candidates.add(bundle); } } final ResourceBundle bundle = _localeToBundle.get(new Locale("")); if (bundle != null) { candidates.add(bundle); } if (candidates.isEmpty()) { throw new NoSuchElementException("There is no bundle for locale " + locale + "."); } resourceBundle = new CombinedResourceBundle(candidates); _localeToBundleCache.put(locale, resourceBundle); } return resourceBundle; }
From source file:org.primeframework.mvc.control.form.CountrySelect.java
/** * Adds the countries Map and then calls super. *//*from www. java 2 s .c o m*/ @Override protected Map<String, Object> makeParameters() { LinkedHashMap<String, String> countries = new LinkedHashMap<String, String>(); if (attributes.containsKey("includeBlank") && (Boolean) attributes.get("includeBlank")) { countries.put("", ""); } String preferred = (String) attributes.get("preferredCodes"); if (preferred != null) { String[] parts = preferred.split(","); for (String part : parts) { Locale locale = new Locale("", part); countries.put(part, locale.getDisplayCountry(locale)); } } SortedSet<Locale> alphabetical = new TreeSet<Locale>(new LocaleComparator(locale)); Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { if (StringUtils.isNotBlank(locale.getCountry()) && StringUtils.isNotBlank(locale.getDisplayCountry(locale))) { alphabetical.add(locale); } } for (Locale locale : alphabetical) { if (!countries.containsKey(locale.getCountry())) { countries.put(locale.getCountry(), locale.getDisplayCountry(this.locale)); } } attributes.put("items", countries); return super.makeParameters(); }