A VERY small and LOW LEVEL example. It uses only GetText unit, you must convert the resulting .rst to .po with rstconv, then copy it for each language_country you would like to support (e.g en_US, in_ID). Name them as translatetest.<language_country>.po After that use msgfmt to convert those .po to .mo. Done. Change your system language and your app will follow.
program translatetest;
{$mode objfpc}{$H+}
uses
GetText;
resourcestring
MyText = 'Hello';
var
MOF: TMOFile;
Lang,DefLang: String;
begin
GetLanguageIDs(Lang,DefLang);
MOF := TMOFile.Create('translatetest.' + Lang + '.mo');
WriteLn(Lang + ': ' + MOF.Translate('Hello'));
MOF.Free;
end.
To use .po instead of .mo, you could add Translations unit to the uses clause, replace TMOFile with TPOFile, and add 2nd argument to Translate method, which is the original string (MyText in program above).
Now for the high level example (much easier, of course
):
program translatetest;
{$mode objfpc}{$H+}
uses
GetText,Translations;
resourcestring
MyText = 'Hello';
var
Lang,DefLang: String;
r: TTranslateUnitResult;
begin
GetLanguageIDs(Lang,DefLang);
TranslateUnitResourceStrings('translatetest','translatetest.%s.po',Lang,DefLang);
WriteLn(MyText);
end.
It uses .po files, but this time all resource strings in the unit (or program) would be translated, and you can use the symbol declared in resourcestring section. You may either have language_country or simply language .po file.