java.util.Locale.getISO3Country()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中java.util.Locale.getISO3Country()方法的一些代码示例,展示了Locale.getISO3Country()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.getISO3Country()方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:getISO3Country

Locale.getISO3Country介绍

[英]Returns the three-letter ISO 3166 country code which corresponds to the country code for this Locale.
[中]返回与此区域设置的国家/地区代码相对应的三个字母的ISO 3166国家/地区代码。

代码示例

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory getISO3Country(Environment env, Memory... args) {
  return StringMemory.valueOf(locale.getISO3Country());
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * 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;
  }
}

代码示例来源:origin: intel-hadoop/HiBench

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();
}

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
 * 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;
}

代码示例来源:origin: stackoverflow.com

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;
 }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

locale.getISO3Country();
} catch (MissingResourceException e) {
  throw new IllegalArgumentException("Unknown country: " + parts[1], e);

代码示例来源:origin: aws-amplify/aws-sdk-android

@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);
}

代码示例来源:origin: osmlab/atlas

private static boolean hasISO3Country(final Locale locale)
{
  try
  {
    locale.getISO3Country();
    return true;
  }
  catch (final MissingResourceException oops)
  {
    return false;
  }
}

代码示例来源:origin: com.anrisoftware.globalpom/globalpomutils-core

/**
 * @see java.util.Locale#getISO3Country()
 */
public String getISO3Country() throws MissingResourceException {
  return locale.getISO3Country();
}

代码示例来源:origin: stackoverflow.com

String userCountry = Locale.getDefault().getISO3Country();

if (EURO_COUNTRIES.contains(userCountry)) {
  // do something
}

代码示例来源:origin: mobileprint/android-print-sdk

private boolean isChina() {
  if (locale == null) {
    locale = context.getResources().getConfiguration().locale.getISO3Country();
  }
  return locale.equals("CHN") || locale.equals("HKG");
}

代码示例来源:origin: stackoverflow.com

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" ) );
 }

代码示例来源:origin: org.n52.janmayen/janmayen

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();
}

代码示例来源:origin: org.n52.janmayen/janmayen

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();
}

代码示例来源:origin: LonamiWebs/Stringlate

private static boolean isValid(final Locale locale) {
  try {
    return locale.getISO3Language() != null && locale.getISO3Country() != null;
  } catch (MissingResourceException ignored) {
    return false;
  }
}

代码示例来源:origin: stackoverflow.com

if (Locale.getDefault().getISO3Country().equals("ESP"))
{
  Locale[] locales = Locale.getAvailableLocales();
  for (Locale loc : locales)
    if (loc.getISO3Language().equals("SPA"))
    {
      Locale.setDefault(loc);
      break;
    }
}

代码示例来源:origin: mukeshsolanki/country-picker-android

public Country getCountryByLocale(@NonNull Locale locale) {
 String countryIsoCode = locale.getISO3Country().substring(0, 2).toLowerCase();
 return getCountryByISO(countryIsoCode);
}

代码示例来源:origin: org.openbase/jps

private boolean isValid(final Locale locale) {
    try {
      return locale.getISO3Language() != null && locale.getISO3Country() != null;
    } catch (MissingResourceException ex) {
      return false;
    }
  }
}

代码示例来源:origin: stackoverflow.com

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
  }
}

代码示例来源:origin: org.openestate.io/OpenEstate-IO-IS24-CSV

public void setObjektLand(String value) {
  this.set(FIELD_OBJEKT_LAND,
      StringUtils.defaultIfBlank(Is24CsvFormat.getCountryCode(value), Locale.GERMANY.getISO3Country()));
}

相关文章