Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Enabling TLang to handle more than 17 translations: a workaround for a regression bug in Delphi XE3

, 15 Jan 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
With TLang you can define a collection of native strings to be localized and the corresponding translations to a particular language.

I recently had to localize a FireMonkey application and for that I aimed to use the TLang component. With TLang you can define a collection of native strings to be localized and the corresponding translations to a particular language. To my surprise the component was allowing to store a maximum of 17 translations for the whole application. So, what about the other strings that need localization?

It seems there’s a regression issue from Delphi XE2 to Delphi XE3 that is preventing TLang to store more than 17 translations. You can even find an entry for this in Embarcadero Quality Central, for which no workaround or fix has been provided up to this date.

I found a programmatic workaround for this issue. Basically, the native strings and the translations could be loaded from text files in which each line will have the form:

NativeString1=Translation1
NativeString2=Translation2
NativeString3=Translation3
…………
NativeStringN=TranslationN

You will need one file containing the native strings and the translations per language. These files can contain as many lines as you which (certainly more than 17). In order to load those files into an existing TLang component you can use the function below:

procedure LoadTranslationsFromFile(aLangCode: string; aFileName: string; aLang: TLang);
var
  Translations: TStrings;
begin
  if (aLangCode <> '') and
     (FileExists(aFileName)) and
     (Assigned(aLang)) then
  begin
    Translations:= TStringList.Create;
    Translations.LoadFromFile(aFileName);
    aLang.Resources.AddObject(aLangCode, Translations);
  end;
end;

For an example of how to use such function see below:

procedure TForm1.Button1Click(Sender: TObject);
begin
  LoadTranslationsFromFile('ES', 'C:\Temp\Lang_Test_ES.txt', Lang1);
  LoadTranslationsFromFile('EN', 'C:\Temp\Lang_Test_EN.txt', Lang1);
end;

Hopefully this bug will be fixed in the near future; but meanwhile you can use this workaround to handle more than 17 translations with the TLang component.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

yanniel
Software Developer Digital Rapids
Canada Canada
My name is Yanniel Alvarez Alfonso. I was born in San Antonio de los Baños, Havana Province, Cuba on October 24th, 1982.
 
I majored in Information Technology Engineering at José Antonio Echeverría Polytechnic Institute (CUJAE) in Havana City, Cuba (July 2006). After that, I got a Masters Degree in Applied Computer Science at the same University (May 2009).
 
I used to work as a professor of Information Technology at CUJAE. Right now, I work as a Software Developer in Toronto, Canada. I moved to Canada under the Skilled Worker Program on February 26th, 2010.
 
This is my personal blog: Yanniel's notes; in which I write about miscellaneous topics.
 
The link at the end of this sentence compiles an index of all the articles I have written so far about Delphi Programming.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 15 Jan 2013
Article Copyright 2013 by yanniel
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid