How to find list of available Locales and Get an existing Locale














































How to find list of available Locales and Get an existing Locale



Here in this example locale is set to German ( de_De ).
locale.setlocale(locale.LC_ALL, 'de_DE')
Note that name may vary accoriding to the Operating System.

Most of the time, it uses the Language Code Identifier (LCID) Reference. For example, de-DE should be stated as de_DE. However, older OS versions might accept the locale in a different format, as shown below:
# using standard Language Code Identifier (LCID) Reference
locale.setlocale(locale.LC_ALL , 'de_DE')
# using ISO country code, alpha-3
locale.setlocale(locale.LC_ALL , 'deu_deu')
# using language name
locale.setlocale(locale.LC_ALL , 'German')

To find List of Available Locale:

The  method is recommended to test out the standard Language Code Identifier Reference first. If you got an error, the next step is to print out the full list of the available locales in your machine.
# for Windows users
for lang in locale.windows_locale.values():
print(lang)
# for different operating systems
for lang in locale.locale_alias.values():
print(lang)

To Get an Existing Locale:

To find the string of an existing locale you can use the following code which is given below:
loc = locale.getlocale()
this code gets you the current locale

<=PREV                                                                                                                                                        NEXT=>





Comments