Recent

Author Topic: [SOLVED] German caption for System-Buttons  (Read 1985 times)

Zvoni

  • Hero Member
  • *****
  • Posts: 3007
[SOLVED] German caption for System-Buttons
« on: October 13, 2023, 01:31:12 pm »
I'll bite.

Couldn't find anything (searching for i18n, system buttons etc.)

How do i get german captions for the System-Buttons in MessageDlg?
mbYesToAll et al
« Last Edit: October 16, 2023, 09:14:37 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

loaded

  • Hero Member
  • *****
  • Posts: 870
Re: German caption for System-Buttons
« Reply #1 on: October 13, 2023, 02:56:53 pm »
"C:\lazarus\lcl\lclstrconsts.pas" line 35
After the change, the file must be saved and the project must be recompiled.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Zvoni

  • Hero Member
  • *****
  • Posts: 3007
Re: German caption for System-Buttons
« Reply #2 on: October 13, 2023, 03:10:35 pm »
"C:\lazarus\lcl\lclstrconsts.pas" line 35
After the change, the file must be saved and the project must be recompiled.
Seriously??
Is there any way, to provide a "translation"-File or something instead of "hacking" into the "originals"?
I think i read something along those lines (Resource-Strings being compiled to a po-file and so on)
Edit: Due to reasons i CANNOT install poedit on my laptop (Company-Laptop)
And yes, i did see the Languages-Folder with the po-files, but i have no clue how to "use" that

EDIT2: hmm.... found this....will have to wait for Monday
https://wiki.freepascal.org/Everything_else_about_translations
« Last Edit: October 13, 2023, 03:22:27 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

loaded

  • Hero Member
  • *****
  • Posts: 870
Re: German caption for System-Buttons
« Reply #3 on: October 13, 2023, 03:53:52 pm »
Seriously??

Serious;
This was the fastest and shortest way since all my applications running on Windows, except Android applications, were in local languages.
If there is another method, I would like to learn it. Respects.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Bart

  • Hero Member
  • *****
  • Posts: 5575
    • Bart en Mariska's Webstek
Re: German caption for System-Buttons
« Reply #4 on: October 13, 2023, 06:50:24 pm »
This was the fastest and shortest way since all my applications running on Windows, except Android applications, were in local languages.
If there is another method, I would like to learn it. Respects.

Use the translation mechanisms provided with Lazarus.
You can automate this, e.g. I have a nlautotranslation unit that I only need to include in my program and all LCL resource strings will be transated (from a resource included in the executable).

Bart

wp

  • Hero Member
  • *****
  • Posts: 12911
Re: German caption for System-Buttons
« Reply #5 on: October 13, 2023, 10:26:14 pm »
  • Copy the file lclstrconsts.de.po from your lazarus installation (folder lcl/languages) into you project folder. This file contains the German translations of the resource strings declared in unit lclstrconsts.
  • Add unit translations to the main form of your project and put the following code into the initialization section of the main unit:
