Delphi FMX TLang Component data creation

Delphi FMX TLang Converter

Creating TLang content external with text editor or spreadsheet

We give out TLang Converter for free: See at the end of the article how to get it!

Delphi FMX.TLang Component is suitable for simple translation / localization processes within MS Windows, Mac OS or Android projects.
Unfortunately the editor for the texts is not very comfortable.
There is a Import-Function for new languages in Text format, but this mean, on every text change you have to import all files for all languages new.
Further there are some bugs and issues in the internal editor.
Also there is no way to delete languages – e.g. to import them from an external file again.
This mean, every time you change some languages you have to clear the component and load all files one by one into the component. Handling many files for different languages is further very prone to failure and not very comfortable to handle.

To enable a more comfortable editing of text resources we developed a CSV converter for the TLang Text format.
This enable
– editing the texts all in one place such as in a spreadsheet program like LibreOffice, OpenOffice or Excel.
– generating the texts out of databases or other tools.

Delphi FMX TLang Converter

The converter read the CSV File (Ansi or UTF-8) and write the binary LNG output file.

TLang.Spreadsheet

Sample of a source spreadsheet to edit the language texts.

After you have created the file, you can load this file in TLang with the function „Load file…“ within the TLang property editor (Doubleclick on the TLang component).

Important:
The TLang component have to be „initial“ befor loading files.
Either you’ve just created it or you delete the binary content of the section „ResourcesBin“ inside the FMX resource file.

object Lang1: TLang
     Lang = 'de'
     Left = 208
     Top = 32
     ResourcesBin = {
       68006900730020007400000770069006C006C00
       20006200650020007400400650064000D000A00
       ... }

Delete the whole entry „ResourcesBin“ prior import the LNG file.

After you have loaded your LNG file do not edit the content within the property editor: There seems to be another bug and some texts will be mixed up.
Just close the property editor after loading the LNG file and trust everything is ok.

Sample Project to show the TLang functions

This program show the use of the TLang component. The strings were be loaded by the converter program into TLang. There are sample spreadsheet data in ANSI and UTF16 to show the handling of external data.

SampleEnSampleDeSampleFrSampleZn

Follow this link to download a sample program for language switching.

This program include also code to do manual requests to the TLang component.

Manual Translations also can be done with the FMX.Types.Translate() function – so this is just an expamle how to work with the TLang component.

Usually the component translate everything on the form (or on its way to the form) itself. For example: When you assign a string to a TLabel, this string will be translated by the component, without any other code:

Label1.Text := 'English'

will result in

‚German‘ for that Label on the screen, if there is a according mapping in the translation resources of the component.
Non-styled components or dialogs do not support those mechanism. If you want to translate those texts, you have to do it by your own. Either you do this with the FMX Translate() or TranslageText() Function or with some code like this, using the TLang component:

Text1.Text := sTextManualF('English');

The routine to get certain text map entry out of TLang:

  function TfmMainSampleTLang.sTextManualF(sOrg: string): string;
  // translate a text, which is not in the automate translation process of TFmxObjects
  begin
   // first check, if the selected language has a mapping
    if Lang1.Resources.IndexOf(Lang1.Lang) >= 0 then
      begin
        // get the resource stringlist of the current language and get the translation
        result := Lang1.LangStr[Lang1.Lang].Values[sOrg];
        if result = '' then
          begin
          // text not found in mapping - keep original text
            result := sOrg;
          end;
      end
    else
      begin // language not found: must be the default language
        result := sOrg;
      end;
  end;

This routine of course could be placed inside a descendant of TLang individual to your project.

Getting the converter for free

We can give you the converter for free as freeware without cost.
Only thing we want is a link to our (this) homepage – to make this small company page a bit more famous 🙂

If you want to get the converter just send us a mail with the link and you got a free copy of the software.

Optional we offer services to do localizations or translations in our office here in Heidelberg for any Delphi VCL or FMX project.

Please contact by our main mail address in the contact page.

For very complex localization tasks you may want to use a external tool like
http://www.tsilang.com
http://www.regulace.org
– but for smaller projects or simple translation purposes we think, the TLang Component is not that bad than some may think after their first experience – especially if you use our converter.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert