I know this has been discussed in other topics, but I wanted to start a new Topic to hopefully pull together a current full answer to this.
The aim:
- Build a multi-language application
- That is cross-platform compilable
- Where the language translation files are included in the executable to make the application single-file-portable
- Where the system language is used to determine the language used i nteh application UI
I have managed to this with other applications where the translation files are stored in a 'languages' sub-folder, but reading the docs it seems it should be possible to embed the .po or .mo files as resources.
I have hunted through the following three resources to try to figure this out but they all seem to refer to different versions of Lazarus/FPC and seem to have been updated at different times in different places so I can't work out a coherent method of doing this.
https://wiki.lazarus.freepascal.org/Step-by-step_instructions_for_creating_multi-language_applications - this is a good guide to getting multi-language working and switchable via the command line when the langauge files are in a sub-folder
https://wiki.lazarus.freepascal.org/Translations_/_i18n_/_localizations_for_programs - this seems to be a bit outdated, but mentions switching via the command line (or run options in the IDE)
https://wiki.freepascal.org/Everything_else_about_translations - this talks about a couple of methods for including the translation files in the executable, but seems to be talking about older versions of Laz/FPC and so doesn;t directly relate to th elatest version particulary using the
TDefaultTranslator class (
uses DefaultTranslator).
First some specific questions...
- If I include the translation files as resources via Project->Project Options->Resources as RCDATA resources (as per one of those linked documents) do I include the .po or .mo versions of the files?
- I understand that if the files are included as resources I am unable to switch language via the command line / run options - is that correct?
- Is there anything else I need to do other than include the langauge files as resources and specify DefaultTranslator in the uses clause to enable the languages to be used when the system/OS language matches?
Note that translations are working exactly as expected in my application at the moment with the language files in a languages sub-directory as specified in i18n settings in Project->Project Options->i18n. I can switch languages via the command line no problem.. I just want to package them in the executable and be able to test them (my machine is set to English so I don't know how to test that the system language activates a translation)
Thanks,
-FM