Code: Pascal  [Select][+][-]
  1. var
  2.   PODir: String;
  3.  
  4. initialization
  5.   PODir := Application.Location;
  6.   TranslateUnitResourceStrings('lclstrconsts', PODir + 'lclstrconsts.de.po');
  7.  
  8. end.

    Alternatively, if you prefer a monolithic application, do this:
    • Again, copy lclstrconsts.de.po into your project folder structure.
    • Open "Project" > "Project Options" > "Resources". Click "Add". Select the copy of lclstrconsts.de.po. This adds the file to the resources of your application as resource type RT_RCDATA.
    • In the initialization section of your main form (which must use "translations" again, and now also LCLType for the RT_RCDATA identifier) you read the po file from the resource, save it to the temp folder and translate it.
    • In the finalization section delete the po file from the temp folder.
    Code: Pascal  [Select][+][-]
    1. var
    2.   PODir: String;
    3.   stream: TResourceStream;
    4.  
    5. initialization
    6.   PODIR := GetTempDir(false);
    7.   ForceDirectories(PODir);
    8.   stream := TResourceStream.Create(HINSTANCE, 'lclstrconsts.de', RT_RCDATA);
    9.   try
    10.     stream.SaveToFile(PODir + 'lclstrconsts.de.po');
    11.     TranslateUnitResourceStrings('lclstrconsts', PODir + 'lclstrconsts.de.po');
    12.   finally
    13.     stream.Free;
    14.   end;
    15.  
    16. finalization
    17.   DeleteFile(PODir + 'lclstrconsts.de.po');
    18.  
    19. end.

    Bart

    • Hero Member
    • *****
    • Posts: 5575
      • Bart en Mariska's Webstek
    Re: German caption for System-Buttons
    « Reply #6 on: October 13, 2023, 11:54:51 pm »
    If you have the .po file as a resource there is no need to store it temporarily, you can perform the translation from with the resource.
    An excerpt from one of my convenience units:

    Code: Pascal  [Select][+][-]
    1. implementation
    2.  
    3. {$R nlautotranslation.res}
    4.  
    5. procedure TranslateUnitFromResource(const AUnitName: string; ALangID: string='');
    6. var Stream: TResourceStream;
    7.     ResName: string;
    8.     POFile: TPOFile;
    9.     hNd: THandle;
    10. begin
    11.   if (ALangID = '') then
    12.     LazGetShortLanguageID(ALangID);
    13.   ResName := UpperCase(AUnitName+'.'+ALangID);
    14.   hNd := FindResource(hInstance,PChar(ResName),RT_RCDATA);
    15.   if (hNd <> 0) then
    16.   begin
    17.     Stream := TResourceStream.Create(hInstance,ResName,RT_RCDATA);
    18.     try
    19.       POFile := TPOFile.Create(Stream);
    20.       try
    21.         TranslateUnitResourceStrings(AUnitName,POFile);
    22.       finally
    23.         POFile.Free;
    24.       end;
    25.     finally
    26.       Stream.Free;
    27.     end;
    28.   end;
    29. end;
    30.  
    31. initialization
    32.   TranslateUnitFromResource('lclstrconsts','nl');

    The .res file is created with the lazres tool that comes with lazarus:
    Code: [Select]
        ($Lazarus)\tools\lazres nlautotranslation.res ($Lazarus)\lcl\languages\lclstrconsts.nl.po

    See also this topic.

    Bart


    wp

    • Hero Member
    • *****
    • Posts: 12911
    Re: German caption for System-Buttons
    « Reply #7 on: October 14, 2023, 12:06:19 am »
    Nice idea. Would be great if this procedure were included in "Translations".

    loaded

    • Hero Member
    • *****
    • Posts: 870
    Re: German caption for System-Buttons
    « Reply #8 on: October 14, 2023, 08:11:07 am »
    Thanks to you, I learned something new too. I would like to thank my brother Onur for the "lclstrconsts.tr.po" file.
    I give 1 Like to wp and Bart for this nice solution.  :)
    Check out  loaded on Strava
    https://www.strava.com/athletes/109391137

    Zvoni

    • Hero Member
    • *****
    • Posts: 3007
    Re: German caption for System-Buttons
    « Reply #9 on: October 16, 2023, 09:14:25 am »
    If you have the .po file as a resource there is no need to store it temporarily, you can perform the translation from with the resource.
    An excerpt from one of my convenience units:

    The .res file is created with the lazres tool that comes with lazarus:
    Code: [Select]
        ($Lazarus)\tools\lazres nlautotranslation.res ($Lazarus)\lcl\languages\lclstrconsts.nl.po

    See also this topic.

    Bart

    Bart, thank you. Exactly what i was looking for.
    Adjusted to "de", added unit in  lpr-file, go!
    +1
    Thx
    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