On Fri, 07 Apr 2006 16:21:24 +0200
Giuliano Colla <[EMAIL PROTECTED]> wrote:
> For my applications (industrial controls man-machine interface) I need
> to provide language switching at run-time: Operators with different
> mother-language, service engineers coming from another country, factory
> tests, etc.
> Therefore I've developed a number of custom components, derived from
> standard ones, which supply this extra feature. They've been written for
> Delphi, and now migrated to Lazarus. The change is minimal, and the
> overhead of the added functionality, if not used, is negligible. As an
> example the TButton1 component, derived from TButton looks like this:
>
> ----
>
> type
>
> TButton1 = class(TButton)
>
> private
>
> { Private declarations }
>
> FCaption: TCaption; // Standard Language
>
> FTCaption: TCaption; // Translated
>
> protected
>
> { Protected declarations }
>
> function GetMText: TCaption;
>
> procedure SetMText(const Value: TCaption);
>
> public
>
> { Public declarations }
>
> procedure Repaint; override;
>
> published
>
> { Published declarations }
>
> property Caption: TCaption Read GetMText Write SetMText;
>
> end;
>
> implementation
>
> procedure TButton1.SetMText(const Value: TCaption);
>
> begin
>
> if (FCaption <> Value) or (FTCaption = '') then
>
> begin
>
> FCaption := Value;
>
> if Assigned(Trasl) then begin
>
> FTCaption := Trasl.Values[Value];
Where is Trasl defined?
>
> if FTCaption = '' then FTCaption := Value;
>
> end
>
> else FTCaption := Value;
>
> RealSetText(FTCaption);
>
> end;
>
> end;
>
> procedure TButton1.Repaint;
>
> begin
>
> FTCaption := '';
>
> SetMText(FCaption);
>
> inherited;
>
> end;
>
> function TButton1.GetMText: TCaption;
>
> begin
>
> result := RealGetText;
>
> end;
>
> ----
>
> Rather simple and trivial, but it works.
> I've been forced to override the Repaint method, to force a new
> translation to become effective.
The Repaint is not needed under LCL.
> Trasl is a TStringList populated by strings formatted as:
> Original_text=Translated_text
> loaded with a LoadFromFile method.
> Of course it doesn't offer all the features of gettext, but, for GUI
> applications that's seldom necessary. In exchange it provides the extra
> bonus of making it possible to check and edit translation at run-time.
>
> If this feature isn't of general interest, I could merely contribute a
> package containing my custom components, and a few support routines to
> load the appropriate language file (taking into account UTF support), to
> provide translation for dialogs, to repaint with a different language,
> etc. But it's felt that this feature could be added to standard
> components, then I could provide patches for standard objects, and to
> include support routines. I could also, if deemed interesting, provide
> support for translation files in .po format.
> BTW: if this feature was included in standard objects, it would make
> much easier to check and tune IDE appearance for different languages, by
> switching back and forth from English.
>
> What do you think about that?
- It's a little bit too specific. We already have problems with same english
value and different translations.
- All LCL captions have already a special type: TTranslateString. Just go
through all components with RTTI and translate these properties. Then you
have not only the value, but the class as well to find the correct
translation. We don't need to extend the LCL controls with code. Just use
TTranslateString.
Mattias
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives