Recent

Author Topic: Translating again...  (Read 4012 times)

dietmar

  • Full Member
  • ***
  • Posts: 170
Translating again...
« on: August 01, 2017, 07:50:36 pm »
Hi,

http://wiki.freepascal.org/Step-by-step_instructions_for_creating_multi-language_applications

does not cover how to translate MessageDlg or others.
Does anyone know how to translate the message and the buttion captions?

Thx,
Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Translating again...
« Reply #1 on: August 01, 2017, 08:04:17 pm »
« Last Edit: August 01, 2017, 08:09:02 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

wp

  • Hero Member
  • *****
  • Posts: 12366
Re: Translating again...
« Reply #2 on: August 01, 2017, 08:49:43 pm »
You must copy the translations of lclstrconsts.po (in (lazarus)/lcl/languages) to the languages folder of your project. And you must be sure that the strings in unit lclstrconsts are translated - this happens automatically if unit LCLTranslator is in the uses clause of the project.

For a test, try the demo in (lazarus)/examples/translation. Copy the lclstrconsts.*.po from lcl/languages to examples/translation/languages. Compile, run and click on the "What did you select" button which opens a message box.

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: Translating again...
« Reply #3 on: August 01, 2017, 09:04:25 pm »
Thx for the quick help!

Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: Translating again...
« Reply #4 on: August 01, 2017, 09:21:15 pm »
Hmmm...

do I have to merge the lclstrconsts.*.po into my app.*.po?

And how do I translate the "free text" in the message dialog, like "Do you want to quit?" or whatever?

Sorry if I bother you,
Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

wp

  • Hero Member
  • *****
  • Posts: 12366
Re: Translating again...
« Reply #5 on: August 01, 2017, 09:54:26 pm »
No problem. I would not recommend to merge individual po files into a common po file because it is more difficult to maintain the new file. So, just copy lclstrconsts*.po into the folder which contains your project language files app.*.po. Note also that there may be other packages which have their own translation files. If you use TAChart, for example, you should know that it has its own translations in the folder (lazarus)/components/tachart/languages - you should copy its tachartstrconsts.*.po in the same way as you did with lclstrconsts. etc. And in the routine which switches the language for you you must manually trigger translation of the strings by calling one of the TranslateUnitResourcestrings procedures in unit Translations.

The "free text", I suppose, is the text that is displayed in the messagebox? Standard messages such as "The file does not exist" (or similar) are already translated. Look in unit lclstrconsts (or corresponding other language unit) and find the name of the resource string constant which you can use in your application. In above-mentioned example you would find the resource string rsfdFileNotExist = 'The file "%s" does not exist.' - the "%s" tells you that you must pass the filename in a Format instruction:

Code: Pascal  [Select][+][-]
  1. uses
  2.   lclstrconsts;
  3.  
  4. procedure OpenFile(AFileName: String);
  5. begin
  6.   if not FileExists(AFileName) then begin
  7.     MessageDlg(Format(rsfdFileNotExist, [AFileName], mtError, [mbOK], 0);
  8.     exit;
  9.   end;
  10.   ...

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: Translating again...
« Reply #6 on: August 02, 2017, 08:38:29 pm »
Hm... whether I copy all the lclstrconsts.*.po files to the example/language directory or not, it does not change anything when I click the mentioned button. It just displays "None selected" in the chosen language.

What should change when I add the lclstrconsts files?

Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

wp

  • Hero Member
  • *****
  • Posts: 12366
Re: Translating again...
« Reply #7 on: August 02, 2017, 10:05:44 pm »
No idea what you are doing wrong here. I just repeated my test with Laz 1.6.4/fpc3.02 (the version of your signature, 32-bit and 64-bit) where the lclstrconsts never had been in the translations directory. I copied the files to this folder, compiled the demo project, selected a non-English language, and the messagedlg was in the translated language.

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Translating again...
« Reply #8 on: August 03, 2017, 01:37:42 am »
IMHO the .po files are for editing, to make the executeble use them they have to be compiled to .mo files. Did you compile all .po files to .mo ?
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: Translating again...
« Reply #9 on: August 03, 2017, 10:47:04 am »
I don't think the .mo files are necessary.

@wp: The MessageDlg in my example is translated correct, although I don't have the lclstrconsts.* installed... so it looks the same behaviour.

Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

 

TinyPortal © 2005-2018