Forum > Translations

[solved] Button of dialog message in Spanish?

(1/1)

BlueIcaro:
Hello, when I use a dialog, the buttons are show in english, and my OS is in spanish.

--- Code: ---   MessageDlg('Caption','Mensaje en espaƱol',mtInformation,mbYesNoCancel,0);   
/[code]

How Can I fix it?,

See the image attached

Thanks

/BlueIcaro

--- End code ---

BlueIcaro:
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:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  Translations;...procedure TForm1.FormCreate(Sender: TObject);begin  TranslateUnitResourceStrings('LCLStrConsts', Application.Location + 'lclstrconsts.es.po');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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  LCLType, Translations, ...;...procedure TForm1.FormCreate(Sender: TObject);var  stream: TResourceStream;  tmpfile: String;begin  stream := TResourceStream.Create(HINSTANCE, 'LCLSTRCONSTS.ES', RT_RCDATA);  try    tmpFile := GetTempFileName;     stream.SaveToFile(tmpFile);    TranslateUnitResourceStrings('LCLStrConsts', tmpFile);    DeleteFile(tmpFile);  finally    stream.Free;  end;end;


BlueIcaro:
Thanks for the tip!
/BlueIcaro

Navigation

[0] Message Index

Go to full version