* * *

Author Topic: Switching languages in multi-language application  (Read 668 times)

maurobio

  • New member
  • *
  • Posts: 15
Switching languages in multi-language application
« on: August 05, 2017, 01:04:19 am »
Dear ALL,

Hi. I have written a multi-language application following the directions provided in the excellent tutorial Step-by-step instructions for creating multi-language applications (http://wiki.freepascal.org/Step-by-step_instructions_for_creating_multi-language_applications).

I have added a menu option "Languages" with two items which allow to change the interface language between English (the default) and Brazilian Portuguese. I created a .po file for each language (myapplication.en.po and myapplication.pt-br.po), jusing Poedit to translate the strings.

When I start my application, the interface is displayed in English. Choosing the "Portuguese" option in the Language menu, it immediately switches to that language. However, if I want to switch back to English, using the "English" option in the Language menu, nothing happens (that is, the interface does not switch back to English).

My Language menu  options are implemented just as recommended in the above cited tutorial:

Code: Pascal  [Select]
  1. procedure TMainForm.MEnglishlanguageClick(Sender: TObject);
  2. begin
  3.   SetDefaultLang('en');
  4. end;  
  5.  
  6. procedure TMainForm.MPortugueseLanguageClick(Sender: TObject);
  7. begin
  8.   SetDefaultLang('pt-br');
  9. end;

Any hints?

Thanks in advance for any assistance you can provide.

Best regards,

lainz

  • Hero Member
  • *****
  • Posts: 2087
Re: Switching languages in multi-language application
« Reply #1 on: August 05, 2017, 02:22:54 am »
That happened before, if I remember well, you need to create a separate .po file for the english language, not the default .po that's in english, another one.

See this project and how it manages translations, that project fixed that bug If I remember, that was discussed in this forum also in the Online Package Manager thread.

http://wiki.freepascal.org/OPM_External_Update_json_Editor

As you can see here:
https://svn.code.sf.net/p/lazarus-ccr/svn/applications/json_packager/locale/

There is a separate english po file.

Another way is change the language, and prompt the user to restart the application to change it.

maurobio

  • New member
  • *
  • Posts: 15
Re: Switching languages in multi-language application
« Reply #2 on: August 06, 2017, 04:41:15 pm »
Dear lainz, Member Hero!

Thank you very much for your reply. I will try your suggestion. I will also take a close look at the jsonpackager application you pointed out, as it has a number of interesting features which I suppose can be useful in my own applications.

Best regards,

kupferstecher

  • Full Member
  • ***
  • Posts: 142
Re: Switching languages in multi-language application
« Reply #3 on: August 06, 2017, 05:55:02 pm »
You already have a ".en.po" file, but did you also "translate" all terms? Means original and English is the same. In POEDIT Ctrl+B copies the original to the translation.

Regards

maurobio

  • New member
  • *
  • Posts: 15
Re: Switching languages in multi-language application
« Reply #4 on: August 13, 2017, 02:45:22 pm »
Dear  kupferstecher,

Yes, that's the trick (which unfortunately the otherwise nice tutorial on creating multilanguage applications in Lazarus does not mention)! I was not 'translating' the en.po file as you suggested.

Now everything works very well!  :D

Thank you very much!

 

Recent

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