@Test @Config(qualifiers = "b+fr+Cyrl+UK") public void localeIsSet() throws Exception { bootstrapWrapper.callSetUpApplicationState(); assertThat(Locale.getDefault().getLanguage()).isEqualTo("fr"); assertThat(Locale.getDefault().getScript()).isEqualTo("Cyrl"); assertThat(Locale.getDefault().getCountry()).isEqualTo("UK"); }
@Test public void applyQualifiers_shouldSetLocaleScript() throws Exception { Bootstrap.applyQualifiers("b+sr+Latn", RuntimeEnvironment.getApiLevel(), configuration, displayMetrics); String outQualifiers = ConfigurationV25.resourceQualifierString(configuration, displayMetrics); assertThat(configuration.locale.getScript()).isEqualTo("Latn"); assertThat(outQualifiers).contains("b+sr+Latn"); }
/** * The script tag for this Lang */ public String script() { return locale().getScript(); }
/** * The script tag for this Lang */ public String script() { return locale().getScript(); }
/** * The script tag for this Lang */ public String script() { return locale().getScript(); }
/** * @see java.util.Locale#getScript() */ public String getScript() { return locale.getScript(); }
Locale[] locales = Locale.getAvailableLocales(); for(Locale locale : locales){ if(locale.getCountry().equalsIgnoreCase("RS") && locale.getScript().equalsIgnoreCase("Latn")) { Configuration config = new Configuration(); config.setLocale(locale); // using this to reference my Activity this.getBaseContext().getResources().updateConfiguration(config, this.getBaseContext().getResources().getDisplayMetrics()); break; } }
/** * Constructs a MetaLocale from a Java Locale object. */ public static MetaLocale fromJavaLocale(java.util.Locale java) { // Some confusing cases can arise here based on the getLanguage() method // returning the deprecated language codes in a handful of cases. See // MetaLocaleTest for test cases for these examples. String language = java.getLanguage(); switch (language) { case "iw": language = "he"; break; case "in": language = "id"; break; case "ji": language = "yi"; break; } return new MetaLocale(language, java.getScript(), java.getCountry(), java.getVariant()); }
@Override public boolean put(String name, T t, Locale... locale) { Params.notNullOrEmpty(name, "Name"); Params.notNullOrEmpty(locale, "Locale"); Params.empty(locale[0].getVariant(), "Locale variant"); Params.empty(locale[0].getScript(), "Locale script"); Params.empty(locale[0].getExtensionKeys(), "Locale extension"); Map<String, T> maps = localeMaps.get(locale[0].toLanguageTag()); if (maps == null) { maps = new HashMap<String, T>(); localeMaps.put(locale[0].toLanguageTag(), maps); } return maps.put(name, t) != null; }
String script = locale.getScript(); String country = locale.getCountry(); String variant = locale.getVariant();
String script = locale.getScript(); String country = locale.getCountry(); String variant = locale.getVariant();
/** * Get named objects map bound to requested locale settings. * * @param locale locale settings to retrieve objects map for. * @return objects map bound to requested locale settings. * @throws IllegalArgumentException if <code>locale</code> argument has variant, script or extension. */ private Map<String, T> maps(Locale locale) { Params.empty(locale.getVariant(), "Locale variant"); Params.empty(locale.getScript(), "Locale script"); Params.empty(locale.getExtensionKeys(), "Locale extension"); Map<String, T> maps = localeMaps.get(locale.toLanguageTag()); if (maps == null) { throw new BugError("Missing repository for locale |%s|.", locale); } return maps; } }
.setScript(locale.getScript()).build().toLanguageTag(); Function<Locale, String> toLanguageRegion = locale -> new Locale.Builder().setLanguage(locale.getLanguage()) .setRegion(locale.getCountry()).build().toLanguageTag(); .filter(locale -> !locale.getScript().isEmpty() && !locale.getCountry().isEmpty()) .filter(locale -> allTags.contains(toLanguageScript.apply(locale))).map(locale -> { String languageTag = locale.toLanguageTag();
sb.append(country); String script = locale.getScript(); if (!script.isEmpty()) { sb.append('#');
/** * Construct I18N file instance bound to specified locale settings. Given locale should be based only on language and * optional country, encoded with ISO 639 alpha-2, respective ISO 3166 alpha-2; script, variant and extension should be * empty. * * @param file underlying filesystem file path, * @param locale locale settings. * @throws IllegalArgumentException if <code>locale</code> argument is null or has variant, script or extension. */ I18nFile(File file, Locale locale) throws IllegalArgumentException { this.file = file; Params.notNull(locale, "Locale"); Params.empty(locale.getVariant(), "Locale variant"); Params.empty(locale.getScript(), "Locale script"); Params.empty(locale.getExtensionKeys(), "Locale extension"); this.locale = locale; }