Recent

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

prof7bit

  • Full Member
  • ***
  • Posts: 139
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: 8897
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: 139
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: 139
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: 139
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: 139
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?

 

TinyPortal © 2005-2018