Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

GNU-gettext-MO-File-Reader

This class provides limited functions to read GNU MO binary files including plural forms. NOT IMPLEMENTED: contexts, domains, automatic translations files lookup

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

GNU gettext MO File Reader

This class provides limited functions to read GNU MO binary files including plural forms. NOT IMPLEMENTED: contexts, domains, automatic translations files lookup

delphi
var
  _: TGetTextProc;
  mo: TGNUMOFileReader;
begin
  mo := TGNUMOFileReader.Create('translations\de\messages.mo');

  try

    mo.Parse;
    _ := mo.Get_gettext;
    __ := mo.Get_ngettext;

    ShowMessageFmt(_('Welcome %s'), ['Luke']);
    // or
    // ShowMessageFmt(mo['Welcome %s'], ['Luke']);
    // or
    // ShowMessageFmt(mo.GetText('Welcome %s'), ['Luke']);

    ShowMessageFmt(__('You have %d new message', 'You have %d new messages', 2), [2]);
    // or
    // ShowMessageFmt(mo.Plurals['You have %d new message', 'You have %d new messages', 2], [2]);
    // or
    // ShowMessageFmt(mo.NGetText('You have %d new message', 'You have %d new messages', 2), [2]);

  finally
    mo.Free;
  end;

Sample PO file can be taken here. Use msgfmt de.po to create binary mo file.