本文整理了Java中java.util.Locale.getISOLanguages()
方法的一些代码示例,展示了Locale.getISOLanguages()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.getISOLanguages()
方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:getISOLanguages
[英]Returns an array of strings containing all the two-letter ISO 639-1 language codes that can be used as the language code when constructing a Locale.
[中]返回一个字符串数组,其中包含所有两个字母的ISO 639-1语言代码,这些代码在构造区域设置时可用作语言代码。
代码示例来源:origin: ankidroid/Anki-Android
/**
* Convert from 3 letter ISO 639-2 language code to ISO 639-1
* @param req 3 letter language code
* @return 2 letter language code
*/
public static String requestToResponseLangCode(String req) {
if (locale_map == null) {
String[] languages = Locale.getISOLanguages();
locale_map = new HashMap<>(languages.length);
for (String language : languages) {
Locale locale = new Locale(language);
locale_map.put(locale.getISO3Language(), locale);
}
}
return locale_map.get(req).getLanguage();
}
}
代码示例来源:origin: stackoverflow.com
String[] languages = Locale.getISOLanguages();
Map<String, Locale> localeMap = new HashMap<String, Locale>(languages.length);
for (String language : languages) {
Locale locale = new Locale(language);
localeMap.put(locale.getISO3Language(), locale);
}
代码示例来源:origin: apache/opennlp
public static void checkLanguageCode(String code) {
List<String> languageCodes = new ArrayList<>();
languageCodes.addAll(Arrays.asList(Locale.getISOLanguages()));
languageCodes.add("x-unspecified");
if (!languageCodes.contains(code)) {
throw new TerminateToolException(1, "Unknown language code " + code + ", " +
"must be an ISO 639 code!");
}
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
private Map<String, String> _getISOLanguages(Locale locale) {
Map<String, String> isoLanguages = new TreeMap<>(
String.CASE_INSENSITIVE_ORDER);
for (String isoLanguageId : Locale.getISOLanguages()) {
Locale isoLocale = _fromLanguageId(isoLanguageId, true);
isoLanguages.put(
isoLocale.getDisplayLanguage(locale), isoLanguageId);
}
return isoLanguages;
}
代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures
if (!Arrays.asList(Locale.getISOLanguages()).contains(language)) {
return null; // throw new IllegalArgumentException("Unrecognized language value: '" + language + "' isn't a valid ISO language");
代码示例来源:origin: stackoverflow.com
for(String lang : Locale.getISOLanguages()) {
System.out.println(lang);
}
代码示例来源:origin: org.eclipse.scout.sdk.s2e/org.eclipse.scout.sdk.s2e.nls
public LanguageSmartFieldModel() {
String[] isoLanguages = Locale.getISOLanguages();
List<Locale> locs = new ArrayList<>(isoLanguages.length);
for (String isoLang : isoLanguages) {
locs.add(new Locale(isoLang));
}
m_locales = locs;
}
代码示例来源:origin: stackoverflow.com
/**
* This is the code used to generate the enum content
*/
public static void main(String[] args) {
String[] codes = java.util.Locale.getISOLanguages();
for (String isoCode: codes) {
Locale locale = new Locale(isoCode);
System.out.println(isoCode.toUpperCase() + "(\"" + locale.getDisplayLanguage(locale) + "\"),");
}
}
代码示例来源:origin: stackoverflow.com
public class TestLocale
{
public static void main(String[] args) {
String[] allLangs = Locale.getISOLanguages();
String[] deprecatedLangs = {"ji", "in", "iw"};
ArrayList<String> validLangs = new ArrayList<String>(Arrays.asList(allLangs));
validLangs.removeAll(Arrays.asList(deprecatedLangs));
for (String lng : validLangs) {
System.out.println(lng);
}
}
}
代码示例来源:origin: org.apache.opennlp/opennlp-tools
public static void checkLanguageCode(String code) {
List<String> languageCodes = new ArrayList<>();
languageCodes.addAll(Arrays.asList(Locale.getISOLanguages()));
languageCodes.add("x-unspecified");
if (!languageCodes.contains(code)) {
throw new TerminateToolException(1, "Unknown language code " + code + ", " +
"must be an ISO 639 code!");
}
}
代码示例来源:origin: stackoverflow.com
public final class IsoUtil {
private static final Set<String> ISO_LANGUAGES = new HashSet<String>
(Arrays.asList(Locale.getISOLanguages()));
private static final Set<String> ISO_COUNTRIES = new HashSet<String>
(Arrays.asList(Locale.getISOCountries()));
private IsoUtil() {}
public static boolean isValidISOLanguage(String s) {
return ISO_LANGUAGES.contains(s);
}
public static boolean isValidISOCountry(String s) {
return ISO_COUNTRIES.contains(s);
}
}
代码示例来源:origin: ai.idylnlp/idylnlp-opennlp-tools-1.8.3
public static void checkLanguageCode(String code) {
List<String> languageCodes = new ArrayList<>();
languageCodes.addAll(Arrays.asList(Locale.getISOLanguages()));
languageCodes.add("x-unspecified");
if (!languageCodes.contains(code)) {
throw new TerminateToolException(1, "Unknown language code " + code + ", " +
"must be an ISO 639 code!");
}
}
代码示例来源:origin: stackoverflow.com
Locale.getISOCountries(); // Returns list of ISO country codes
Locale.getISOLanguages(); // Returns list of ISO language codes
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-spellchecker
public static String getErrorsForLocale(String locale) {
if (locale.length() == 0) {
return "ERR_LocaleIsEmpty";
}
String[] components = locale.split("_");
if (components.length > 3) {
return "ERR_InvalidLocale";
}
if (!Arrays.asList(Locale.getISOLanguages()).contains(components[0])) {
return "ERR_UnknownLanguage";
}
if (components.length > 1) {
if (!Arrays.asList(Locale.getISOCountries()).contains(components[1])) {
return "ERR_UnknownCountry";
}
if (!Arrays.asList(Locale.getAvailableLocales()).contains(new Locale(components[0], components[1]))) {
return "ERR_UnsupportedLocale";
}
}
return null;
}
代码示例来源:origin: stackoverflow.com
Date date = new Date();
int n = 0;
for (String country : Locale.getISOCountries()) {
for (String language : Locale.getISOLanguages()) {
Locale loc = new Locale(language, country);
String as = "";
String prev = null;
for (int i = 0; i < 20; ++i) {
++n;
as += "a";
String current = new SimpleDateFormat(as, loc).format(date);
if (prev != null && !prev.equals(current)) {
System.out.println("Locale: " + loc + ", as=" + as + ", current="
+ prev + ", next=" + current);
}
prev = current;
}
}
}
System.out.println("Tried out " + n + " combinations.");
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-propertyeditors
public void addBaseItems(List list) {
ReferenceDataItem item;
String[] languageCodes;
super.addBaseItems(list);
list.add(newItem(
"", // NOI18N
null,
true,
false));
languageCodes = Locale.getISOLanguages();
for (int i = 0; i < languageCodes.length; i++) {
Locale locale = new Locale(languageCodes[i]);
item = newItem(locale.getDisplayLanguage(), languageCodes[i], false, false);
list.add(item);
}
}
代码示例来源:origin: LonamiWebs/Stringlate
public LocaleEntryAdapter(final Context context, boolean showCountrySpecific, boolean showMoreLocales) {
mPreferredLocale = new AppSettings(context).getLanguage();
mShowMoreLocales = showMoreLocales;
// Create a map {locale code: Locale} to behave like a set and avoid duplicates
final HashMap<String, Locale> locales = new HashMap<>();
for (Locale locale : Locale.getAvailableLocales()) {
if (showCountrySpecific || locale.getCountry().isEmpty())
locales.put(LocaleString.getFullCode(locale), locale);
}
if (mShowMoreLocales) {
for (String isoLang : Locale.getISOLanguages()) {
if (!locales.containsKey(isoLang))
locales.put(isoLang, new Locale(isoLang));
}
}
// Once everything is filtered, fill in the array list
initLocales(locales.values());
}
代码示例来源:origin: com.phloc/phloc-commons-jdk5
private static void _initialFillCache ()
{
// add pseudo locales
_initialAdd (CGlobal.LOCALE_ALL);
_initialAdd (CGlobal.LOCALE_INDEPENDENT);
// add all predefined languages
for (final Locale aLocale : Locale.getAvailableLocales ())
_initialAdd (aLocale);
// http://forums.sun.com/thread.jspa?threadID=525482&tstart=1411
for (final String sCountry : Locale.getISOCountries ())
_initialAdd (new Locale ("", sCountry));
for (final String sLanguage : Locale.getISOLanguages ())
_initialAdd (new Locale (sLanguage, ""));
}
代码示例来源:origin: com.hurence.logisland/logisland-api
@Override
public ValidationResult validate(final String subject, final String value) {
String reason = String.format("'%s' is not a supported language tag", value);
for (String tag : Locale.getISOLanguages()) {
if (tag.equals(value)) reason = null;
}
return new ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(reason == null).build();
}
};
代码示例来源:origin: org.eclipse.mylyn.docs/org.eclipse.mylyn.docs.epub.core
public PublicationProxy(Publication publication, File markupFile) {
this.publication = publication;
this.markupFile = markupFile;
String id = publication.getPackage().getUniqueIdentifier();
if (id == null || id.trim().length() == 0) {
publication.getPackage().setUniqueIdentifier(ID);
publication.addIdentifier(ID, "UUID", UUID.randomUUID().toString()); //$NON-NLS-1$
}
// Clear everything except the metadata
publication.getPackage().getManifest().getItems().clear();
publication.getPackage().getGuide().getGuideItems().clear();
publication.getPackage().getSpine().getSpineItems().clear();
sorted_locales = new TreeMap<String, String>();
String[] iso639s = Locale.getISOLanguages();
for (String iso639 : iso639s) {
Locale locale = new Locale(iso639);
sorted_locales.put(locale.getDisplayLanguage(), locale.getLanguage());
}
}
内容来源于网络,如有侵权,请联系作者删除!