Author Topic: [ANSWERED] How to unload a translation?  (Read 227 times)

CM630

  • Hero Member
  • *****
  • Posts: 1809
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
[ANSWERED] How to unload a translation?
« on: September 14, 2026, 10:34:53 am »
I apply .PO translations with this code:

Code: Pascal  [Select][+][-]
  1. procedure SetAppLang(LocaleFileName: string; LangCode: string = '');
  2. var
  3.   LocalTranslator: TUpdateTranslator;
  4.   i: integer;
  5. begin
  6.   if (LocaleFileName = '') or (FileExistsUTF8(LocaleFileName) = false)  then exit;
  7.   LocalTranslator := nil;
  8.   Translations.TranslateResourceStrings(LocaleFileName);
  9.   LocalTranslator := TPOTranslator.Create(LocaleFileName);
  10.   if (LangCode <> '') then
  11.     TranslateLCLResourceStrings(LangCode, LocaleFileName);
  12.  
  13.   if (LocalTranslator<>nil) then
  14.   begin
  15.     if Assigned(LRSTranslator) then
  16.       LRSTranslator.Free;
  17.     LRSTranslator := LocalTranslator;
  18.     for i := 0 to Screen.CustomFormCount-1 do
  19.       LocalTranslator.UpdateTranslation(Screen.CustomForms[i]);
  20.     for i := 0 to Screen.DataModuleCount-1 do
  21.       LocalTranslator.UpdateTranslation(Screen.DataModules[i]);
  22.   end;
  23. //  LocalTranslator.Free; - do not free, the app will crash
  24. end;  
  25.  

But how can I unload a translation, in order to have the original captions and resource strings displayed?
« Last Edit: September 14, 2026, 02:46:41 pm by CM630 »
Лазар 4,8 32 bit (sometimes 64 bit); FPC3,2,2

Zvoni

  • Hero Member
  • *****
  • Posts: 3574
Re: How to unload a translation?
« Reply #1 on: September 14, 2026, 10:44:01 am »
Have the original Captions/Strings in its own PO-File.
You insert between Line 5 and Line 6 a check if LocaleFileName is Empty, and Line 6 you check only for Existance

Code: Pascal  [Select][+][-]
  1. If LocaleFileName = '' Then LocaleFileName:=FileNameOfOriginalStrings.po;
  2. if (FileExistsUTF8(LocaleFileName) = false)  then exit;
  3. //Everything else stays as it is
  4.  

You reset Everything by passing an empty string for LocaleFileName, optionally passing the LanguageCode
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

CM630

  • Hero Member
  • *****
  • Posts: 1809
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to unload a translation?
« Reply #2 on: September 14, 2026, 10:59:40 am »
Have the original Captions/Strings in its own PO-File.
...
This is how I do it now, but I wonder if I can reset without restarting the app.
Лазар 4,8 32 bit (sometimes 64 bit); FPC3,2,2

Zvoni

  • Hero Member
  • *****
  • Posts: 3574
Re: How to unload a translation?
« Reply #3 on: September 14, 2026, 11:12:00 am »
Have the original Captions/Strings in its own PO-File.
...
This is how I do it now, but I wonder if I can reset without restarting the app.
Ouch.
You want to avoid a restart of the App?

The only thing coming to mind would be dynamic assigning of Captions from code.
As in: You would have to run through all Controls, and set their captions to whatever Language-Strings you have currently loaded.
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

wp

  • Hero Member
  • *****
  • Posts: 13687
Re: How to unload a translation?
« Reply #4 on: September 14, 2026, 11:54:45 am »
The untranslated strings are in the pot file. I copy it and give the copy the extension .en.po (assuming that the untranslated version of your application is in English). I load the .en.po file into poedit, select each line one by one and press CTRL+B - this copies the original string into the translated column (unfortunately poedit does not have a command to copy all strings). After saving you have your original strings in a standalong "translation" file to which can be used like any other translation file without having to restart the application.

CM630

  • Hero Member
  • *****
  • Posts: 1809
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to unload a translation?
« Reply #5 on: September 14, 2026, 12:02:34 pm »
...
The only thing coming to mind would be dynamic assigning of Captions from code.
As in: You would have to run through all Controls, and set their captions to whatever Language-Strings you have currently loaded.
I also thought about that, but this way I will have to loop trough all forms, too + I am not sure if it will handle the localisations of the LPKs.


The untranslated strings are in the pot file. I copy it and give the copy the extension .en.po (assuming that the untranslated version of your application is in English). I load the .en.po file into poedit, select each line one by one and press CTRL+B - this copies the original string into the translated column (unfortunately poedit does not have a command to copy all strings). After saving you have your original strings in a standalong "translation" file to which can be used like any other translation file without having to restart the application.
Quite the same to what I am doing now. But according to my observation it is not necessary to do the Ctrl+B thing. When an untranslated entry is present, its default value is taken. All that shall be taken care of is to update the default .PO from the .POT regularly.
Лазар 4,8 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13687
Re: How to unload a translation?
« Reply #6 on: September 14, 2026, 12:25:29 pm »
Quite the same to what I am doing now. But according to my observation it is not necessary to do the Ctrl+B thing. When an untranslated entry is present, its default value is taken. All that shall be taken care of is to update the default .PO from the .POT regularly.
Ah, you're right. I think I had made the opposite observation, but this seems to have changed.

 

TinyPortal © 2005-2018