Recent

Author Topic: [Solved] Translation of ResourceString  (Read 1866 times)

jcmontherock

  • Sr. Member
  • ****
  • Posts: 336
[Solved] Translation of ResourceString
« on: September 28, 2025, 06:18:47 pm »
I have the following definitions in an application using the translation:
Code: Pascal  [Select][+][-]
  1. ResourceString
  2.   rReload      = 'File:' + #13 + '%s + #13 + has been changed by another application.' + #13 +
  3.                  'Should I reload it from disk ?';
  4. ....
I use it in:
Code: Pascal  [Select][+][-]
  1. rc := Application.MessageBox(PChar(Format(rReload,
  2.                                [sPoFileName])), PChar(rFileChanged), MB_YESNO or MB_ICONQUESTION);
  3.  
The result of this entry in the pot, po file is:
Code: Pascal  [Select][+][-]
  1. #: editpou.rreload
  2. #, object-pascal-format
  3. msgid ""
  4. "File:\n"
  5. "%s \n”
  6. “has been changed by another application.\n"
  7. "Should I reload it from disk ?"
  8. msgstr ""
  9.  
The line "#, object-pascal-format" was added and the original string is not in the "msgid" param. Several help applications for input translation do not recognize this entry in po file.
What should I do ?
« Last Edit: October 11, 2025, 03:26:12 pm by jcmontherock »
Windows 11 UTF8-64 - Lazarus 4.4-64 - FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 13336
Re: Translation of ResourceString
« Reply #1 on: September 28, 2025, 06:44:10 pm »
Code: Pascal  [Select][+][-]
  1. ResourceString
  2.   rReload      = 'File:' + #13 + '%s + #13 + has been changed by another application.' + #13 +
  3.                  'Should I reload it from disk ?';
  4. ....
Code: Pascal  [Select][+][-]
  1. #: editpou.rreload
  2. ...
Why are there two r's in the line "#:editpou.rreload"? In my own projects, the pot/po file has in the '#:' lines the name of the resourcestring unit, a dot and the name of the resourcestring. Therefore I would expect to see "#:editpou.reload". Maybe delete (or rename) the pot/po files and recreate them by "Project" > "Resave forms with enabled i18n".

Khrys

  • Sr. Member
  • ****
  • Posts: 383
Re: Translation of ResourceString
« Reply #2 on: September 29, 2025, 07:39:33 am »
The  "#, object-pascal-format"  line seems to be added whenever a format specifier is detected in the string (here it's  %s).
It's a special comment that might be used by some programs for providing better diagnostics, but shouldn't affect compatibility otherwise.

I'd be more concerned about the single carriage return line endings (not used by any major platform - it's either  #10  or  #13#10,  but never  #13  alone). Are you targeting the Commodore 64, the ZX-Spectrum or another retro machine?



Also, are you aware that you (most likely) forgot two quotes around the second  #13?

Code: Pascal  [Select][+][-]
  1. 'File:'
  2. +
  3. #13
  4. +
  5. '%s + #13 + has been changed by another application.'
  6. +
  7. #13
  8. +
  9. 'Should I reload it from disk ?'



Why are those special quote characters there?


"%s \n
has been changed by another application.\n"



  U+201D  Right Double Quotation Mark
  U+201C  Left Double Quotation Mark

Thaddy

  • Hero Member
  • *****
  • Posts: 18711
  • To Europe: simply sell USA bonds: dollar collapses
Re: Translation of ResourceString
« Reply #3 on: September 29, 2025, 08:59:46 am »
I'd be more concerned about the single carriage return line endings (not used by any major platform - it's either  #10  or  #13#10,  but never  #13  alone). Are you targeting
Don't forget classic mac and Apple 11 and TRS80
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

jcmontherock

  • Sr. Member
  • ****
  • Posts: 336
Re: Translation of ResourceString
« Reply #4 on: September 29, 2025, 12:10:33 pm »
@wp: there are 2 "r" because it's the name of the string: rReload.

- My problem seems to be in the original string: text is out of msgid param.

- destination is Windows 11.
Windows 11 UTF8-64 - Lazarus 4.4-64 - FPC 3.2.2

Zvoni

  • Hero Member
  • *****
  • Posts: 3230
Re: Translation of ResourceString
« Reply #5 on: September 29, 2025, 01:58:55 pm »
@wp: there are 2 "r" because it's the name of the string: rReload.

- My problem seems to be in the original string: text is out of msgid param.

- destination is Windows 11.
Then your problem probably stems from (don't quote me on it)
1) Windows uses #13#10 as CarriageReturn/NewLine
2) the missing quotes Khrys mentioned
Code: Pascal  [Select][+][-]
  1. ResourceString
  2.   rReload      = 'File:' + #13#10 + '%s' + #13#10 + 'has been changed by another application.' + #13#10 +
  3.                  'Should I reload it from disk ?';

