Which locale value does Python return for you?

#1

Hi,

I’m working on internalization of my code in Python. Since my language has no other variants but pl_PL, I wonder which values the Python interpreter returns for e.g. en_AU / en_UK / en_GB or es_ES / es_MX system settings. Especially I wonder if en_EN could be the default localization value. Could you please tell me your language and terminal output of commands as below?

OS language: Polish (Poland)

[piotr@asuspro ~]$ python
Python 3.7.2 (default, Jan 10 2019, 23:51:51) 
[GCC 8.2.1 20181127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
('pl_PL', 'UTF-8')
>>> 
0 Likes

#2
[pts/0]-[~]% python
Python 3.6.8 (default, Feb  1 2019, 07:25:12) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
('en_US', 'UTF-8')
1 Like

#3
┌ ~
└> % python                                                                                                                                                                                                                                                                                                                                                                           18:37:25
Python 3.7.2 (default, Jan 10 2019, 23:51:51)
[GCC 8.2.1 20181127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
1 Like

#4

Debian buster:

empty@shinken:~ $ python3
Python 3.7.2+ (default, Feb 27 2019, 15:41:59) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
('en_GB', 'UTF-8')
>>> exit()
empty@shinken:~ $ localectl
   System Locale: LANG=en_GB.UTF-8
                  LANGUAGE=en_GB:en
       VC Keymap: n/a
      X11 Layout: gb
       X11 Model: pc105
empty@shinken:~ $

Also:

empty@shinken:~ $ LC_ALL=C python3
Python 3.7.2+ (default, Feb 27 2019, 15:41:59) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
(None, None)
>>>
1 Like

#5
provakaos@ultimoarchlabs ~ % python
Python 3.7.2 (default, Jan 10 2019, 23:51:51) 
[GCC 8.2.1 20181127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
('it_IT', 'UTF-8')
>>> 
1 Like

#6

It seems my default en_EN does not appear in real life. Very well. The default “Level {} finished in {} moves” may be translated as “Well done, bro” into en_NZ and “Not bad, indeed” into en_GB. :wink:

Seriously: I didn’t know if to use en_GB or en_UK for British. It also turns out that I need to protect the code against (None, None) values (thx @Head_on_a_Stick). I still wonder what it’s going to look like for e.g. variants of Spanish.

Thank you all for help!

1 Like

#7
└> % python                                                  15:54:23
Python 3.7.2 (default, Jan 10 2019, 23:51:51) 
[GCC 8.2.1 20181127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
('es_ES', 'UTF-8')

1 Like