0

Ask the title, how can i get the languge from locale in android? I used countrycodepicker to get country code and used locale.getLanguage to get language of that country. But when i choose usa, france, british, ... it get wrong language such as USA - ikt; France - gsw?

String countryCode = ccp.getSelectedCountryNameCode();
        String languageCode = null;
        Locale[] all = Locale.getAvailableLocales();
        for (Locale locale : all) {
            String country = locale.getCountry();
            if(country.equalsIgnoreCase(countryCode)){
                languageCode = locale.getLanguage();
            }
        }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Locale.getDefault().getDisplayLanguage(); please check with this. you can get name of default language. In your case check the mehod locale.getDisplayLanguage() – Avinash tiwari Dec 06 '19 at 08:20
  • no, i don't want to get the default language. I use country code picker to get country code of any country. then i want to get the language of that country – Đức Huy Dec 06 '19 at 09:09
  • locale.getLanguage() instead of this you can use locale.getDisplayLanguage() in your code – Avinash tiwari Dec 06 '19 at 09:35

1 Answers1

0

To get the current Locale language, Please use the below method:

Locale.getDefault().getLanguage()
  • i want to get the language of the country which i am selecting by country code picker, if i use Locale.getDefault().getLanguage() it will always return the default language – Đức Huy Dec 06 '19 at 09:03
  • Yeah, the default in terms of current locale language. – Parthiv Mistri Dec 06 '19 at 09:10
  • i tried, but when i choose USA, the language is lkt, not en. Same problem with some country such as: United Kingdom, France, ... Do you know why? – Đức Huy Dec 07 '19 at 08:47