* * *

Author Topic: Unclear howe to translate allpication  (Read 4632 times)

patyi

  • Full Member
  • ***
  • Posts: 127
Unclear howe to translate allpication
« on: July 29, 2013, 10:12:45 am »
Hi all !

The translation of lclstrconsts is seams to bee Ok, (the MessaheDlg buttons is translated) but rest of my allication Lazfont is not translated.
Po files (lazfont.hu.po, lazfont.rs.po, lclstrconsts.hu.po, lclstrconsts.rs.po) is in lazfont.lrs.

Below is the code, witch is separate unit, placed in uses section of main form, also main form has:

Initialization
  {$I lazfont.lrs}
  TranslateLCL('hu');
  TranslateApp('hu');

Pleas could somebody help mi, why is my application not translated ?
(the main language is Serbian I'd like to translate to Hungarian and back to Serbian on run time) 

I'm read and study all wiki pages and examples related with, but still confused, unclear how it's (should) work ...   :o
My environment is : Lazarus 1.1 svn, FPC 2.6.3 svn, XUbuntu 12.04 LTS 32bit


unit Translation;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Translations, LCLProc, LResources, Dialogs;

procedure TranslateLCL(lan: string);
procedure TranslateApp(lan: string);

implementation

resourcestring
  rsGreKaPrevodaPrograma = 'Greška prevoda programa na drugi jezik  !';

procedure TranslateLCL(lan: string);
var
  res : TLResource;
  pof : TPOFile;
  str : TStringStream;
begin
  res := LazarusResources.Find('lclstrconsts.'+lan,'PO');
  if res <> nil then begin
    str := nil;
    pof := nil;
    try
      str := TStringStream.Create(res.Value);
      pof := TPoFile.Create(str, False);
      try
        if not TranslateUnitResourceStrings('lclstrconsts', pof) then
          MessageDlg(rsGreKaPrevodaPrograma, mtError, [mbOk], 0);
      except
        MessageDlg(rsGreKaPrevodaPrograma, mtError, [mbOk], 0);
      end;
    finally
      if Assigned(str) then
        str.Free;
      if Assigned(pof) then
        pof.Free;
    end;
  end;
end;

procedure TranslateApp(lan: string);
var
  res : TLResource;
  pof : TPOFile;
  str : TStringStream;
begin
  res := LazarusResources.Find('Lazfont.'+lan,'PO');
  if res <> nil then begin
    str := nil;
    pof := nil;
    try
      str := TStringStream.Create(res.Value);
      pof := TPoFile.Create(str, False);
      try
        if not TranslateUnitResourceStrings('Lfont', pof) then
          MessageDlg(rsGreKaPrevodaPrograma, mtError, [mbOk], 0);
      except
        MessageDlg(rsGreKaPrevodaPrograma, mtError, [mbOk], 0);
      end;
    finally
      if Assigned(str) then
        str.Free;
      if Assigned(pof) then
        pof.Free;
    end;
  end;
end;

end.   

Blaazen

  • Hero Member
  • *****
  • Posts: 2370
  • POKE 54296,15
    • Eye-Candy Controls
Re: Unclear howe to translate allpication
« Reply #1 on: July 29, 2013, 01:02:25 pm »
I guess the code is taken from wiki, so in general it should work (it worked in my case).
1) I don't know if it is possible to translate at run-time, in my case I needed to restart application.
2) Try to check case-sensitivity, mabye 'hu' is different from 'HU'.
3) Take a quick look to *.lrs whether it is contains correct translations. (I created them using 'lazres').
Lazarus 1.9 r54600M FPC 3.0.2 x86_64-linux-qt Chakra, Qt 4.8.7, Plasma 5.9.4
Lazarus 1.6.4 r54278 FPC 3.0.2 i386-win32-win32/win64 Wine 2.4










Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Bart

  • Hero Member
  • *****
  • Posts: 2631
    • Bart en Mariska's Webstek
Re: Unclear howe to translate allpication
« Reply #2 on: July 29, 2013, 02:00:10 pm »
You can translate at runtime.
Mind you, that controls that are already created befoer invoking the translation will still have their original (untranslated) captions.

The call to TranslateApp is probably done after the creation of the forms he wants to translate.

@patyi: Did you check that any of the resource strings from "Lazfont" are translated after the call to TranslateApp?

