Search code examples
androidlocale

How to get the full language code for default locale (e.g. zh-hans)


It seems that Locale.getDefault().getLanguage() only returns the language code (e.g. en or zh). Is there a way to get the full language code and script (e.g. zh-hans and en-us)? Locale.getDefault().getScript() is API 21+, and it seems to return the empty string even on applicable OSes.


Solution

  • Use simply toString

    Locale.getDefault().toString()
    

    Or if you need a script separately, take a look at How to get the script from a Locale object on Android?