Lazarus
Miscellaneous => Translations => Topic started by: patyi 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.
-
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').
-
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
-
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 ... :'(
-
@patyi: you did not answer my question.
Say in Lazfont you have resourcestring:
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
-
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)
-
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 !
-
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
-
Is somebody succeed with translation application written in Lazarus and FPC via PO files ?
Lazarus IDE itself succeeded in doing it >:D
Bart
-
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().