Programming => General => Topic started by: wp on February 02, 2013, 08:03:44 pm

Title: Localization of frames
Post by: wp on February 02, 2013, 08:03:44 pm
One of my applications is being localized to several languages. I am using po files as described in the wiki ( One feature is the possibility to switch language according to the selection of a combobox. As I observed many strings change immediately, but some do not change. It turned out that these strings belong to texts on embedded frames.

The attached demo demonstrates this behavior. The form contains two versions of a frame (in unit2) with just a label "Text on frame". The first frame is embedded into the form without modification. In the other frame the text is changed to "Modified text on frame". There is another label ("Text on form") which resides in the form directly.

When the language is switched to "German" you see that all strings switch to German language except for the one on the unmodified frame ("Text on frame").

The program uses a modified local copy of the DefaultTranslator unit (see below). When stepping through the method TUpdateTranslator.IntUpdateTranslation the strings of the original frame are not found because the Translator only scans the CustomForms of the application, not the frames. If I knew how to access the non-embedded frames of an application I'd think the translator would find also those strings.

There is another issue when I want to revert the translation to the one built into the application. When you run the demo, click on "German", and then on "Built-in language" (which is written in German now), but you'll see that the language does not switch back to English. For the English strings I had the idea to use the non-translated po file which contains the nontranslated string. I modified the DefaultTranslator such that it uses this file when SetDefaulLang is called with an empty string. But obviously, the strings are not translated. Is there a way to use the nontranslated po file? Or do I always have to create an English translation file (as it is called when clicking on the "English" button).
Title: Re: Localization of frames
Post by: wp on February 03, 2013, 03:04:10 pm
In the meantime I could fix the translation issue with the embedded form. The solution was to check the frame class explicitely whenever an embedded frame is detected. Here are the changes to be applied at the end of TUpdateTranslator.IntUpdateTranslation (in DefaultTranslator.pas):

Code: [Select]
procedure TUpdateTranslator.IntUpdateTranslation(AnInstance: TPersistent);
  if (AnInstance is TComponent) then
    for i := 0 to TComponent(AnInstance).ComponentCount-1 do
      // wp: begin inserting
      if TComponent(AnInstance).Components[i] is TCustomFrame then begin
        FStackPath := StoreStackPath;
      // wp: end inserting

I'll post a bugreport in the BugTracker
TinyPortal © 2005-2018