Recent

Author Topic: [solved] Button of dialog message in Spanish?  (Read 363 times)

BlueIcaro

  • Hero Member
  • *****
  • Posts: 716
    • My github
[solved] Button of dialog message in Spanish?
« on: May 23, 2022, 01:32:56 pm »
Hello, when I use a dialog, the buttons are show in english, and my OS is in spanish.
Code: [Select]
   MessageDlg('Caption','Mensaje en español',mtInformation,mbYesNoCancel,0);   
/[code]

How Can I fix it?,

See the image attached

Thanks

/BlueIcaro
« Last Edit: May 23, 2022, 01:50:47 pm by BlueIcaro »

BlueIcaro

  • Hero Member
  • *****
  • Posts: 716
    • My github
Re: Button of dialog message in Spanish?
« Reply #1 on: May 23, 2022, 01:50:36 pm »
Hi, I found the solution by my self.
Reading the wiki https://wiki.lazarus.freepascal.org/Step-by-step_instructions_for_creating_multi-language_applications
I put the file lclstrconsts.es.po into the folder or my application. And I add DefaultTranslator unit to my proyect, and know its works.

/BlueIcaro

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: [solved] Button of dialog message in Spanish?
« Reply #2 on: May 23, 2022, 03:08:24 pm »
When you only want the strings defined by the LCL in your local language, but do not intend any further translations, maybe the LCLTranslator/DefaultTranslator machinery is a bit too much. The following solutions have less overhead:
  • Copy the file lclstrconsts.es.po from its location in the Lazarus installation (lcl/translations) to the output directory of your project (this is the directory in which the binary exists).
  • Add unit "translations" to the uses clause of your main form.
  • Write a handler for the main form's OnCreate event which translates the lcl language file:
Code: Pascal  [Select][+][-]
  1. uses
  2.   Translations;
  3. ...
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. begin
  6.   TranslateUnitResourceStrings('LCLStrConsts', Application.Location + 'lclstrconsts.es.po');
  7. end;

If you do not want to distribute an additional file along with your application you can pack the language file into its resources:
  • Copy the lclstrconsts.es.po from (lazarus)/lcl/translations to the source directory of your project.
  • Open the project options > Resources. Click "Add" and add the lclstrconsts.es.po from its new location.
  • In your main form, add the units "Translations" and "LCLType" to the uses clause.
  • Add the following code to the OnCreate handler of the main form:
Code: Pascal  [Select][+][-]
  1. uses
  2.   LCLType, Translations, ...;
  3. ...
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. var
  6.   stream: TResourceStream;
  7.   tmpfile: String;
  8. begin
  9.   stream := TResourceStream.Create(HINSTANCE, 'LCLSTRCONSTS.ES', RT_RCDATA);
  10.   try
  11.     tmpFile := GetTempFileName;
  12.     stream.SaveToFile(tmpFile);
  13.     TranslateUnitResourceStrings('LCLStrConsts', tmpFile);
  14.     DeleteFile(tmpFile);
  15.   finally
  16.     stream.Free;
  17.   end;
  18. end;




BlueIcaro

  • Hero Member
  • *****
  • Posts: 716
    • My github
Re: [solved] Button of dialog message in Spanish?
« Reply #3 on: May 23, 2022, 05:13:15 pm »
Thanks for the tip!
/BlueIcaro

 

TinyPortal © 2005-2018