@Signature public Memory getISO3Country(Environment env, Memory... args) { return StringMemory.valueOf(locale.getISO3Country()); }
/** * Checks if specified locale object is valid * * @param locale * object for validation * @return true if locale is available */ public static boolean isValid(Locale locale) { try { return locale.getISO3Language() != null && locale.getISO3Country() != null; } catch (MissingResourceException e) { return false; } }
public static void createCCodes(Path hdfs_ccode) throws IOException { Utils.checkHdfsPath(hdfs_ccode); FileSystem fs = hdfs_ccode.getFileSystem(new Configuration()); FSDataOutputStream fout = fs.create(hdfs_ccode); Locale[] locales = Locale.getAvailableLocales(); for( Locale locale : locales ){ String country = null, language = null; try { country = locale.getISO3Country(); language = locale.getLanguage().toUpperCase(); } catch (Exception e) { continue; } if (!"".equals(country) && !"".equals(language)) { String ccode = country + "," + country + "-" + language + "\n"; fout.write(ccode.getBytes("UTF-8")); } } fout.close(); }
/** * Default constructor * * @param context the context */ public EndpointProfileLocation(final PinpointContext context) { String localeCountry; try { localeCountry = context.getApplicationContext().getResources().getConfiguration().locale.getISO3Country(); } catch (final MissingResourceException exception) { log.debug("Locale getISO3Country failed, falling back to getCountry."); localeCountry = context.getApplicationContext().getResources().getConfiguration().locale.getCountry(); } country = localeCountry; }
public void setResources(String locale) { // validate locale Locale lo = parseLocale(locale); if (isValid(lo)) { System.out.println(lo.getDisplayCountry()); } else { System.out.println("invalid: " + locale); } } private Locale parseLocale(String locale) { String[] parts = locale.split("_"); switch (parts.length) { case 3: return new Locale(parts[0], parts[1], parts[2]); case 2: return new Locale(parts[0], parts[1]); case 1: return new Locale(parts[0]); default: throw new IllegalArgumentException("Invalid locale: " + locale); } } private boolean isValid(Locale locale) { try { return locale.getISO3Language() != null && locale.getISO3Country() != null; } catch (MissingResourceException e) { return false; } }
locale.getISO3Country(); } catch (MissingResourceException e) { throw new IllegalArgumentException("Unknown country: " + parts[1], e);
@Test public void testCountryWithInvalidISO3Code() { Context mockApplicationContext = mock(Context.class); android.content.res.Resources mockResources = mock(android.content.res.Resources.class); android.content.res.Configuration mockConfiguration = mock(android.content.res.Configuration.class); mockConfiguration.locale = new Locale("en", "CS"); Context mockedContext = mockContext.getApplicationContext().getApplicationContext(); when(mockResources.getConfiguration()).thenReturn(mockConfiguration); when(mockApplicationContext.getResources()).thenReturn(mockResources); when(mockApplicationContext.getApplicationContext()).thenReturn(mockedContext); when(mockContext.getApplicationContext()).thenReturn(mockApplicationContext); final TargetingClient targetingClient = new TargetingClient(mockContext, mock(ThreadPoolExecutor.class)); final EndpointProfile endpointProfile = targetingClient.currentEndpoint(); String localeCountry; // Old country code for Serbia and Montenegro that has no ISO3 equivalent. // See https://en.wikipedia.org/wiki/ISO_3166-2:CS for more info try { localeCountry = mockContext.getApplicationContext().getResources().getConfiguration().locale.getISO3Country(); } catch (final MissingResourceException exception) { localeCountry = mockContext.getApplicationContext().getResources().getConfiguration().locale.getCountry(); } final EndpointProfileLocation location = endpointProfile.getLocation(); assertTrue(location.getCountry().equalsIgnoreCase(localeCountry)); targetingClient.updateEndpointProfile(endpointProfile); }
private static boolean hasISO3Country(final Locale locale) { try { locale.getISO3Country(); return true; } catch (final MissingResourceException oops) { return false; } }
/** * @see java.util.Locale#getISO3Country() */ public String getISO3Country() throws MissingResourceException { return locale.getISO3Country(); }
String userCountry = Locale.getDefault().getISO3Country(); if (EURO_COUNTRIES.contains(userCountry)) { // do something }
private boolean isChina() { if (locale == null) { locale = context.getResources().getConfiguration().locale.getISO3Country(); } return locale.equals("CHN") || locale.equals("HKG"); }
public static void main(String[] args) { // setup Locale[] availableLocales = Locale.getAvailableLocales(); HashMap<String, String> map = new HashMap<String, String>(); for ( Locale l : availableLocales ) { map.put( l.getCountry(), l.getISO3Country() ); } // usage System.out.println( map.get( "IN" ) ); System.out.println( map.get( "GB" ) ); }
public static String encode(Locale input) { if (input == null) { return null; } String country = input.getISO3Country(); String language = input.getISO3Language(); StringBuilder sb = new StringBuilder(language); if (!country.isEmpty()) { sb.append("-").append(country); } return sb.toString(); }
public String getLangString() { String country = this.lang.getISO3Country(); String language = this.lang.getISO3Language(); StringBuilder sb = new StringBuilder(language); if (!country.isEmpty()) { sb.append("-").append(country); } return sb.toString(); }
private static boolean isValid(final Locale locale) { try { return locale.getISO3Language() != null && locale.getISO3Country() != null; } catch (MissingResourceException ignored) { return false; } }
if (Locale.getDefault().getISO3Country().equals("ESP")) { Locale[] locales = Locale.getAvailableLocales(); for (Locale loc : locales) if (loc.getISO3Language().equals("SPA")) { Locale.setDefault(loc); break; } }
public Country getCountryByLocale(@NonNull Locale locale) { String countryIsoCode = locale.getISO3Country().substring(0, 2).toLowerCase(); return getCountryByISO(countryIsoCode); }
private boolean isValid(final Locale locale) { try { return locale.getISO3Language() != null && locale.getISO3Country() != null; } catch (MissingResourceException ex) { return false; } } }
for (Locale locale : locales) { try { String iso = locale.getISO3Country(); String code = locale.getCountry(); String name = locale.getDisplayCountry(); if (!"".equals(iso) && !"".equals(code) && !"".equals(name)) { countries.add(new Country(iso, code, name)); } catch (MissingResourceException e){ //do nothing } }
public void setObjektLand(String value) { this.set(FIELD_OBJEKT_LAND, StringUtils.defaultIfBlank(Is24CsvFormat.getCountryCode(value), Locale.GERMANY.getISO3Country())); }