[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,

  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.

This file 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 GetLanguageIDs function of the gettext unit in the project lpr file:

uses
      ...
      Translations, LCLProc;

    procedure TranslateLCL;
    var
      PODirectory, Lang, FallbackLang: String;
    begin
      PODirectory := '/path/to/lazarus/lcl/languages/';
      Lang := '';
      FallbackLang:='';
      LCLGetLanguageIDs(Lang, FallbackLang); // in unit LCLProc
      Translations.TranslateUnitResourceStrings('LCLStrConsts',
        PODirectory+'lclstrconsts.%s.po', Lang, FallbackLang);
    end;

    begin
      TranslateLCL;
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.

Note for Mac OS X:

The supported language IDs should be added into the application bundle property list to CFBundleLocalizations key, see lazarus.app/Contents/Info.plist for an example.