Hi
I’m new to Anvil. I appreciate your product especially the ability to do everything in Python. I need solutions that stick to Python and the Anvil IDE :
My client side code calls :
from datetime import datetime
from locale import locale
I get this error message :
NotImplementedImportError: locale is not yet implemented in Skulpt
My goal si to be able to localize the datetime output :
locale.setlocale(locale.LC_ALL, “fr_FR”) #French
datetime.now().strftime(“%a, %d.%m.%y”)
And also, localize the date picker and have the first day of the week on Monday.
What I have already tried
settings>Python versions and there I tried to add library. The only library with a name close to “locale” is “local”. After adding that library and building. I get the error ModuleNotFoundError: No module named ‘local’ for server code (the vertical band is orange in the output) even when the code is in the client side (the form).
Also: when times are selected with the datepicker component, the returned datetime.datetime object has its timezone (tzinfo ) explicitly set to the timezone of the user’s browser.
Based on the docs here and here, it doesn’t appear to be possible to change the first day the week from the Sunday default.
Hello Tom,
Thank you for your answer. To give you more info, I’m writing the application for Swiss.
Here, we speak French, German and Italian.
So I need to make pdf for people based on their mother tongue. This means the pdf document is done on server side and I need to give a special locale based on the user I’m doing the pdf for.
The dealing with timezones says : “This means that datetime objects generated on the client are automatically ‘stamped’ with the timezone of the browser, while those generated on the server are ‘stamped’ with the timezone of the server, which is always guaranteed to be UTC.”
Is it possible to write something like this on the server side :
user_time = datetime.now(anvil.tz.tzlocal(“fr_FR”)) so that the datetime object is translated in French when I call : .strftime(“%a, %d.%m.%y”) on it?
Also,
print(datetime.now(anvil.tz.tzlocal()).strftime(“%a, %d.%m.%y”))
gives me :
Tue, 18.02.25 (This is English, I was expecting French on my machine)
Sorry – other than using anvil.tz.tzlocal() for non-datepicker-generated times on the client side, I’m afraid that I don’t know much about localization.
Hopefully another forum member (or someone from Anvil) can help more.