* * *

Author Topic: LCLTranslator and XML Property Storage  (Read 416 times)

cpicanco

  • Sr. Member
  • ****
  • Posts: 411
    • My Portfolio
LCLTranslator and XML Property Storage
« on: September 04, 2017, 04:56:22 pm »
Hi,

LCLTranslator may conflict with persistence components like XML Property Storage. For example, setting default languages will reset comboboxes itemindex and text. As a work around, I am doing this:

https://github.com/cpicanco/stimulus_control/blob/98bc398ffa31c943a473653f6606de12f737af37/src/forms/userconfigs.pas#L323-L339

Code: Pascal  [Select]
  1. procedure TFormUserConfig.XMLPropStorage1RestoreProperties(Sender: TObject);
  2. var
  3.   Texts : array [0..4] of string;
  4.   ItemIndexes : array [0..4] of integer;
  5.   ComboBoxes : array [0..4] of TComboBox;
  6.   i: Integer;
  7. begin
  8.   ComboBoxes[0] := ComboBoxLanguage;
  9.   ComboBoxes[1] := ComboBoxGridType;
  10.   ComboBoxes[2] := ComboBoxRandomize;
  11.   ComboBoxes[3] := ComboBoxFillTargetColumn;
  12.   ComboBoxes[4] := ComboBoxBlocCounter;
  13.  
  14.   for i := Low(ComboBoxes) to High(ComboBoxes) do
  15.   begin
  16.     ItemIndexes[i] := ComboBoxes[i].ItemIndex;
  17.     Texts[i] := ComboBoxes[i].Text;
  18.   end;
  19.   SetDefaultLang(XMLPropStorage1.StoredValue['language']);
  20.   for i := Low(ComboBoxes) to High(ComboBoxes) do
  21.   begin
  22.     ComboBoxes[i].ItemIndex := ItemIndexes[i];
  23.     ComboBoxes[i].Text := Texts[i];
  24.   end;

But it is ugly and would require a lot of work in the long term. So, any alternatives, recommendations?

cpicanco

  • Sr. Member
  • ****
  • Posts: 411
    • My Portfolio
Re: LCLTranslator and XML Property Storage
« Reply #1 on: September 12, 2017, 04:22:10 pm »
Why:

Code: Pascal  [Select]
  1.   SetDefaultLang(XMLPropStorage1.StoredValue['language']);

will reset properties of comboboxes? Is it a "bug" or a "feature"?

wp

  • Hero Member
  • *****
  • Posts: 3894
Re: LCLTranslator and XML Property Storage
« Reply #2 on: September 12, 2017, 04:33:39 pm »
That's what SetDefaultLang is supposed to do: It translates the resource strings and strings used in visual controls to the language passed as a parameter.

If you don't want to switch language don't call SetDefaultLang, only read the value of the xml node.

If you don't want to translate combobox strings make sure that they are not translated in a po file.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

cpicanco

  • Sr. Member
  • ****
  • Posts: 411
    • My Portfolio
Re: LCLTranslator and XML Property Storage
« Reply #3 on: September 12, 2017, 11:30:41 pm »
I want to translate the strings contained in Combobox.Items. It is not done automagically by calling SetDefaultLang as far as I know. So do you mean it is a "bug"...?

wp

  • Hero Member
  • *****
  • Posts: 3894
Re: LCLTranslator and XML Property Storage
« Reply #4 on: September 13, 2017, 12:24:18 am »
You are right: looking into the source code of TUpdateTranslator.IntUpdateTranslation (unit LCLTranslator), I see that this in fact does not translate the Items of any TStrings descendant - sorry for the confusion.

I don't know if it is a bug, but I think this translation would be very difficult to add because the Items of TStrings cannot be accessed outside the class, and a TStrings property is created in many facets, even in a platform-dependent way.

But why don't you post a report/feature request in BugTracker?
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

cpicanco

  • Sr. Member
  • ****
  • Posts: 411
    • My Portfolio
Re: LCLTranslator and XML Property Storage
« Reply #5 on: September 13, 2017, 01:23:15 am »
Thank you wp! I can do that feature request.

Further, as you might expect, I am filling the Items using normal resource strings, saving them using XML property storage and doing the mentioned hack to load everything back.

cpicanco

  • Sr. Member
  • ****
  • Posts: 411
    • My Portfolio
Re: LCLTranslator and XML Property Storage
« Reply #6 on: September 13, 2017, 01:48:36 am »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus