Support locale in production

Hai,

I need to set the number of an month to the name of the month. I’m using the following code to do this:

from datetime import datetime
month = '3' 
print( datetime.strptime(month, '%m').strftime('%B')

This will print the month march but to transfer to Dutch I will use the package locale.
The difference will be:

from datetime import datetime
import locale
month = '3' 
locale.setlocale(locale.LC_TIME, 'nl_NL.utf8')
print( datetime.strptime(month, '%m').strftime('%B')

But trying this in our code will give an error.

locale.setlocale(locale.LC_TIME, 'nl_NL.utf8')
  File "/usr/local/lib/python3.7/locale.py", line 608, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

Could somebody help me with this?

Kind regards jip,

P.S. When typing locale -a in ubuntu the nl_NL.utf8 is shown.

Hi Jip,

I don’t think locales are enabled in the docker container which runs in production. I will relabel this topic as feature request.

As a workaround I’m afraid you will need to map the words manually.

There is a solution for those searching this issue. Add the following line to your viktor.config.toml:

packages = ["locales-all"]

This uses the recent packages option to install the locales-all package. that package includes all locales, not just those configured in the default docker image.

2 Likes