List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:com.android.quicksearchbox.google.GoogleSuggestionProvider.java
/** * Queries for a given search term and returns a cursor containing * suggestions ordered by best match./* www . j av a2 s . co m*/ */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { String query = getQuery(uri); 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="; } String suggestUri = mSuggestUri + query; if (DBG) Log.d(LOG_TAG, "Sending request: " + suggestUri); HttpGet method = new HttpGet(suggestUri); 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); if (DBG) Log.d(LOG_TAG, "Got " + suggestions.length() + " results"); return new SuggestionsCursor(suggestions, popularity); } else { if (DBG) Log.d(LOG_TAG, "Request failed " + response.getStatusLine()); } } 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.google.cloud.android.speech.ApiFragment.java
private String getDefaultLanguageCode() { final Locale locale = Locale.getDefault(); final StringBuilder language = new StringBuilder(locale.getLanguage()); final String country = locale.getCountry(); if (!TextUtils.isEmpty(country)) { language.append("-"); language.append(country);/*from w w w . j a va 2 s . c o m*/ } return language.toString(); }
From source file:gov.nih.nci.ncicb.cadsr.service.impl.CaDSRQueryServiceImpl.java
public Properties getApplicationProperties(Locale locale) throws Exception { ApplicationPropertiesQuery query = new ApplicationPropertiesQuery(); try {/*ww w .j av a2 s . c om*/ query.setDataSource(getDataSource()); query.setSql(CaDSRConstants.UMLBROWSER, locale.getCountry()); query.execute(); } catch (Exception exp) { log.error("Error getting properties from database"); throw exp; } return query.getProperties(); }
From source file:com.properned.model.MultiLanguageProperties.java
private String getFileName(Locale locale) { String fileName = baseName.get(); if (StringUtils.isNotEmpty(locale.getLanguage())) { fileName += "_" + locale.getLanguage(); }// ww w . j ava 2 s .c o m if (StringUtils.isNotEmpty(locale.getCountry())) { fileName += "_" + locale.getCountry(); } fileName += ".properties"; return fileName; }
From source file:de.hybris.platform.acceleratorservices.web.payment.controllers.HostedOrderPageMockController.java
@ModelAttribute("billingCountries") public List<SelectOption> getBillingCountries() { final List<SelectOption> countries = new ArrayList<SelectOption>(); final Locale[] locales = Locale.getAvailableLocales(); final Map<String, String> countryMap = new HashMap<String, String>(); for (final Locale locale : locales) { final String code = locale.getCountry(); final String name = locale.getDisplayCountry(); // putting in a map to remove duplicates if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(name)) { countryMap.put(code, name);//from w w w . ja v a 2s.c om } } for (final String key : countryMap.keySet()) { countries.add(new SelectOption(key, countryMap.get(key))); } Collections.sort(countries, CountryComparator.INSTANCE); return countries; }
From source file:com.surveypanel.utils.DBMessageSource.java
/** * build an array of alternative locales for the given locale <br/> * result does not contain original locale * @param locale the locale to find alternatives for * @return an array of alternative locales *///w ww . j ava2s. c o m private Locale[] getAlternativeLocales(Locale locale) { Locale[] locales = new Locale[3]; int count = 0; if (locale.getVariant().length() > 0) { // add a locale without the variant locales[count] = new Locale(locale.getLanguage(), locale.getCountry()); count++; } if (locale.getCountry().length() > 0) { // add a locale without the country locales[count] = new Locale(locale.getLanguage()); count++; } if (fallbackLocale != null) { locales[count] = fallbackLocale; } return locales; }
From source file:de.iew.services.impl.MessageBundleServiceImpl.java
protected MessageBundleStore loadBundle(Locale locale, String basename) { List<MessageBundle> messageBundles; if (basename == null) { messageBundles = this.messageBundleDao.findByLocale(locale.getLanguage(), locale.getCountry()); } else {/*from www. ja v a 2 s.co m*/ messageBundles = this.messageBundleDao.findByLocaleAndBasename(locale.getLanguage(), locale.getCountry(), basename); } MessageBundleStore messageBundleStore = new MessageBundleStore(locale, basename); for (MessageBundle messageBundle : messageBundles) { messageBundleStore.put(messageBundle); } return messageBundleStore; }
From source file:org.apache.cocoon.forms.datatype.convertor.LocaleMap.java
/** * Gets an object based on the given locale. An automatic fallback mechanism is used: * if nothing is found for language-COUNTRY-variant, then language-COUNTRY is searched, * the language, and finally "" (empty string). If nothing is found null is returned. */// ww w . ja va 2 s. c om public Object get(Locale locale) { if (map.size() == 0) return null; String full = getFullKey(locale); if (!map.containsKey(full)) { // check more general variant (lang-COUNTRY and lang), and store result in the map // under the full key, so that next time we have a direct hit String altKey = locale.getLanguage() + '-' + locale.getCountry(); Object object = map.get(altKey); if (object != null) { map.put(full, object); return object; } altKey = locale.getLanguage(); object = map.get(altKey); if (object != null) { map.put(full, object); return object; } object = map.get(""); if (object != null) { map.put(full, object); return object; } map.put(full, null); } return map.get(full); }
From source file:architecture.ee.component.core.lifecycle.ConfigServiceImpl.java
/** * ?? ./*from w w w .jav a2 s . com*/ * * @param newLocale */ public void setLocale(Locale newLocale) { String country = newLocale.getCountry(); String language = newLocale.getLanguage(); setApplicationProperty(ApplicationConstants.LOCALE_COUNTRY_PROP_NAME, country); setApplicationProperty(ApplicationConstants.LOCALE_LANGUAGE_PROP_NAME, language); resetL10N(); }
From source file:com.magicmod.mmweather.engine.YahooWeatherProvider.java
private String getLanguage() { Locale locale = mContext.getResources().getConfiguration().locale; String country = locale.getCountry(); String language = locale.getLanguage(); if (TextUtils.isEmpty(country)) { return language; }//from w w w.ja v a 2s .c o m return language + "-" + country; }