How to get locale with region?

后端 未结 3 1725
不思量自难忘°
不思量自难忘° 2021-02-15 06:30

I am trying to get the current device locale with the region like \"en_us\",\"en_gb\".

I am calling Locale.getDefault().getLanguage() and it returns only th

3条回答
  •  情话喂你
    2021-02-15 07:08

    Format like "en_us" or "en_gb" has "language code"_"country code"

    A Locale object contains both country code and language code.

    So you can use below snippet to format your own code..

    String cCode = Locale.getDefault().getCountry();
    String lCode = Locale.getDefault().getLanguage();
    String code = lCode+"_"+cCode;
    

    or

    you can use toString() method on Locale object to get the data

    String code = Locale.getDefault().toString();
    

提交回复
热议问题