So I've been trying to work with gettext in a standalone python application, not a web environment. And I've been failing to get my translations to work, now I have the following:
# Set the desired language from the json_data, default if not present is english
target_language = self.pdf_content_json.get("language", "en_US")
# Set the locale for the program
locale.setlocale(locale.LC_ALL, target_language)
# Set up the translation
translation = gettext.translation('messages', localedir='translations/', languages=['nl_NL'])
translation.install()
This is how my folder structure looks:
This is the exception I get:
Exception has occurred: FileNotFoundError (note: full exception trace is shown but execution is paused at: _run_module_as_main)
[Errno 2] No translation file found for domain: 'messsages'
File "C:\Users\joren\AppData\Local\Programs\Python\Python312\Lib\gettext.py", line 528, in translation
raise FileNotFoundError(ENOENT,
File "D:\Documents\coding\pdf_creator\app\pdf_creator\src\pdf_types\base_pdf.py", line 34, in initialise
translation = gettext.translation('messsages', localedir='translations', languages=['nl_NL'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\coding\pdf_creator\app\pdf_creator\main.py", line 31, in generate_checkinout_pdf
pdf.initialise(json_data)
File "D:\Documents\coding\pdf_creator\app\pdf_creator\main.py", line 71, in main
generate_checkinout_pdf("checkin_report.pdf")
File "D:\Documents\coding\pdf_creator\app\pdf_creator\main.py", line 77, in <module>
main()
File "C:\Users\joren\AppData\Local\Programs\Python\Python312\Lib\runpy.py", line 88, in _run_code
exec(code, run_globals)
File "C:\Users\joren\AppData\Local\Programs\Python\Python312\Lib\runpy.py", line 198, in _run_module_as_main (Current frame)
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No translation file found for domain: 'messsages'```
