Translations unit
Contains classes and routines used to load/check/maintain translations from .po (portable object) files.
translations.pas contains classes and routines used to
load/check/maintain translations from .po (portable object) files.
translations.pas is part of the
LazUtils package.
Initial authors: Mattias Gaertner, Bart Broersma, Giuliano Colla
Example 1: Load a specific .po file
procedure TForm1.FormCreate(Sender: TObject);
var
PODirectory: String;
begin
PODirectory := '/path/to/lazarus/lcl/languages/';
TranslateUnitResourceStrings('LCLStrConsts',
PODirectory+'lcl.%s.po', 'nl', '');
MessageDlg('Title', 'Text', mtInformation, [mbOk, mbCancel, mbYes], 0);
end;
Example 2: Load the current language file using the GetLanguageID function:
uses
...
Translations;
procedure TranslateLCL;
var
PODirectory: String;
LangID: TLanguageID;
begin
PODirectory:='/path/to/lazarus/lcl/languages/';
LangID := GetLanguageID;
Translations.TranslateUnitResourceStrings('LCLStrConsts',
PODirectory+'lclstrconsts.%s.po', LangID.LanguageID,
LangID.LanguageCode);
end;
...
begin
TranslateLCL;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.Classes and records
EPOFileError | class | Exception type raised when an error occurs in the UpdatePOFile or UpdatePOFileTranslations routines. |
TLanguageID | record | Record type used to return language and country codes/identifiers for a locale. |
TPOFile | class | Class used to represent a .po file with translation entries for a single target language. |
TPOFileItem | class | Represents a single key/value pair in a .po file which maps a string to its translated value. |
TTranslationStatistics | record | Represents translation statistics calculated for the key/value pairs in a .po translation file. |
Procedures and functions
FindAllTranslatedPoFiles | function | Returns a string list with the fully-qualified path to .po files for the same unit as the specified file name. |
GetLanguageID | function | Gets a record with the language code and country code for the current system locale. |
GetLanguageIDFromLocaleName | function | Gets the language identifier found in the specified locale identifier. |
GetPOFilenameParts | function | Gets the unit name and language used in the specified Filename. |
TranslateResourceStrings | function | Translates all resource strings using the specified .po or .pot file. |
TranslateUnitResourceStrings | function | Translates resource strings for one unit. |
UpdatePoFile | function | Updates a specified .PO template using the list of translations specified. |
UpdatePoFileTranslations | procedure | Updates all .po translation files found in the path using the specified .pot template file. |
UTF8ToSystemCharSet | function | Converts the specified UTF-8-encoded string to the character set for the system locale. |
Types
TStringsType | enumeration | Format used in the string table passed to the TPOFile.UpdateStrings method. |
TTranslateUnitResult | enumeration | Represents the return value for the TranslateUnitResourceStrings function. |
Constants
sBadFormatFlag | constant | Value used for the "badformat" flag in a translation entry. |
sFormatFlag | constant | Value used for the language-specific "format" flag in a translation entry. |
sFuzzyFlag | constant | Value used for the "fuzzy" flag in a translation entry. |
sNoFormatFlag | constant | Value used for a language-specific "format" flag is not used in a translation entry. |
Variables
SystemCharSetIsUTF8 | variable | Indicates whether the default system character is UTF-8 for the platform. |
Uses
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