To get any idea: Does your problem happen if you leave out the #13 and concatenation?
As in: ResourceString as one line
Code: Pascal  [Select][+][-]
  1. ResourceString
  2.   rReload      = 'File: %s has been changed by another application. Should I reload it from disk ?';
« Last Edit: September 29, 2025, 02:02:20 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

jcmontherock

  • Sr. Member
  • ****
  • Posts: 336
Re: Translation of ResourceString
« Reply #6 on: September 30, 2025, 11:24:26 am »
Change #13 with #13#10 does not change anythings.
Double quotation char is added by LCLTranslator. It's included in the GetText po, pot file format.
« Last Edit: September 30, 2025, 11:28:10 am by jcmontherock »
Windows 11 UTF8-64 - Lazarus 4.4-64 - FPC 3.2.2

Zvoni

  • Hero Member
  • *****
  • Posts: 3230
Re: Translation of ResourceString
« Reply #7 on: September 30, 2025, 11:25:49 am »
Change #13 with #13#10 does not change anythings.
Have you tried the "one-liner" i mentioned above?
resp. have you corrected the missing Single-Quotes?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

jcmontherock

  • Sr. Member
  • ****
  • Posts: 336
Re: Translation of ResourceString
« Reply #8 on: September 30, 2025, 11:33:33 am »
Suppress newline and/or returncarriage works fine. So what I do, as a workaround, is the following:
Code: Pascal  [Select][+][-]
  1. ResourceString
  2.  
  3.   rReload1     = 'File:';
  4.   rReload2     = '%s';
  5.   rReload3     = 'has been changed by another application.';
  6.   rReload4     = 'Should I reload it from disk ?';
  7. .....
  8.  
  9.   rc := Application.MessageBox(PChar(Format(rReload1{'File:'} + #13 +
  10.                                rReload2{'%s '} + #13 +
  11.                                rReload3{has been changed by another application.'} + #13 +
  12.                                rReload4{'Should I reload it from disk ?';},
  13.                                [sPoFileName])), PChar(rFileChanged), MB_YESNO or MB_ICONQUESTION);
  14.  

It's not really smart. So, I get the following po file for that definition:
Code: Pascal  [Select][+][-]
  1. #: editpou.rreload1
  2. msgid "File:"
  3. msgstr "Le fichier :"
  4.  
  5. #: editpou.rreload2
  6. #, object-pascal-format
  7. msgid "%s"
  8. msgstr "%s"
  9.  
  10. #: editpou.rreload3
  11. msgid "has been changed by another application."
  12. msgstr "a été modifié par une autre application."
  13.  
  14. #: editpou.rreload4
  15. msgctxt "editpou.rreload4"
  16. msgid "Should I reload it from disk ?"
  17. msgstr "Dois-je le recharger du disque ?"
  18.  
« Last Edit: September 30, 2025, 11:39:42 am by jcmontherock »
Windows 11 UTF8-64 - Lazarus 4.4-64 - FPC 3.2.2

Zvoni

  • Hero Member
  • *****
  • Posts: 3230
Re: Translation of ResourceString
« Reply #9 on: September 30, 2025, 11:37:31 am »
Try?
Code: Pascal  [Select][+][-]
  1. ResourceString
  2.   rReload1     = 'File:\n %s\n has been changed by another application.\n Should I reload it from disk ?';
  3.  
  4. .....
  5.  
  6.   rc := Application.MessageBox(PChar(Format(rReload1,  [sPoFileName])), PChar(rFileChanged), MB_YESNO or MB_ICONQUESTION);
  7.  
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12599
  • FPC developer.
Re: Translation of ResourceString
« Reply #10 on: September 30, 2025, 12:12:15 pm »
The line "#, object-pascal-format" was added and the original string is not in the "msgid" param. Several help applications for input translation do not recognize this entry in po file.
What should I do ?

Use one that does, like dxgettext's GORM ? That is what I do, though to be fair, my translatable apps haven't been fully migrated to Lazarus yet.

CM630

  • Hero Member
  • *****
  • Posts: 1581
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Translation of ResourceString
« Reply #11 on: September 30, 2025, 03:07:24 pm »
It this in your .PO or something went wrong with the quotation? I do not expect that it should work if it is written this way.
See the second screenshot, your code seems wrong to me.
And I guess the reason for #, object-pascal-format being added is that you have %f in the string (it might be %n, %d, etc..).
« Last Edit: September 30, 2025, 03:16:51 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1570
    • Lebeau Software
Re: Translation of ResourceString
« Reply #12 on: September 30, 2025, 05:43:58 pm »
Try?
Code: Pascal  [Select][+][-]
  1. ResourceString
  2.   rReload1     = 'File:\n %s\n has been changed by another application.\n Should I reload it from disk ?';
  3.  
  4. .....
  5.  
  6.   rc := Application.MessageBox(PChar(Format(rReload1,  [sPoFileName])), PChar(rFileChanged), MB_YESNO or MB_ICONQUESTION);
  7.  

Pascal does not have escape sequences in string literals, like C/C++ does. \n will not be treated as a line break, but as literal characters '\' and 'n' in the text.  To use \n as a line break, you would have to replace it at runtime, eg:

Code: Pascal  [Select][+][-]
  1. s := StringReplace(rReload1, '\n', #13#10, [rfReplaceAll]);
  2. rc := Application.MessageBox(PChar(Format(s,  [sPoFileName])), PChar(rFileChanged), MB_YESNO or MB_ICONQUESTION);
« Last Edit: September 30, 2025, 05:48:27 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Khrys

  • Sr. Member
  • ****
  • Posts: 383
Re: Translation of ResourceString
« Reply #13 on: October 01, 2025, 07:35:22 am »
For what it's worth, I've never had issues with multi-line resource strings that use a single line feed as separator.

Code: Pascal  [Select][+][-]
  1. unit Constants;
  2.  
  3. interface
  4.  
  5. const
  6.   NEWLINE = #$0A; // Equivalent to `#10`
  7.  
  8. resourcestring
  9.   S_EXAMPLE = 'First line' + NEWLINE + 'Second line';

Quote from: de.po
#: constants.s_example
msgid ""
"First line\n"
"Second line"
msgstr ""
"Erste Zeile\n"
"Zweite Zeile"

Zvoni

  • Hero Member
  • *****
  • Posts: 3230
Re: Translation of ResourceString
« Reply #14 on: October 01, 2025, 08:39:36 am »
For what it's worth, I've never had issues with multi-line resource strings that use a single line feed as separator.

Code: Pascal  [Select][+][-]
  1. unit Constants;
  2.  
  3. interface
  4.  
  5. const
  6.   NEWLINE = #$0A; // Equivalent to `#10`
  7.  
  8. resourcestring
  9.   S_EXAMPLE = 'First line' + NEWLINE + 'Second line';

Quote from: de.po
#: constants.s_example
msgid ""
"First line\n"
"Second line"
msgstr ""
"Erste Zeile\n"
"Zweite Zeile"
Khrys, if i understood TS correctly you'd have the same Problem, that your Strings are not within the Doublequotes of the Params msgid/msgstr

But i found something interesting: https://stackoverflow.com/questions/14833917/line-breaks-in-django-po-files
Yes, it's for "django" (Whatever that is. I only know it as a Western-Movie).

jc, have you tried to "embed" the Linebreaks?

Untested (Note the ampersand before #10)
Code: Pascal  [Select][+][-]
  1. ResourceString
  2.   rReload1     = 'File:&#10 %s&#10 has been changed by another application.&#10 Should I reload it from disk ?';
  3.  
  4. .....
  5.  
  6.   rc := Application.MessageBox(PChar(Format(rReload1,  [sPoFileName])), PChar(rFileChanged), MB_YESNO or MB_ICONQUESTION);

Try?
Code: Pascal  [Select][+][-]
  1. ResourceString
  2.   rReload1     = 'File:\n %s\n has been changed by another application.\n Should I reload it from disk ?';
  3.  
  4. .....
  5.  
  6.   rc := Application.MessageBox(PChar(Format(rReload1,  [sPoFileName])), PChar(rFileChanged), MB_YESNO or MB_ICONQUESTION);
  7.  

Pascal does not have escape sequences in string literals, like C/C++ does. \n will not be treated as a line break, but as literal characters '\' and 'n' in the text.  To use \n as a line break, you would have to replace it at runtime, eg:

Code: Pascal  [Select][+][-]
  1. s := StringReplace(rReload1, '\n', #13#10, [rfReplaceAll]);
  2. rc := Application.MessageBox(PChar(Format(s,  [sPoFileName])), PChar(rFileChanged), MB_YESNO or MB_ICONQUESTION);
Thx Remy.
Good to know
« Last Edit: October 01, 2025, 08:42:04 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018