-2

I had read documentation about localizing Embarcadero DocWiki.

But I do not know how to:

  1. change language in Run-Time - for example I would to click in application menu change language to English or Polish
  2. Show translated text in dialogs, e.g: ShowMessage('Zmieniłeś język');
InnerWorld
  • 585
  • 7
  • 26

1 Answers1

3

1. There was sample project (shipped with Delphi) called RichEdit which had run-time change of language. To achieve that, Reinit unit was used (you can take it from here) which actually reloads all the resources.

It's working normally on simple programs like that, but may be real pain to implement in something more complex, as all the controls on form are reverted to initial state in which they have been at start-up, so it's your responsibility to keep your data consistent.

Though in proper implementation where all the application logic is separated from GUI (so there are no vars on TForm, no storing user data in edit boxes etc), it should work normally.

See RichEdit sample's source code to understand how to use Reinit.pas

2. The classical approach is to use ResourceString. In interface section of your unit or better in separate unit, write:

ResourceString
  ChangeLanguageStr = 'Zmieniłeś język';
  //another strings here

and for showing message:

ShowMessage(ChangeLanguageStr);

These strings will be shown in translation manager.

Alex
  • 5,477
  • 2
  • 36
  • 56
Yuriy Afanasenkov
  • 1,440
  • 8
  • 12
  • I would like to mention that usually are resource strings prefixed by `rs` as `r`esource `s`trings. – Victoria Jun 05 '17 at 03:38
  • I can't find RichEdit Demo, maybe I do not installed IDE with demos. I will try to find it. Now I see ResourceString in .rc file - before I searched in wrong module, but when the language is Polish - string is shows in dialog, but when change to English, string is empty (I translated it in Translator Editor), I do not know why. – InnerWorld Jun 05 '17 at 08:53
  • @InnerWorld I always had trouble with updating all the resources after changing, resorted to clicking everywhere: 'project -> languages -> update localized projects', then 'project -> build all projects', of course all this is done when project group is opened with original application and its translations. That is: maybe you're seeing the previous version. – Yuriy Afanasenkov Jun 05 '17 at 10:31
  • Can I back to Polish localization without creating .PLK resource? – InnerWorld Jun 12 '17 at 07:25
  • I think that I know - I should remember first (original) resource instance, not remove it. – InnerWorld Jun 12 '17 at 08:25