Sign in Join
FPDoc Onlineexperiment

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

EPOFileErrorclassException type raised when an error occurs in the UpdatePOFile or UpdatePOFileTranslations routines.
TLanguageIDrecordRecord type used to return language and country codes/identifiers for a locale.
TPOFileclassClass used to represent a .po file with translation entries for a single target language.
TPOFileItemclassRepresents a single key/value pair in a .po file which maps a string to its translated value.
TTranslationStatisticsrecordRepresents translation statistics calculated for the key/value pairs in a .po translation file.

Procedures and functions

FindAllTranslatedPoFilesfunctionReturns a string list with the fully-qualified path to .po files for the same unit as the specified file name.
GetLanguageIDfunctionGets a record with the language code and country code for the current system locale.
GetLanguageIDFromLocaleNamefunctionGets the language identifier found in the specified locale identifier.
GetPOFilenamePartsfunctionGets the unit name and language used in the specified Filename.
TranslateResourceStringsfunctionTranslates all resource strings using the specified .po or .pot file.
TranslateUnitResourceStringsfunctionTranslates resource strings for one unit.
UpdatePoFilefunctionUpdates a specified .PO template using the list of translations specified.
UpdatePoFileTranslationsprocedureUpdates all .po translation files found in the path using the specified .pot template file.
UTF8ToSystemCharSetfunctionConverts the specified UTF-8-encoded string to the character set for the system locale.

Types

TStringsTypeenumerationFormat used in the string table passed to the TPOFile.UpdateStrings method.
TTranslateUnitResultenumerationRepresents the return value for the TranslateUnitResourceStrings function.

Constants

sBadFormatFlagconstantValue used for the "badformat" flag in a translation entry.
sFormatFlagconstantValue used for the language-specific "format" flag in a translation entry.
sFuzzyFlagconstantValue used for the "fuzzy" flag in a translation entry.
sNoFormatFlagconstantValue used for a language-specific "format" flag is not used in a translation entry.

Variables

SystemCharSetIsUTF8variableIndicates 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.