Unit 'Translations' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#lazutils]

Reference for unit 'Translations'

Contains classes and routines used to load/check/maintain translations from .po (portable object) files.

uses

  System,

  Classes,

  sysutils,

  jsonscanner,

  jsonparser,

  fpjson,

  FileUtil,

  

Miscellaneous routines, types, and classes for manipulating files, file names, and paths.

  LazFileUtils,

  

Contains types, procedures, and functions used for file and directory operations.

  LazUTF8,

  

Number of characters (codepoints) to get from the string.

  LConvEncoding,

  

Contains routines used to perform conversions between Unicode and System Code Page encodings.

  LazLoggerBase,

  

Defines base logging classes used in the Lazarus IDE.

  AvgLvlTree,

  

An Average Level Tree structure, which is kept balanced so that finding a node is very rapid.

  StringHashList;

  

Implements a hashed list of string values.

Overview

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: Object
  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.