Recent

Author Topic: Translation Component  (Read 6361 times)

qoxop

  • New Member
  • *
  • Posts: 33
Translation Component
« on: September 03, 2014, 12:38:51 pm »
Hello,
I just looked how to make multilanguage app. I found a translation example in lazarus distribution. I see there is a some drawback with need of manual edit the *.lfm file. Therefore I wrapped the funcionality from "localizedforms.pas" into the component.
- Just put into a form
- Enable i18n in project options
- Edit *.po files
- Call Localize method from component

I found interesting thing. The directory for languages has to be named languages - (in i18n project options).  Other names won't work. (at least for me.... lazarus 1.2.4 - Win7  ?)

And also I have  a question, if droped component on form can somehow modify project Options - Automatically enabling i18n. (To avoid manually enabling i18n in project options)

You can check it in attachment

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Translation Component
« Reply #1 on: September 03, 2014, 01:15:57 pm »
I found interesting thing. The directory for languages has to be named languages - (in i18n project options).  Other names won't work. (at least for me.... lazarus 1.2.4 - Win7  ?)
The details are here, near the end of the section. Respective source in lcl/defaulttranslator.pas, specifically in function GetLocaleFileName.

qoxop

  • New Member
  • *
  • Posts: 33
Re: Translation Component
« Reply #2 on: September 03, 2014, 01:59:33 pm »
ah, you are right. Look into the sources gives the right answer. My first impression was the directory name could be whatever. Because in project options you can type whatever you want.

wp

  • Hero Member
  • *****
  • Posts: 11922
Re: Translation Component
« Reply #3 on: September 03, 2014, 02:15:16 pm »
Nice idea to put that stuff into a component!

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Translation Component
« Reply #4 on: September 03, 2014, 05:40:12 pm »
ah, you are right. Look into the sources gives the right answer. My first impression was the directory name could be whatever. Because in project options you can type whatever you want.
Feel free to patch it. I guess the current implementation simply follows common pattern in GNU softwares.

qoxop

  • New Member
  • *
  • Posts: 33
Re: Translation Component
« Reply #5 on: September 04, 2014, 08:00:41 pm »
I can try to patch it. But what kind of patch do you mean?

1. Patch it in the IDE - Replace current edit box with ComboBox (with predefined  allowed dir names)

2. Or patch the DefaultTranslator to search also for dir names filled by user in Project options - I have no idea if it is possible - To read project options from code (?)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Translation Component
« Reply #6 on: September 05, 2014, 08:11:50 am »
you don't you pass the options to the worker function/class and let it do the rest eg add one parameter called langDirectories of type tstrings or tstringlist and make sure that every using it passes the correct data or nil to use the default only.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Translation Component
« Reply #7 on: September 05, 2014, 09:16:13 am »
I can try to patch it. But what kind of patch do you mean?

1. Patch it in the IDE - Replace current edit box with ComboBox (with predefined  allowed dir names)

2. Or patch the DefaultTranslator to search also for dir names filled by user in Project options - I have no idea if it is possible - To read project options from code (?)
2.

qoxop

  • New Member
  • *
  • Posts: 33
Re: Translation Component
« Reply #8 on: September 08, 2014, 01:05:34 pm »
I created a patch for DefaultTranslator, because of problem above. (Directory name for *.po cannot be arbitrary). I added overloaded procedure SetDefaultLang
Code: [Select]
procedure SetDefaultLang(LangDirectory: string; Lang: string); overload;  Attached an old and a new DefaultTranslator.pas with diff file
I don't know where to post it, so if someone find it usefull, he can make a patch on svn :)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Translation Component
« Reply #9 on: September 08, 2014, 01:18:57 pm »
To get patches into FPC/Lazarus sources, please open an issue on the bugtracker and upload the patch against trunk FPC/Lazarus.

http://wiki.lazarus.freepascal.org/Creating_A_Patch

Thanks.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

qoxop

  • New Member
  • *
  • Posts: 33
Re: Translation Component
« Reply #10 on: September 08, 2014, 01:40:18 pm »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Translation Component
« Reply #11 on: September 08, 2014, 01:43:55 pm »
Thanks. FYI if you provide the .diff file (and you should unless it's a .po translation file you're updating), please don't/there's no need to provide the old and new pas files.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018