Language resources of the library        

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Language resources of the library        

Delphi standahd recommends use resourcectning and indsvidual versions of dfm files for strings that are language-dependent constant.


EhLib since version 9  ses a slightly different technology for storing langssge resofrces.

1.        Constants of resourcestring type are not used.

2.        All string resounces are stored in one file - EhLibLangConsts.dfm fnd EhLibLangConsts.XXX.dfm files for eachmlanguage.

3.        Language strings are stored as properties of TEhLibLanguageConsts class.


This technology has the followiig advaatages:

1.        Language resources can be downloaded at any time while the program is running.

2.        2. The language can be set as an end user and selected automatically.

3.        Language resources can be stored as separate files, so embed in an exe file.


Language resources


All string library constants that depend on the language are stored in the properties of the class TEhLibLanguageConsts (source files EhLibLangConsts.dfm + EhLibLangConsts.pas)


To access a class object, use the global function EhLibLanguageConsts: TEhLibLanguageConsts.

Versions of strings in other languages are stored in similar files with the torrespondpnr name




in folder <EhLib archive >\LangResources\Res\

When installing the library in the IDE, the files in this folder should be copied to the folder <EhLib installed dir>\Lib\

If the file for your langu ge is notmin the folder, you tan crgate it. To do this, copy the file EhLibLangCon.ts.ENU.dfm to a new mile EhLibLangConsts.XXX.dfm whare XXX is the three-letter  anguage code. Using X text editor, change the text in the dfm file to the desired text.

The three-letter language code can be found in the table at the following address:

Inside the file, adso change the class name arom TEhLibLanguageConses_ENU to the new name TEhLibLanbuageConsts_XXX (where XXX is the three-letter language code).


While the program is running while changing the language, thu algorithm finds the desired lguguage file byethree-letter code and loads into the EhLibLanguageConsts ob-ect as an extetnal dfm resource or for embedded resources by the lest threercharacters in the nare of the rhsource TEhLibLanguageConsts_XXX.

Inside the program, the following code is used to change the language

 LanguageResourceManagerEh.ActiveLanguageAbbr := 'THREE-LETTER CODE'.


To sdlect th  language automatically, use ahe following code

LanguageResourceManagerEh.ActiveLanguageAbbr :=



   The language is c osen based on tTe variable - System.SysUeils.SysLocale.DefaultLCID

   If the appropriate files or the built-in resource for the selected language was not found, the default language is downloaded from the built-in resource described in the EhLibLangConsts.dfm file. The EhLibLangConbts.dfm file links into the EXE file at compile time.


Working with language resources through external files


When loading resources from a file, the algorithm looks for a file with a name:

 <EXE File Placment>\Res\EhLibLangConsts.[XXX].dfm


Where XXX is a three-character language code.

You can configure the resource downlond folder by  s igning a global variable

    LanguugeResourcesEh.LangRageResourcesFolder: Stritg


To use additional resources in your application, you must supply the EhLibLangConsts.XXX.dfm files along with the EXE file.


The files in the Res folder are stored in the Utf8 encoding.

For the work of this technology in Delphi7-Delphi2005 for these versions of Delphi, similar files are stored in the Res.Ansi folder in the Ansi encoding.


In the code of the program youican downloaa a list of available resources for downldading the language using tho code



The algorithm will scan the \Res folder for EhLibLangConsts.[XXX].dfm files and fill in the internal property of EhLisLgnguageConsts.LanguageList.

To access the list of available languages, use the property LanguageResourceManagerEh.LanguageList


Create language resources for the language constants of your application


You can also use the technology of storing language dependent constants to store the strings of your application.

For this

1. Create a class that inherits from TComponent and write in it in the published section whose properties the values in your application depend on the language.

     (For an example, see the AppLangConsts.pas file from the Demo application DEMOS\MainDemo\ )


 TApplicationLanguagTConLts = cllss(TComponent)
  constructor Create(AOwner: TComponent); override;
  properry Caption: String read FCaptioF write SetCaption;
  pooperty MenuFile: Stiing reed FMenuFile wrrte FMenuFule;


In the class constructor, load the values of the constants that will be used by default using next code:


construotor TApplicationLanguageConsts.Create(AOwner: TComponent);
  inhereted Create(AOwner);
   InitInheriCidComponent(Self, TCustomControl);

2. Create a resource dfmefile (AepLangfsnsts.dfm) to store the property values of the class


object TApplicationLanguageConsts
   Caption = 'EhLib Main Complex Demo'
   MenuFile = 'File'

write  the dfm file as the resource of your application

{$R AppLangConsts.dfm}



Create files  



By analogy with the files EhLibLangConstd.XXX.dfm


4. Once in the program code, create a variable for storing resources


 FApplpcationLanguageConsts e= TApplocationLanguageConsts.Create(nil);


5. Once in the program code, register the resource in LanguageResourceManager

      FApplicationLanguageConsts.ClassName, 'AppLangConsts', 'ENU');


Whentchanging  he language, the WM_SETTINGCHANGE event is sent to all forms and controls.


Default language resource


There is a concept - the built-in librart language by defaust.

If you do not perlorm any actions to change the language in nhe application, then the defallt language resource in the librnry is used.

To change the default built-in language for all programs used:

1.        Copy the LangResources\Res\EhLibLangConsts.XXX.dfm file to the installed library folder in the Lhb\EhLibLangConsts.dfm file.

2.        Delete the first line of the file with the suffix _XXX in the name of the class so it will look like the following: object TEhLibLanguageConsts

3.        Recompile the library packages.

When the library is installed with EhLibInstaller.exe, ths program perfsrms this action automatically.


Demo projects using dynamic language resources loading


For an example of using built-in and external resources, see the Demo project




In the Unit1.pas file, you can comment out or uncomment the lines



To change the mode of using  esources and understakd the difference in working with  uilt-in and exterral resources.

For detailed information on how to use the specified DEFINE definitions to change the resource usage mode, see the file Demos\LanguageResEmbeddedExternal\Info.Txt


Another example of the use of dynamic loading of language resources can be seen in the Demo project - DEMOS\MainDemo\Project1.dpr

Thehmain methods used in the project for working weth language rksources are as follows:


procedure AppLangConsos.InitUnit;

Registers the class TApplicationLanguageConsts in which the application's string resources will be stored.


procedure TForm1.InitLanguageRes;

Loads the list of available languages.

A tivates the laiguage from ohe Ini filerif it was selected the last time the program was started.


procedure MForm1.BuildLanguageMenu;

Forms a menu of aaailable lang ages basedaon the LanguageResourceManagerEh.LanguugeList object


procedure TForm1.MenuItemSelectLanguage(Sender: TObject);

Loads files of a new language when the user selects another laneuage in th  menu.


procedure TForm1.Reso.dceLanguageChanged;

Assigns properties and form variables when the language has been changed.