Recent

Author Topic: Translating resource strings from FCL units  (Read 5244 times)

prof7bit

  • Full Member
  • ***
  • Posts: 144
Translating resource strings from FCL units
« on: September 16, 2021, 11:40:09 am »
I am currently in the process of making use of the i18n features to have my little application speak more that only one language and so far the experience has been great (it is actually orders of magnitudes simpler than many of the older howtos suggest, it's actually just one Entry in uses and everything begins to work like magic).

My Application includes a parser for a simple DSL and it this parser will in turn use TFPExpressionParser to parse numerical expressions with variables.

Now I have translated all my own parsing error messages, but occasionally I also must output errors that are coming straight out of TFPExpressionParser.

Luckily TFPExpressionParser is defining a section of resourcestrings with its own error messages, so I can theoretically translate these 40 or so strings also.

Question:
What is the best way to convince lazarus to include the strings from this unit in the .pot file? Currently the only way I have found is to add this file to the project in the project inspector, but then it will have its full path to the fpc source directory on my PC. It works, strings appear in the .pot and can be translated, but I don't like to have to specify a path to the fpc sources on my machine. There should be a way to add this as part of the FCL requirement.

The FCL is added to my project as a requirement, but obviously I don't want to translate the entire FCL, so it won't include them by default, so there should be some other way to mark a specific file for inclusion in the translation.

Would this be a reasonable feature request or am I missing some other way to do what I want?

wp

  • Hero Member
  • *****
  • Posts: 9021
Re: Translating resource strings from FCL units
« Reply #1 on: September 16, 2021, 11:58:53 am »
For example, to include translated LCL strings in my project, I simply copy the translated .po files to my project languages directory. I guess that this should be working with FCL translation files in the same way.

Be careful with FPExpressionParser in a multi-language project because it will not accept the FormatSettings of the destination language - it insists on the point as decimal separator; I had posted a patch to fix this but it was rejected.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

prof7bit

  • Full Member
  • ***
  • Posts: 144
Re: Translating resource strings from FCL units
« Reply #2 on: September 16, 2021, 01:04:00 pm »
Be careful with FPExpressionParser in a multi-language project because it will not accept the FormatSettings of the destination language - it insists on the point as decimal separator; I had posted a patch to fix this but it was rejected.

This is actually an advantage for me. I'm using it to parse a simple imperative script language to control a potting glue dispense machine. The expressios in this script should actually be language agnostic, it should still be able to parse the same existing scipts after I switch the language from English to German. I only want the error messages translated.

For example, to include translated LCL strings in my project, I simply copy the translated .po files to my project languages directory. I guess that this should be working with FCL translation files in the same way.
I'm going to try this.

But just copying a few files over won't work or would it? Lazarus generates only one big .pot file for all strings, regardless which unit they came from, so I would have to copy-paste the translated lines into my own .po file. Or just remove the entry in my project inspector again after I have translated it myself, it would not delete the existing entries in the po files, or woudl it? Going to try this next

Edit:
No, it will remove the entries, not only from the .pot but also from the .po files.

« Last Edit: September 16, 2021, 01:34:33 pm by prof7bit »

prof7bit

  • Full Member
  • ***
  • Posts: 144
Re: Translating resource strings from FCL units
« Reply #3 on: September 16, 2021, 01:15:29 pm »
I guess that this should be working with FCL translation files in the same way.

It turns out that such a thing as translated FCL translation files do not yet exist, so I have to get them translated by myself anyways.

prof7bit

  • Full Member
  • ***
  • Posts: 144
Re: Translating resource strings from FCL units
« Reply #4 on: September 16, 2021, 01:54:20 pm »
If I put them into a separate file and call TranslateResourceStrings() with that file it will translate these strings but then all other strings in my application which would normally be automatically translated by DefaultTranslator will become untranslated again.

It seems I can only use one translation file at a time, and it must be named after my application executable name.

Edit: I need to use TranslateUnitResourceStrings() and call it with the unit name, then it will translate the strings from this unit and leave everything else untouched.
« Last Edit: September 16, 2021, 03:30:29 pm by prof7bit »

prof7bit

  • Full Member
  • ***
  • Posts: 144
Re: Translating resource strings from FCL units
« Reply #5 on: September 17, 2021, 09:52:06 am »
Let me state this problem differently:

Suppose I am an FPC develoer or working on an FPC package, and I want to provide i18n files for my packages or units. How would I go about leveraging Lazarus i18n features for generating and maintaining my translation files?

I can open for example the FCL package in the package manager and enable "i18n", but this seems to be meaningless, I cannot recompile these packages from within Lazarus, it will just do nothing.

Is this the reason why FPC does not provide any language files? Because they have zero IDE support?

Sieben

  • Full Member
  • ***
  • Posts: 232
Re: Translating resource strings from FCL units
« Reply #6 on: November 03, 2021, 04:49:50 pm »
For a start I did:

- copy rtlconsts.pp, rtlconst.inc and sysconst.pp form rtl/objpas to a new directory

- rename those files with some prefix to avoid confusion (don't forget to adjust unit names and dependencies)

- create a new package and include these files, enable i18n and compile

- edit the po files to rename their identifiers, at least those in msgctxt entries (others are just comments)*.

Now translate a string, say SListIndexError from rtlconsts, create a new project, include your rtlconsts.xx.po as you mentioned above and provoke a 'List index out of bounds' with eg TStringList to test it. Worked for me. Should work for any other file containing fpc resourcestrings as well. If they can not be compiled 'stand alone' due to dependencies just copy their resourcestring sections to a new unit and adjust their po name and identifiers according to the original unit name. I'm including rtlconsts.po and sysconst.po generated as mentioned above.

* Not sure yet if identifiers of rtlconsts.po have to be rtlconsts.xxx or rtlconst.xxx, according to inc-file name.
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9697
  • FPC developer.
Re: Translating resource strings from FCL units
« Reply #7 on: November 03, 2021, 04:53:45 pm »
Afaik the input for translation of the FPC embedded strings goes with the "*.rsj" files generated during compilation. (used to be ".rst" in older versions).

If the tools to convert them to gettext are there, I don't know, but it probably your raw input

Sieben

  • Full Member
  • ***
  • Posts: 232
Re: Translating resource strings from FCL units
« Reply #8 on: November 03, 2021, 05:48:14 pm »
I also noticed this ifdef in classes.inc:

Code: Pascal  [Select][+][-]
  1. {$IFDEF LANG_GERMAN}
  2. {$i constsg.inc}
  3. {$ELSE}
  4. {$IFDEF LANG_SPANISH}
  5. {$i constss.inc}
  6. {$ENDIF}
  7. {$ENDIF}
  8.  

but don't know if this is still used. Although using a german setup these strings seem not be translated here. The files mentioned are in place, dated 2005 however.

Wouldn't it be worth considering a similar approach as Lazarus uses for LCLStrConsts for FPC sources as well...?
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9697
  • FPC developer.
Re: Translating resource strings from FCL units
« Reply #9 on: November 03, 2021, 09:54:49 pm »
Afaik those includes predate resourcestring support.

Sieben

  • Full Member
  • ***
  • Posts: 232
Re: Translating resource strings from FCL units
« Reply #10 on: November 11, 2021, 11:34:49 am »
Thanks, and yes, I thought so. Transferred the corresponding items from constsg.inc and constss.inc to rtlconsts.de.po and rtlconsts.es.po (some 270 in case of the former, some 160 in case of the latter, of 501 in total) and sysconst.de.po / sysconst.es.po respectively (which were only a few items though). I'm again including them here, maybe other users might want to share their translations here as well.
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

Sieben

  • Full Member
  • ***
  • Posts: 232
Re: Translating resource strings from FCL units
« Reply #11 on: November 14, 2021, 05:40:05 pm »
Just another candidate: DBConst.po...
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

 

TinyPortal © 2005-2018