I've programmed a Lazarus application in German and now I want to translate it into English. So I activated i18n in the project settings and checked "update .po file...". Then, I created a unit uTranslationStrings
and put resourcestring example = 'Beispiel';
before implementation
. I made sure to use
uTranslationStrings, DefaultTranslator, LCLTranslator
in my main unit. Then, I ran the application and opened the projectXY.po
file in Poedit. I translated everything into English and saved it as projectXY.en.po
. I did the same thing for the German locale. Also, I added a language menu entry letting the user switch between German and English.
procedure TMainForm.MenuDeutschClick(Sender: TObject);
begin
SetDefaultLang('de');
end;
procedure TMainForm.MenuEnglischClick(Sender: TObject);
begin
SetDefaultLang('en');
end;
But when I try to actually switch the languages, nothing happens. I thought the reason could be that all the translation strings are just captions of labels so I added the following code in uMain
:
Application.MessageBox(PChar(i18nWarning),PChar(i18nError),MB_ICONERROR);
and the following code in uTranslationStrings
:
resourcestring
// other strings
i18nWarning = 'Warnung! Deine Eingabe ist inkorrekt!';
i18nError = 'Fehler';
but the MessageBox
is always displayed in German even if I start my program with program.exe --lang en
(but note that the German text is displayed).
Why is that and how to fix it?
Thank you!
Here's how I "solved" the problem: I completely deleted the i18n and did everything again (in the exact same way). For some reason, it does work now.