2

I'm using locale.currency(100) to display currency [works fine - gives back '$100.00'], but I can't get it to display Israeli currency...

I tried playing with locale.setlocale(locale.LC_TIME, 'il_IL.UTF-8') but that just prompted Error: unsupported locale setting. (same goes for trying other countries - 'ru_RU.UTF-8')

As @jdehesa commented, the right locale for Israel should be 'he_IL.UTF-8' instead of 'il_IL.UTF-8'. Checked that too, and got the same error.

I have no idea where to look, as the docs and this SO answer didn't help.


My machine's Locale:

C:\> systeminfo | findstr "Locale"
System Locale:             he;Hebrew
Input Locale:              en-us;English (United States)

BTW, I'm using Python3 on Windows 8 (tried checking it also on ideone) for both Python 2&3

CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
  • 2
    Interestingly, I can reproduce the error in Windows with Python 2 but not with Python 3. I don't know what may be making the difference, the point where the exception is raised look pretty similar in both versions of the C module ([2.7](https://github.com/python/cpython/blob/2.7/Modules/_localemodule.c), [3.6](https://github.com/python/cpython/blob/3.6/Modules/_localemodule.c)). Unrelatedly, it seems the right locale for Israel would be `he_IL`. – jdehesa Jul 05 '18 at 13:42
  • 1
    locale.setlocale(locale.LC_ALL,'he_IL.UTF-8') works on my Mac (python 3.6.5) and locale.currency prints ש״ח correctly – Arnon Rotem-Gal-Oz Jul 05 '18 at 15:05

1 Answers1

2

Maybe check first in your terminal which locale is installed in your system (call depends on your os):

$ locale -a

Additional you might set all settings, not only the time ;-)

locale.setlocale(locale.LC_ALL, 'il_IL.UTF-8')

In python that works on my system:

In [1]: import locale

In [2]: locale.setlocale(locale.LC_ALL, '')
Out[2]: 'LC_CTYPE=en_US.UTF-8;LC_NUMERIC=de_DE.UTF-8;LC_TIME=de_DE.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=de_DE.UTF-8;LC_ADDRESS=de_DE.UTF-8;LC_TELEPHONE=de_DE.UTF-8;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=de_DE.UTF-8'

In [3]: locale.currency(100)
Out[3]: '100,00 €'

In [4]: locale.getlocale()
Out[4]: ('en_US', 'UTF-8')

In [5]: locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
Out[5]: 'en_US.UTF-8'

In [6]: locale.currency(100)
Out[6]: '$100.00'

Maybe check this thread too:

Python locale error: unsupported locale setting

zerocewl
  • 11,401
  • 6
  • 27
  • 53