A possible solution would be to have a UpdateCaptions (or similar) method on each form that uses the Lazfont resource strings.
After calling TranslateApp you should then call UpdateCaptions to update all captions to reflect the new content of the resourcestrings.

Bart

patyi

  • Full Member
  • ***
  • Posts: 127
Re: Unclear howe to translate allpication
« Reply #3 on: July 29, 2013, 02:46:53 pm »
Blazen,
Yes, I'm double check everything ...

Bart,
The strangest thing is that at start up of the program in initialization - the first call - of TranslateApp('hu') and TranslatLCL('hu') as initial
language, while the original language is Serbian, LCL is translated successfully but the captions off app is remains untranslated !
I cant get it translated what ever method is used (po files, mo files, po in resources ...), don't have any idea what to try more ...  :'(

Bart

  • Hero Member
  • *****
  • Posts: 2631
    • Bart en Mariska's Webstek
Re: Unclear howe to translate allpication
« Reply #4 on: July 29, 2013, 03:11:46 pm »
@patyi: you did not answer my question.
Say in Lazfont you  have resourcestring:

Code: [Select]
resourcestring
  rsHello = 'Hello';

In 'hu' po file it is translated to 'huHello';

Now after the call to TranslateApp('hu') do something like writeln('rsHello =',rsHello);
What is the output: 'Hello' or 'huHello' ?
If it still is 'Hello' then translations failed for some reason, and you'll have to debug further in the translations unit to see what happens.

Bart

patyi

  • Full Member
  • ***
  • Posts: 127
Re: Unclear howe to translate allpication
« Reply #5 on: July 29, 2013, 03:28:33 pm »
Bart,

Yes I have resourcestring and have translation in after calling TranslateApp('hu') !

The MessageDlg before exit from application is correctly translated, like this:

procedure TFLfont.MenuItem4Click(Sender: TObject);
begin
  TranslateApp('rs');
  TranslateLCL('rs');
end;

procedure TFLfont.MenuItem5Click(Sender: TObject);
begin
  TranslateApp('hu');
  TranslateLCL('hu');
end;   

I can switch between languages on run time there, MessageDlg is OK !

At start up can't get the translation ! Where to put TranslateApp('hu') procedure ? I trying this :

program Lazfont;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, Lfont, fontovi, printer4lazarus, zcomponent,
  Dialogs, Translation;

{$R *.res}

begin
  TranslateApp('hu');
  TranslateLCL('hu');

  Application.Title := 'Fontovi';
  Application.Initialize;
  Application.CreateForm(TFLfont, FLfont);
  Application.Run;
end.   

Unfortunately with no affect ... (original language - Serbian - is present)

patyi

  • Full Member
  • ***
  • Posts: 127
Re: Unclear howe to translate allpication
« Reply #6 on: July 29, 2013, 03:55:00 pm »
In attachment is my little application to see complete code ...

If the translations with PO files is working for everybody, except me then must bee a reason !
Acceptable solution is that the application load language at start up, and restart it if needed for other language ...

Thanks for Your help !

patyi

  • Full Member
  • ***
  • Posts: 127
Re: Unclear howe to translate allpication
« Reply #7 on: August 17, 2013, 04:16:46 pm »
Is somebody succeed with translation application written in Lazarus and FPC via PO files ?

if so, then please help to clarify that procedure, not just for me, but for others with same headache !
(I'm searching forums lot in this theme, finding that is confusing and many posters are lost ...)

Thanks, Patyi.   :D

Bart

  • Hero Member
  • *****
  • Posts: 2631
    • Bart en Mariska's Webstek
Re: Unclear howe to translate allpication
« Reply #8 on: August 17, 2013, 04:31:23 pm »
Is somebody succeed with translation application written in Lazarus and FPC via PO files ?

Lazarus IDE itself succeeded in doing it  >:D

Bart

avra

  • Hero Member
  • *****
  • Posts: 871
    • Additional info
Re: Unclear howe to translate allpication
« Reply #9 on: August 17, 2013, 07:00:34 pm »
At start up can't get the translation ! Where to put TranslateApp('hu') procedure ? I trying this :

SRB: Пробај да ставиш позиве за превођење после креирања форми.

ENG: Try to move translation calls after Application.CreateForm().
ct2laz - Easily convert components and projects between Lazarus and CodeTyphon

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus