List of usage examples for java.util Locale toLanguageTag
public String toLanguageTag()
From source file:Main.java
public static void main(String[] args) { Locale locale = new Locale("ENGLISH"); System.out.println("Locale:" + locale); System.out.println(locale.toLanguageTag()); }
From source file:org.eclipse.swt.snippets.Snippet370.java
private static void createForLocale(Shell shell, Locale locale) { System.setProperty("swt.datetime.locale", locale.toLanguageTag()); Composite composite = new Composite(shell, SWT.BORDER); composite.setLayout(new RowLayout(SWT.HORIZONTAL)); new Label(composite, SWT.NONE).setText(locale.toLanguageTag()); new DateTime(composite, SWT.DROP_DOWN); new DateTime(composite, SWT.SHORT); new DateTime(composite, SWT.TIME); }
From source file:com.astamuse.asta4d.util.i18n.LocalizeUtil.java
public static String createLocalizedKey(String str, Locale locale) { if (StringUtils.isEmpty(locale.toLanguageTag())) { return str; }/* ww w . j a v a2 s . c om*/ return str + "::" + locale.toLanguageTag(); }
From source file:org.osiam.addons.selfadministration.util.RegistrationHelper.java
public static Locale getLocale(String userLocale) { if (!Strings.isNullOrEmpty(userLocale)) { Locale locale = new Locale(userLocale); if (!locale.toLanguageTag().equals("und")) { // Undetermined return locale; }/*from w ww. ja v a 2 s .c o m*/ } return LocaleContextHolder.getLocale(); }
From source file:nu.yona.server.goals.service.ActivityCategoryException.java
public static ActivityCategoryException duplicateName(Locale locale, String name) { return new ActivityCategoryException("error.activitycategory.duplicate.name", locale.toLanguageTag(), name); }
From source file:kontrol.HttpUtil.java
public static HttpGet createHttpGet(URI url, Locale locale) { HttpGet request = new HttpGet(url); request.addHeader("Accept-Language", locale.toLanguageTag()); return request; }
From source file:kontrol.HttpUtil.java
public static int getStatus(URI url, Locale locale, int timeout) throws IOException { try {//from ww w .j av a 2s .co m HttpGet request = new HttpGet(url); request.addHeader("Accept-Language", locale.toLanguageTag()); HttpResponse response = getCookielessHttpClient(timeout).execute(request); if (response.getStatusLine().getStatusCode() >= 400) { System.err.println(url + ":" + response.getStatusLine().getStatusCode()); // System.err.println(response.getStatusLine().getStatusCode() + ":" + IOUtils.toString(response.getEntity().getContent())); } return response.getStatusLine().getStatusCode(); } catch (ConnectTimeoutException e) { System.err.println(e.getMessage()); return -1; } catch (Exception e) { System.err.println(e.getMessage()); return 999; } }
From source file:com.android.providers.contacts.LocaleSet.java
/** * Modified from:/*from www . j a va2s. c o m*/ * https://github.com/apache/cordova-plugin-globalization/blob/master/src/android/Globalization.java * * Returns a well-formed ITEF BCP 47 language tag representing this locale string * identifier for the client's current locale * * @return String: The BCP 47 language tag for the current locale */ private static String toBcp47Language(Locale loc) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return loc.toLanguageTag(); } // we will use a dash as per BCP 47 final char SEP = '-'; String language = loc.getLanguage(); String region = loc.getCountry(); String variant = loc.getVariant(); // special case for Norwegian Nynorsk since "NY" cannot be a variant as per BCP 47 // this goes before the string matching since "NY" wont pass the variant checks if (language.equals("no") && region.equals("NO") && variant.equals("NY")) { language = "nn"; region = "NO"; variant = ""; } if (language.isEmpty() || !language.matches("\\p{Alpha}{2,8}")) { language = "und"; // Follow the Locale#toLanguageTag() implementation // which says to return "und" for Undetermined } else if (language.equals("iw")) { language = "he"; // correct deprecated "Hebrew" } else if (language.equals("in")) { language = "id"; // correct deprecated "Indonesian" } else if (language.equals("ji")) { language = "yi"; // correct deprecated "Yiddish" } // ensure valid country code, if not well formed, it's omitted if (!region.matches("\\p{Alpha}{2}|\\p{Digit}{3}")) { region = ""; } // variant subtags that begin with a letter must be at least 5 characters long if (!variant.matches("\\p{Alnum}{5,8}|\\p{Digit}\\p{Alnum}{3}")) { variant = ""; } StringBuilder bcp47Tag = new StringBuilder(language); if (!region.isEmpty()) { bcp47Tag.append(SEP).append(region); } if (!variant.isEmpty()) { bcp47Tag.append(SEP).append(variant); } return bcp47Tag.toString(); }
From source file:com.haulmont.chile.core.datatypes.Datatypes.java
/** * Returns localized format strings.// w w w .j a v a 2s .c o m * @param locale selected locale * @return {@link FormatStrings} object. Throws exception if not found. */ @Nonnull public static FormatStrings getFormatStringsNN(Locale locale) { FormatStrings format = instance.getFormat(locale); if (format == null) { throw new IllegalArgumentException("Not found format strings for locale " + locale.toLanguageTag()); } return format; }
From source file:org.apache.openmeetings.db.dao.label.LabelDao.java
public static String getLabelFileName(Locale l) { String name = APP_RESOURCES_EN; if (!Locale.ENGLISH.equals(l)) { name = String.format(APP_RESOURCES, l.toLanguageTag().replace('-', '_')); }//from ww w. j ava 2s .co m return name; }