List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:Main.java
/** * Converte a Locale object to an xmlLang String * @param locale/*from w w w .j a v a 2 s . c o m*/ * @return String of the form <locale.getLanguage()>-<locale.getCountry()> */ private static String localeToXmlLang(Locale locale) { if (locale == null) { return Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry(); } String lang = locale.getLanguage(); String countryCode = locale.getCountry(); if (countryCode == null || countryCode.length() == 0) { return lang; } else { return new String(lang + "-" + countryCode); } }
From source file:fr.gouv.culture.thesaurus.util.LangUtils.java
public static String localeString(Locale locale) { List<String> components = new LinkedList<String>(); if (StringUtils.isNotEmpty(locale.getLanguage())) { components.add(locale.getLanguage().toLowerCase()); }//w w w.jav a 2 s. c om if (StringUtils.isNotEmpty(locale.getCountry())) { components.add(locale.getCountry().toLowerCase()); } if (StringUtils.isNotEmpty(locale.getVariant())) { components.add(locale.getVariant().toLowerCase()); } return StringUtils.join(components, "-"); }
From source file:de.tudarmstadt.ukp.dkpro.c4corpus.boilerplate.impl.Utils.java
/** * Loads the stop-words list of a given language * * @param locale locale// w w w .j ava2 s .c o m * @return set of stop words * @throws IOException exception */ public static Set<String> loadStopWords(Locale locale) throws IOException { String streamName = "/stoplists/" + locale.getLanguage() + ".txt"; InputStream stream = Utils.class.getResourceAsStream(streamName); if (stream == null) { throw new IOException("Stream " + streamName + " not found"); } List<String> stopList = IOUtils.readLines(stream); return new HashSet<>(stopList); }
From source file:com.googlecode.l10nmavenplugin.model.PropertiesFileUtils.java
/** * Parent locale , ex: en_US => en/*from ww w.j ava2s . c o m*/ * * @param locale * @return null if no parent locale */ public static Locale getParentLocale(Locale locale) { Locale parentLocale = null; if (locale != null) { String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); if (!StringUtils.isEmpty(language)) { if (!StringUtils.isEmpty(variant)) { parentLocale = new Locale(language, country); } else if (!StringUtils.isEmpty(country)) { parentLocale = new Locale(language); } } } return parentLocale; }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.helpers.boilerplateremoval.impl.Utils.java
/** * load the stop-words list of a given language * * @param locale/*from w w w. j a v a2 s . c o m*/ * @return * @throws URISyntaxException * @throws IOException */ public static Set<String> loadStopWords(Locale locale) throws IOException { String streamName = "/stoplists/" + locale.getLanguage() + ".txt"; InputStream stream = Utils.class.getResourceAsStream(streamName); if (stream == null) { throw new IOException("Stream " + streamName + " not found"); } List<String> stopList = IOUtils.readLines(stream); HashSet<String> stopSet = new HashSet<String>(stopList); return stopSet; }
From source file:Main.java
/** * Convert a locale into a string that is conform with XML's xml:lang attribute. * Basically it is language-COUNTRY, e.g. en-US. * * @param locale a locale, must not be null * @return/*from w ww. j av a 2s .c o m*/ * @throws IllegalArgumentException if locale is null */ public static String locale2xmllang(Locale locale) { if (locale == null) throw new IllegalArgumentException("Locale must not be null"); String country = locale.getCountry(); if (!"".equals(country)) return locale.getLanguage() + "-" + country; return locale.getLanguage(); }
From source file:com.limegroup.gnutella.gui.LanguageUtils.java
/** * Applies this language code to be the new language of the program. *//* ww w.j a v a2 s .com*/ public static void setLocale(Locale locale) { ApplicationSettings.LANGUAGE.setValue(locale.getLanguage()); ApplicationSettings.COUNTRY.setValue(locale.getCountry()); ApplicationSettings.LOCALE_VARIANT.setValue(locale.getVariant()); GUIMediator.resetLocale(); }
From source file:com.limegroup.gnutella.gui.LanguageUtils.java
/** * Returns true if the language of <code>locale</code> is English. *///from w w w.java 2 s. co m public static boolean isEnglishLocale(Locale locale) { return Locale.ENGLISH.getLanguage().equals(locale.getLanguage()); }
From source file:de.onyxbits.raccoon.gplay.PlayManager.java
/** * Create a connection object for accessing Google Play, using an arbitrary * profile//from w ww . java2 s .c om * * @param profile * the profile to use for connecting * @return a connection according to the submitted profile */ public static GooglePlayAPI createConnection(PlayProfile profile) { GooglePlayAPI ret = new GooglePlayAPI(profile.getUser(), profile.getPassword()); ret.setUseragent(profile.getAgent()); ret.setAndroidID(profile.getGsfId()); ret.setToken(profile.getToken()); Locale l = Locale.getDefault(); String s = l.getLanguage(); if (l.getCountry() != null) { s = s + "-" + l.getCountry(); } ret.setLocalization(s); try { HttpClient proxy = createProxyClient(profile); if (proxy != null) { ret.setClient(proxy); } } catch (Exception e) { e.printStackTrace(); } return ret; }
From source file:LocaleMap.java
public static String getString(Locale locale) { boolean hasLanguage = !locale.getLanguage().equals(""); boolean hasCountry = !locale.getCountry().equals(""); boolean hasVariant = !locale.getVariant().equals(""); if (hasLanguage && hasCountry && hasVariant) return locale.getLanguage() + '-' + locale.getCountry() + '-' + locale.getVariant(); else if (hasLanguage && hasCountry) return locale.getLanguage() + '-' + locale.getCountry(); else if (hasLanguage) return locale.getLanguage(); else//www . j ava 2s .c om return ""; }