For my application I create the virtualenv in /opt/anw/ivirtualenvs and start the application with
/opt/anw/.virtualenvs/Kalendarium/bin/python /opt/anw/Kalendarium/calendarium/startKalender.py
and I get " FileNotFoundError: [Errno 2] No translation file found for domain: ‘calendar’".
Looking for the reason I copied gettext.py into my development environment and put some prints into it. Also I put test prints into my start program:
get 53
get60
get104
get 166
GET 179
get 215
get 257
get 316
get 466
get 522
get 557
get 601
get 550
get 652
eigenes gettext 524 messages None None None False
eigenes gettext 524 messages None None None False
eigenes gettext 524 messages None None None False
eigenes gettext 524 messages None None None False
eigenes gettext 524 messages None None None False
eigenes gettext 524 messages None None None False
eigenes gettext 524 messages None None None False
hpt 68
70
eigenes gettext 524 calendar locales ['de'] None False
eigenes gettext 524 messages None None None False
eigenes gettext 524 messages None None None False
The first lines shows the initialtion of gettext. Then the translation method is seven times invoked. Then the flow goes back to my start program. My program invokes the translation method. And then there are two other invokes. After that the file is found and my program works normally.
I wrote “In development environment I activated the virtualenvironment” , in production environment I did “opt/anw/.virtualenvs/Kalendarium/bin/python /”
Sourcing activate sets up a lot of environment variables. That’s what actually makes the venv work. Just calling that version of Python without the environment variables means that it doesn’t take packages from the correct place (among other things.)
egon@HeraDebEinzel:~$ source /opt/anw/.virtualenvs/Kalendarium/bin/activate && /opt/anw/.virtualenvs/Kalendarium/bin/python /opt/anw/Kalendarium/calendarium/startKalender.py
Traceback (most recent call last):
File "/opt/anw/Kalendarium/calendarium/startKalender.py", line 85, in <module>
start()
File "/opt/anw/Kalendarium/calendarium/startKalender.py", line 69, in start
de = gettext.translation('calendar', localedir='locales', languages=['de'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/gettext.py", line 531, in translation
raise FileNotFoundError(ENOENT,
FileNotFoundError: [Errno 2] No translation file found for domain: 'calendar'
(Kalendarium) egon@HeraDebEinzel:~$
I think you need to figure out the absolute path to your locale directory and use use a relative path. I suspect you wil need to start with the __file__ of the main script.
I put the absolut path in “localdir” and it finds the fle. Now iI have to construct the path so it works in development and production environment.
Barry thank you Egon