Page 1 of 1

How to UN-translate a string?

Posted: Thu Apr 03, 2014 8:07 am
by anudedeus
My default language is English, but the user configuration might be using for example Portuguese in the application (i.e. the active language is Portuguese).
How do I use any tranlated word (a string in a const section) that is currently translated to Portuguese and find out the original English(default) word?

For example, the Portuguese word for 'street' is 'rua'.
When I find the string 'rua' in my application, I want to revert it back to 'street', without having to change the active language, I just need to know where 'rua' came from.

Posted: Fri Apr 04, 2014 1:37 pm
by isiticov
Hello,

There is FStringsColl protected property of TsiLang which is TsiStringsCollection. You can iterate through its Items property and check their Values[LanguageIndex] property to detect if your current string matches it. Then retrieve Values[0] (which is assumed to be default) to get default value.
Hope this helps.

But my FStringsColl.count is 0

Posted: Mon Apr 07, 2014 2:15 pm
by anudedeus
Thanks, but for some reason, even though I have 21 languages loaded, the collection count is still 0.
See example below, what am I doing wrong?

Code: Select all

type TAccessTsi = class(TsiCustomLang);

procedure TMyForm.StatusBarDblClick(Sender: TObject);
var 
lStr : TsiStringsCollection;
 s : String;
 i : Integer;
 L : Integer;
begin
  s := 'Departamento';
  lStr :=  TAccessTsi(siLang1).FStringsColl;
  L := 5;
  for I := 0 to lStr.Count -1 do //<<<<< [b]THIS COUNT IS ALWAYS 0!![/b]
  begin
     if lStr[i].Values[L] = s then
       outputdebugstring(pchar('Found it: '+lStr[i].Values[0]))
     else
       outputdebugstring(pchar('not yet: '+lStr[i].Values[L]));
  end;
end;

Posted: Tue Apr 08, 2014 6:47 am
by isiticov
May be Strings property of TsiLang is empty in your case? FStringsColl uses Strings property. If you need to retrieve the default value for ANY string then you would need to iterate through all TsiLang translation properties like Captions, Hints and so on and test the value.