Recent

Author Topic: Translate .lfm file in a lazarus package  (Read 695 times)

tprud

  • Newbie
  • Posts: 3
Translate .lfm file in a lazarus package
« on: April 17, 2026, 10:24:40 am »
Hello,
I've made a Lazarus package with Forms and Frames. I've enabled i18n in my project and in my package option, and I've checked the 'Create/update .po file when saving a lfm file' both on my project and my package. I've selected the output folder.
But when I do some modifications, either on my project or my package, my project creates its own pot file for frames, forms and resource strings, but my package creates its own pot file only for resource strings. I've spent some time reading the forum and looking into Lazarus options, but I cannot resolve this issue.
The only options that cames in my mind are:
- Create a script to generate pot files from lrj files generated by lazarus for my package
- Use resource strings in forms and frames instead of using the properties of components from the IDE

Is there a solution to generate pot file for frames and forms of a lazarus package? Did I miss something?

I'm using Lazarus 4.5 with freepascal 3.2.2, installed using fpcupdeluxe. I'm working on Windows.

wp

  • Hero Member
  • *****
  • Posts: 13518
Re: Translate .lfm file in a lazarus package
« Reply #1 on: April 17, 2026, 12:08:39 pm »
Is there a solution to generate pot file for frames and forms of a lazarus package? Did I miss something?
Packages have their own i18n settings: "Package Options" > "i18n" > Check "Enable i18n", and, if you want form and frame strings to be in the po(t) files as well, check also "Create/update .po file when saving a lfm file" (in Laz release versions) or "Extract translatable strings from a form when saving its LFM file" (in Laz/main).

In your application, you must copy the po files of the packages into the languages files of the application so that the package strings can be translated. A famous example are the lclstrconsts.*.po containing the translated strings of the LCL package.
« Last Edit: April 17, 2026, 12:11:45 pm by wp »

tprud

  • Newbie
  • Posts: 3
Re: Translate .lfm file in a lazarus package
« Reply #2 on: April 17, 2026, 12:24:06 pm »
Is there a solution to generate pot file for frames and forms of a lazarus package? Did I miss something?
Packages have their own i18n settings: "Package Options" > "i18n" > Check "Enable i18n", and, if you want form and frame strings to be in the po(t) files as well, check also "Create/update .po file when saving a lfm file" (in Laz release versions) or "Extract translatable strings from a form when saving its LFM file" (in Laz/main).

As I said in my first message, I've already checked the i18n both on the project and the package. The "Create/update .po file when saving a lfm file" is checked as well both on the project and the package.

jcmontherock

  • Sr. Member
  • ****
  • Posts: 354
Re: Translate .lfm file in a lazarus package
« Reply #3 on: April 17, 2026, 05:14:17 pm »
For your project, not for the package, each unit, which needs translation, should be included in the project inspector. Mentioned in uses clause is not enough.
« Last Edit: April 17, 2026, 05:17:30 pm by jcmontherock »
Windows 11 UTF8-64 - Lazarus 4.6-64 - FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 13518
Re: Translate .lfm file in a lazarus package
« Reply #4 on: April 18, 2026, 12:07:11 am »
As I said in my first message, I've already checked the i18n both on the project and the package. The "Create/update .po file when saving a lfm file" is checked as well both on the project and the package.
Sorry, I should read more carefully... Yes, I can confirm your observation.

wp

  • Hero Member
  • *****
  • Posts: 13518
Re: Translate .lfm file in a lazarus package
« Reply #5 on: April 19, 2026, 01:40:24 am »
I asked Maxim, the maintainer of the Lazarus translation system, about this issue, and he told me that extraction of strings from lfm files in packages probably is not implemented. He anyway recommends to use only resource strings rather than these auto-created strings which have several disadvantages: impossibility to assign a string to several captions (which is an unnecessary load for the translators), requiring manual maintaining of lists of strings to be excluded from the po file, requirement to still use resource strings because the auto-strings cannot be created in many cases (comboboxes, radiogroups, ...).

I picked up this recommendation and reworked the ChartEditor demo project (in components/tachart/demo/charteditor) to move all the editor dialogs into a package and to introduce translations based on resource strings only. Well, this project has a variety of frames and forms, and it took me some time to set up all the resource strings. But on the other hand, having all package strings in a dedicated unit, is a very clear concept, much clearer than the confusing auto-extracted strings. I am posting this project/package here for you to study. Note that before you load the demo you must install the package from its dedicated folder. In the "Settings" menu there is an item to switch language between English and German. Click on any chart element to open its corresponding editor.

tprud

  • Newbie
  • Posts: 3
Re: Translate .lfm file in a lazarus package
« Reply #6 on: April 23, 2026, 09:05:13 am »
Hello,
thanks for your fast reply and work.
I got the reason why it should be better to use resource strings, by having only one resource for multiple captions. I'm going to follow your recommandation, thanks.
But I still have a question. Why it should be necessary on a package and not on the project? I understand that it's not implemented to extract strings from lfm in packages, and it should not, but in my opinion, it should be better that translation must follow the same behavior on a package and on the project. There is currently the same checkbox on the project options and the package options (Create/update .po file when saving a lfm file) that does not have the same behavior.

 

TinyPortal © 2005-2018