Recent

Author Topic: [SOLVED] How to to use po. files to translate aplication!?  (Read 9351 times)

nicke85

  • Jr. Member
  • **
  • Posts: 92
  • #13#10
[SOLVED] How to to use po. files to translate aplication!?
« on: June 06, 2011, 10:56:23 am »
I need to translate Dialogs buttons caption from english to my native language.
And want to use po file from lcl\languages.After read many post on forum and reading wiki i can't find solution how to use it in my aplication.
If somebody have a little demo aplication which use po and i18n please to post..
or some peace of code..to know what to do and how po files can be used!?
any language can help me to see method of implementation..:)
« Last Edit: June 08, 2011, 01:57:42 pm by nicke85 »
ArchLinux X64 (XFCE) & Windows 7 SP1 Ultimate X64
FPC 2.7.1 / Lazarus 1.1 / ZeosDBO / fortes4lazarus -- all svn

eMarc

  • New Member
  • *
  • Posts: 35
Re: How to to use po. files to translate aplication!?
« Reply #1 on: June 06, 2011, 12:36:22 pm »
Hi.

You can use GNU Gettext for Delphi

http://dxgettext.po.dk/

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to to use po. files to translate aplication!?
« Reply #2 on: June 06, 2011, 03:04:58 pm »
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.
Code: Delphi  [Select][+][-]
  1. program translatetest;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   GetText;
  7.  
  8. resourcestring
  9.   MyText = 'Hello';
  10.  
  11. var
  12.   MOF: TMOFile;
  13.   Lang,DefLang: String;
  14. begin
  15.   GetLanguageIDs(Lang,DefLang);
  16.   MOF := TMOFile.Create('translatetest.' + Lang + '.mo');
  17.   WriteLn(Lang + ': ' + MOF.Translate('Hello'));
  18.   MOF.Free;
  19. end.
  20.  
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 :)):
Code: Delphi  [Select][+][-]
  1. program translatetest;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   GetText,Translations;
  7.  
  8. resourcestring
  9.   MyText = 'Hello';
  10.  
  11. var
  12.   Lang,DefLang: String;
  13.   r: TTranslateUnitResult;
  14. begin
  15.   GetLanguageIDs(Lang,DefLang);
  16.   TranslateUnitResourceStrings('translatetest','translatetest.%s.po',Lang,DefLang);
  17.   WriteLn(MyText);
  18. end.
  19.  
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.
« Last Edit: June 06, 2011, 03:47:25 pm by Leledumbo »

nicke85

  • Jr. Member
  • **
  • Posts: 92
  • #13#10
Re: How to to use po. files to translate aplication!?
« Reply #3 on: June 07, 2011, 09:01:09 am »
Thanx eMarc for link nice app..:)
Thanx Leledumbo for post..I have understood the point to translate resource strings in console aplication and gui application and for what is po used..but how it can be used to translate MessageDlg Buttons Caption eg. to be (Yes --> Da) and (No --> Ne)
I need app with one button which will call MessageDlg to see how it work..thanx for advice :)
ArchLinux X64 (XFCE) & Windows 7 SP1 Ultimate X64
FPC 2.7.1 / Lazarus 1.1 / ZeosDBO / fortes4lazarus -- all svn

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to to use po. files to translate aplication!?
« Reply #4 on: June 07, 2011, 06:02:22 pm »
Quote
but how it can be used to translate MessageDlg Buttons Caption eg. to be (Yes --> Da) and (No --> Ne)
Simple:
Code: [Select]
TranslateUnitResourceStrings('LCLStrConsts',<path to languages folder> + 'lclstrconsts.%s.po',Lang,DefLang);
The other parts of the code is the same as I posted before. You can also bring out the .po files anywhere you like an refer them there.

eMarc

  • New Member
  • *
  • Posts: 35
Re: How to to use po. files to translate aplication!?
« Reply #5 on: June 07, 2011, 09:19:42 pm »
Thanx eMarc for link nice app..:)

You are welcome.  :)

This is not an App, this is an Object Pascal unit to dinamically translate your application using .po files.

Leledumbo has showed you a sample code to use this unit into your application.

PS : Additionally, in the link you will found several command line utilities to compile/decompile .po files, extract strings to translate from your application source code, etc. ...

Regards.

nicke85

  • Jr. Member
  • **
  • Posts: 92
  • #13#10
Re: How to to use po. files to translate aplication!?
« Reply #6 on: June 08, 2011, 12:27:19 pm »
Finally work thank you guys for sugestions :)
 
ArchLinux X64 (XFCE) & Windows 7 SP1 Ultimate X64
FPC 2.7.1 / Lazarus 1.1 / ZeosDBO / fortes4lazarus -- all svn

 

TinyPortal © 2005-2018