Author Topic: How to avoid duplicates in the PO translation files [SOLVED]  (Read 3750 times)

mig-31

  • Sr. Member
  • ****
  • Posts: 320
How to avoid duplicates in the PO translation files [SOLVED]
« on: August 13, 2026, 11:43:31 am »
How to avoid duplicates in the PO translation files?
For example I use the translation string in two units, for example Unit1 and Unit2
Code: Pascal  [Select][+][-]
  1. resourcestrings
  2.   sError='Error';
  3.  

This generates two same translation strings in the POT file

When I use INC file, where I collect translation strings, in each unit like that
Code: Pascal  [Select][+][-]
  1. resourcestrings
  2.  {$include translation.inc}
  3.  
In this case result is the same.
« Last Edit: August 13, 2026, 05:36:14 pm by mig-31 »
Lazarus 4.8 - OpenSuse Leap 15.6, Debian Forky

korba812

  • Hero Member
  • *****
  • Posts: 502
Re: How to avoid duplicates in the PO translation files
« Reply #1 on: August 13, 2026, 12:01:56 pm »
Just put all resourcestrings in a separate module.

mig-31

  • Sr. Member
  • ****
  • Posts: 320
Re: How to avoid duplicates in the PO translation files
« Reply #2 on: August 13, 2026, 01:44:47 pm »
I created a separate unit
Code: Pascal  [Select][+][-]
  1. unit translations;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. resourcestring
  8.   sUserID = 'User ID';
  9.   sNumberingSymbol = '#';
  10.   sStatus = 'STATUS';
  11.   sLot = 'LOT';
  12.   sArticle = 'ARTICLE';
  13.   sRecipe = 'RECIPE';
  14. implementation
  15.  
  16. end.                
  17.  

and added it to uses section Unit1 of Form1 and Unit2 of Form2. Now Lazarus generates me three copies of same translation string for three units.

Do I understand your tip correctly?
Thanks
Lazarus 4.8 - OpenSuse Leap 15.6, Debian Forky

korba812

  • Hero Member
  • *****
  • Posts: 502
Re: How to avoid duplicates in the PO translation files
« Reply #3 on: August 13, 2026, 01:48:31 pm »
Yes, you understood correctly. Did you remove the resourcestrings from Unit1 and Unit2?

mig-31

  • Sr. Member
  • ****
  • Posts: 320
Re: How to avoid duplicates in the PO translation files
« Reply #4 on: August 13, 2026, 03:06:26 pm »
Yes, I removed it.
Code: Pascal  [Select][+][-]
  1. unit unit1;
  2.  
  3. {$mode objfpc}{$H+}{$modeswitch advancedrecords}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
  9.   ExtCtrls, Buttons, Grids, ActnList, FileUtil, DefaultTranslator, LCLTranslator, appsettings, login, jobeditor,
  10.   StrUtils, recipeeditor, recipeutils, Types, translations;
  11.  
  12. {declarations}
  13.  
  14. implementation
  15.  
  16. {code}
  17.  
  18. end;
  19.  
  20.  

POT File

Code: Pascal  [Select][+][-]
  1. #: unit1.serror
  2. msgctxt "unit1.serror"
  3. msgid "Error"
  4. msgstr ""
  5.  
  6. #: unit2.serror
  7. msgctxt "unit2.serror"
  8. msgid "Error"
  9. msgstr ""
  10.  
  11. #: translations.serror
  12. msgctxt "translations.serror"
  13. msgid "Error"
  14. msgstr ""  
  15.  
Lazarus 4.8 - OpenSuse Leap 15.6, Debian Forky

CM630

  • Hero Member
  • *****
  • Posts: 1788
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to avoid duplicates in the PO translation files
« Reply #5 on: August 13, 2026, 03:33:30 pm »
Did you try to delete the old .POT?
I check a project with 3 forms, rosourcestrings are in a separate .pas, no dupli/triplication in the .pot.
Лазар 4,8 32 bit (sometimes 64 bit); FPC3,2,2

mig-31

  • Sr. Member
  • ****
  • Posts: 320
Re: How to avoid duplicates in the PO translation files
« Reply #6 on: August 13, 2026, 05:35:46 pm »
I missed one resourcestring in a small unit.

Now .pot generated correctly without duplicates.

Thanks a lot guys!!! :)
Lazarus 4.8 - OpenSuse Leap 15.6, Debian Forky

 

TinyPortal © 2005-2018