Recent

Author Topic: Internationalization in Custom Controls  (Read 2083 times)

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Internationalization in Custom Controls
« on: March 18, 2018, 12:30:00 pm »
Hello all,

I made a multi language application using the LCL's i18n capabilities. For LCL controls (TButton, TLabel etc.) and ResourceStrings this works fine.
For custom controls, e.g. a button based on TCustomControl, currently I do the translations using a ResourceString and assigning the captions "manually" for each button which is quite some effort. I'd like to implement the i18n capabilities in the control.

So my question is, how to implement a string property in a custom control to be 'i18n'-sensitive? I.e. to be listed in the po-file by Lazarus and to be translated automatically by the LCLTranslator.

A web and forum search didn't bring me further.

Regards~
« Last Edit: March 18, 2018, 12:44:24 pm by kupferstecher »

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Internationalization in Custom Controls
« Reply #1 on: March 18, 2018, 12:47:54 pm »
A rough guess: Declare the string as TTranslateString?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Internationalization in Custom Controls
« Reply #2 on: March 18, 2018, 01:11:13 pm »
published properties?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Internationalization in Custom Controls
« Reply #3 on: March 18, 2018, 01:58:28 pm »
It works  :)

Thanks for both your answers!

The string has to be declared as TTranslateString as public property. After (!) the package is installed in Lazarus the translation works like on any other Control.

Code: Pascal  [Select][+][-]
  1. type TFancyButton = class(TCustomControl)
  2.   ...
  3.   protected
  4.     fButtonCaption: TTranslateString;
  5.     procedure SetButtonCaption(ACaption: TTranslateString);
  6.   published
  7.     property Caption : TTranslateString read fButtonCaption write SetButtonCaption;

EDIT: Added in the Wiki.
http://wiki.freepascal.org/Everything_else_about_translations#Control_design_with_internationalization_capability
« Last Edit: March 18, 2018, 02:22:43 pm by kupferstecher »

 

TinyPortal © 2005-2018