The package introduces a non-visual VCL component called TDKLanguageController, which is to be placed on each form you wish to localize. Language controller automatically maintains an internal list of all components and their properties of type String (also known as AnsiString or long string), ShortString and WideString (complete Unicode support is implemented). There's a little chance you will ever need another type of data to be changed in synch with language change.
So, the language controller keeps a list of component properties, each having assigned a form-wide unique natural number identifier (ID). This is done transparently by the controller so you don't need to bother when you add or remove components to/from the form, or change their property values.
Additionally, if a controller's Options include dklcoAutoSaveLangSource (this is the default), the controller saves its data in a plain text file (starting with version 3.0 of the package the file encoding is Unicode) into the so-called project language source, each time you save modifications to the form the controller is on. The project language source is a file named the same as the project (.dpr) file, but having .dklang extension. Each controller replaces the corresponding section in that file when it saves its data. If autosave is off you are still able to save the controller data by right-clicking the component on the form and selecting the Save data to project language source item. You may also select the Project | Update project language source main menu item, this will force all the contollers available for the project to update their language source in project's .dklang file.
The package also introduces TDKLanguageManager class an instance of which is accessible via global function LangManager. The manager is instantiated first time the function is called. This will happen once a form having a controller will be instantiated, or when you invoke the LangManager e. g. to scan for language files (see the provided examples). Language manager performs all tasks of maintaining the list of available languages or switching between them.
Constants are often used to display messages, titles, labels etc. in language that should match the program language. DKLang offers a simple yet functional solution of implementing constants.
You define a set of constants in the default language of your project using Project | Edit project constants... IDE menu item (a project must be open in IDE). This opens DKLang Constant Editor dialog allowing you to review, edit, add or remove constants.
In order to link constant resource file to your project add the following line to project source file (.dpr):
A constant entry consists of a name and a value.
Constant name must meet the standard Delphi identifier naming requirements, i. e. consist of alphanumric,
digit and underscore characters only and not start with a digit; the name must be unique (case makes no sense) over
the whole list.
Constant value is a WideString (Unicode) value which can also be empty.
To read value of a constant you use its name (again, case-insensitively) and obtain an Unicode (original) or ANSI value (converted from Unicode using appropriate code pade) using these functions:
You may use freeware DKLang Translation Editor application to open the language source files (.dklang), and to create new translations (.lng files) based on them.
NB: Do not edit .dklang files directly since the contents of these files is controlled automatically by
language controllers and constant editor. Any changes to property mappings or constant values will be lost once the
file is updated!
Nevertheless, you can add your custom comments (each line starting with a semicolon) at the top of the file. The
package leaves such comments intact.