List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:org.squale.welcom.taglib.aide.Aide.java
/** * Ajoute une Aideressource pour une locale donne * /*from w w w . j a v a2 s. co m*/ * @param locale la locale * @throws AideException l'exception susceptible d'etre levee */ public void addAideRessource(final Locale locale) throws AideException { if (fileBundle != null) { hAideLocale.put(locale, new AideRessource(fileBundle, locale)); log.info("Chargement de l'aide pour la locale : " + locale.getCountry() + "_" + locale.getLanguage()); } else { throw new AideException("Nom du fichier Bundle d'Aide vide"); } }
From source file:org.codehaus.mojo.pml10n.GoogleInterpreter.java
private String fromLocale(Locale source) { String googleLanguage = (String) googleLanguages.get(source); if (googleLanguage == null) { googleLanguage = (String) googleLanguages.get(new Locale(source.getLanguage(), source.getCountry())); }/*from w ww .j a v a2 s . c om*/ if (googleLanguage == null) { googleLanguage = (String) googleLanguages.get(new Locale(source.getLanguage())); } return googleLanguage; }
From source file:org.echocat.locela.api.java.support.StandardLocaleNormelizer.java
protected boolean startsWith(@Nullable Locale toTest, @Nullable Locale with) { final boolean result; if (toTest != null && with != null) { final String language = with.getLanguage(); if (!isEmpty(language)) { if (language.equals(toTest.getLanguage())) { final String country = with.getCountry(); if (!isEmpty(country)) { if (country.equals(toTest.getCountry())) { final String variant = with.getCountry(); if (!isEmpty(variant)) { // noinspection RedundantIfStatement if (variant.equals(toTest.getCountry())) { result = true; } else { result = false; }//w w w.j a va2 s. co m } else { result = true; } } else { result = false; } } else { result = true; } } else { result = false; } } else { result = true; } } else { result = toTest == null && with == null; } return result; }
From source file:org.nanoframework.commons.util.StringUtils.java
/** * Determine the RFC 3066 compliant language tag, * as used for the HTTP "Accept-Language" header. * @param locale the Locale to transform to a language tag * @return the RFC 3066 compliant language tag as {@code String} *//* w w w .j ava 2 s. co m*/ public static String toLanguageTag(Locale locale) { return locale.getLanguage() + (hasText(locale.getCountry()) ? '-' + locale.getCountry() : ""); }
From source file:org.alfresco.grid.WebDriverFactory.java
/** * Converts locale to string. /*from w w w . j a va 2s . co m*/ * @param locale {@link Locale} locale * @return String locale in string */ private String formatLocale(Locale locale) { if (locale == null) { throw new IllegalArgumentException("Locale value is required"); } return locale.getCountry().isEmpty() ? locale.getLanguage() : locale.getLanguage() + "-" + locale.getCountry().toLowerCase(); }
From source file:net.technicpack.ui.lang.ResourceLoader.java
public String getCodeFromLocale(Locale locale) { if (locale.getLanguage().isEmpty()) { return "default"; } else if (locale.getCountry().isEmpty()) { return locale.getLanguage(); } else if (locale.getVariant().isEmpty()) { return String.format("%s,%s", locale.getLanguage(), locale.getCountry()); } else {// w w w . j a va 2s. com return String.format("%s,%s,%s", locale.getLanguage(), locale.getCountry(), locale.getVariant()); } }
From source file:com.android.googlesearch.SuggestionProvider.java
/** * Queries for a given search term and returns a cursor containing * suggestions ordered by best match./*from w w w . j av a 2 s. c o m*/ */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { String query = selectionArgs[0]; if (TextUtils.isEmpty(query)) { return null; } if (!isNetworkConnected()) { Log.i(LOG_TAG, "Not connected to network."); return null; } try { query = URLEncoder.encode(query, "UTF-8"); // NOTE: This code uses resources to optionally select the search Uri, based on the // MCC value from the SIM. iThe default string will most likely be fine. It is // paramerterized to accept info from the Locale, the language code is the first // parameter (%1$s) and the country code is the second (%2$s). This code *must* // function in the same way as a similar lookup in // com.android.browser.BrowserActivity#onCreate(). If you change // either of these functions, change them both. (The same is true for the underlying // resource strings, which are stored in mcc-specific xml files.) if (mSuggestUri == null) { Locale l = Locale.getDefault(); String language = l.getLanguage(); String country = l.getCountry().toLowerCase(); // Chinese and Portuguese have two langauge variants. if ("zh".equals(language)) { if ("cn".equals(country)) { language = "zh-CN"; } else if ("tw".equals(country)) { language = "zh-TW"; } } else if ("pt".equals(language)) { if ("br".equals(country)) { language = "pt-BR"; } else if ("pt".equals(country)) { language = "pt-PT"; } } mSuggestUri = getContext().getResources().getString(R.string.google_suggest_base, language, country) + "json=true&q="; } HttpPost method = new HttpPost(mSuggestUri + query); StringEntity content = new StringEntity(""); method.setEntity(content); HttpResponse response = mHttpClient.execute(method); if (response.getStatusLine().getStatusCode() == 200) { /* Goto http://www.google.com/complete/search?json=true&q=foo * to see what the data format looks like. It's basically a json * array containing 4 other arrays. We only care about the middle * 2 which contain the suggestions and their popularity. */ JSONArray results = new JSONArray(EntityUtils.toString(response.getEntity())); JSONArray suggestions = results.getJSONArray(1); JSONArray popularity = results.getJSONArray(2); return new SuggestionsCursor(suggestions, popularity); } } catch (UnsupportedEncodingException e) { Log.w(LOG_TAG, "Error", e); } catch (IOException e) { Log.w(LOG_TAG, "Error", e); } catch (JSONException e) { Log.w(LOG_TAG, "Error", e); } return null; }
From source file:com.puppycrawl.tools.checkstyle.TreeWalkerTest.java
@Test public void testCacheFile() 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); final 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);// w w w . j ava2s .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); // one more time to reuse cache verify(checker, pathToEmptyFile, pathToEmptyFile, expected); }
From source file:com.salesmanager.customer.profile.LogonAction.java
/** * Prepares object for registration form * //from www . j av a 2 s. c om * @return */ public String displayRegistration() { try { MerchantStore store = SessionUtil.getMerchantStore(getServletRequest()); Integer merchantid = store.getMerchantId(); int shippingCountryId = PropertiesUtil.getConfiguration().getInt("core.system.defaultcountryid", Constants.US_COUNTRY_ID); Locale locale = super.getLocale(); String countryCode = locale.getCountry(); if (!StringUtils.isBlank(countryCode)) { CountryDescription country = CountryUtil.getCountryByIsoCode(countryCode, locale); shippingCountryId = country.getId().getCountryId(); } prepareZones(); generateCaptchaImage(); Customer c = new Customer(); c.setCustomerCountryId(shippingCountryId); c.setCustomerBillingCountryId(shippingCountryId); this.setCustomer(c); } catch (Exception e) { logger.error(e); } return SUCCESS; }
From source file:org.sakaiproject.portal.charon.handlers.BasePortalHandler.java
protected void addLocale(PortalRenderContext rcontext, Site site, String userId) { Locale prevLocale = null;//from w w w.j a v a2s . com ResourceLoader rl = new ResourceLoader(); if (userId != null) { prevLocale = rl.getLocale(); } Locale locale = setSiteLanguage(site); if (log.isDebugEnabled()) { log.debug("Locale for site " + site.getId() + " = " + locale.toString()); } String localeString = locale.getLanguage(); String country = locale.getCountry(); if (country.length() > 0) localeString += "-" + country; rcontext.put("locale", localeString); rcontext.put("dir", rl.getOrientation(locale)); if (prevLocale != null && !prevLocale.equals(locale)) { // if the locale was changed, clear the date/time format which was cached in the previous locale timeService.clearLocalTimeZone(userId); } }