[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'Translations' (#lazutils)

Reference for unit 'Translations'

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

uses

  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,

  

Routines for managing UTF-8-encoded strings.

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

Version 4.0 Generated 2025-05-03 Home