Recent

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

Lulu

  • Sr. Member
  • ****
  • Posts: 335
Re: Translation of ResourceString
« Reply #15 on: October 01, 2025, 07:58:18 pm »
Hi all,
In my resourcestring, I write entry with multiple lines like this:
Code: Pascal  [Select][+][-]
  1. ...
  2.    resourcestring
  3.       S_EXAMPLE1 = 'First line' + LineEnding + 'Second line';
  4.       S_EXAMPLE2 = 'Player %s win the game';
  5. .....
  6. Label1.Caption := Format(S_EXAMPLE2, ['Bob']);

It work well and LineEnding is crossplatform.
wishing you a nice life!
GitHub repositories https://github.com/Lulu04

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1566
    • Lebeau Software
Re: Translation of ResourceString
« Reply #16 on: October 01, 2025, 11:38:57 pm »
How about just using multi-line string literals? That feature has been available in FPC for a few months now.

https://forum.lazarus.freepascal.org/index.php/topic,46050.msg561813.html#msg561813

I'm assuming it works for resource strings, eg:

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

Code: Pascal  [Select][+][-]
  1. resourcestring
  2.   S_EXAMPLE = '''
  3.    First line
  4.    Second line
  5.    ''';
  6.  
« Last Edit: October 01, 2025, 11:40:29 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Khrys

  • Sr. Member
  • ****
  • Posts: 348
Re: Translation of ResourceString
« Reply #17 on: October 02, 2025, 06:58:18 am »
That feature has been available in FPC for a few months now.

There are many nice things in trunk, but still no official release 🥲

Function references & anonymous functions, the LLVM backend (ASAN my beloved ❤️), constant generic parameters, implicit function specializations, move semantics for RAII managed records and of course multiline string literals... the list goes on, and it's a pity to see all these features stashed away untagged.

Thaddy

  • Hero Member
  • *****
  • Posts: 18376
  • Here stood a man who saw the Elbe and jumped it.
Re: Translation of ResourceString
« Reply #18 on: October 02, 2025, 07:21:43 am »
Yes, that works. Complete:
Code: Pascal  [Select][+][-]
  1. program resstr;
  2. {$ifdef fpc}{$mode objfpc}{$endif}
  3. uses windows;
  4. resourcestring
  5.   test = '''
  6.         Let's
  7.          test
  8.          that
  9.          ''';
  10.  
  11. begin
  12.   messagebox(0,PChar(test),'test me',MB_OK);
  13. end.
Confuses the highlighter, though ;)
And only in trunk/main.

Is equivalent to:
Code: Pascal  [Select][+][-]
  1. {$ifdef fpc}{$mode objfpc}{$endif}
  2. uses windows;
  3. resourcestring
  4.   test = 'Let''s'+LineEnding+'test'+LineEnding+'that';
  5. begin
  6.    messagebox(0,PChar(test),'test me',MB_OK);
  7. end.

« Last Edit: October 02, 2025, 10:04:45 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Zvoni

  • Hero Member
  • *****
  • Posts: 3140
Re: Translation of ResourceString
« Reply #19 on: October 02, 2025, 10:10:04 am »
*sigh*
Guys, TS' problem is not the usage of the Ressourcestring directly.
His Problem is apparently that if his Ressourcestring has LineBreaks, they DON'T end up in the msgid-Parameter of the po-file resp. the translation in the msgstr.
Look closely at his first post
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: 316
Re: Translation of ResourceString
« Reply #20 on: October 11, 2025, 03:22:35 pm »
Finally the Remy's solution is good with some little changes:
Code: Pascal  [Select][+][-]
  1. ResourceString
  2.   rReload      = 'File:\n%s\n has been changed by another application.\nShould I reload it from disk ?';
  3. ...
  4.  
  5.   sStr := StringReplace(rReload, '\n', #13#10, [rfReplaceAll]);
  6.   rc := Application.MessageBox(PChar(Format(sStr, [sPoFileName])), PChar(rFileChanged),
  7.                                MB_YESNO or MB_ICONQUESTION);
  8.  
Which gives the following po file:
Code: Pascal  [Select][+][-]
  1. #: editpou.rreload
  2. msgid "File:\\n%s\\n has been changed by another application.\\nShould I reload it from disk ?"
  3. msgstr "Fichier:\\n%s\\na été modifié par une autre application.\\ndois-je le recharger du disque ?"
  4.  
Thanks a lot to everybody.
Windows 11 UTF8-64 - Lazarus 4.2-64 - FPC 3.2.2

 

TinyPortal © 2005-2018