EDIT:
I have a language name in English, nothing else. How do I get the code for it. e.g.:
- English -> en
- German -> de
- Spanish -> es
- Chinese -> zh
EDIT:
I have a language name in English, nothing else. How do I get the code for it. e.g.:
LanguageCode enum contained in com.neovisionaries:nv-i18n:1.11 (or later) has findByName
methods to get language codes whose names match a given pattern.
List<LanguageCode> findByName(String regex);
List<LanguageCode> findByName(Pattern pattern);
To get ISO 639-1 codes (2-letter, lower-case alphabets) for English, German, Spanish and Chinese:
String[] names = { "English", "German", "Spanish", "Chinese" };
for (String name : names)
{
String code = LanguageCode.findByName(name).get(0).name();
System.out.format("%s -> %s\n", name, code);
}
The above code snippet will output:
English -> en
German -> de
Spanish -> es
Chinese -> zh
https://github.com/TakahikoKawasaki/nv-i18n
http://takahikokawasaki.github.io/nv-i18n/
<dependency>
<groupId>com.neovisionaries</groupId>
<artifactId>nv-i18n</artifactId>
<version>1.11</version>
</dependency>
We have to set the Language name and country name for locale to get this
// Locale(String language, String country)
Locale locale = new Locale("German" , "DE");
// print ISO3 country name for corresponding locale
System.out.println("Name:" + locale.getISO3Country());
This returns ISO3Country name as DEU