Page 1 of 1

resourcestring -> the official solution

Posted: Thu Feb 17, 2011 4:40 pm
by Pumper
Hi there,

I've read through all of the topic of resourcestring. It seems to me that using resourcestring or const is not the best way. I have a project what I want to translate to several languages. At this time all of MessageDlg's strings are in one separate unit in resourcestring or const section. Several times those uses same strings. I've decided to take the effort and one time refactor all of the codes what are necessary.

So, here is my question:

What is the best/official way to store these strings of all MessageDlg?

Thank you

Regards,
Pumper

Posted: Mon Feb 21, 2011 11:39 am
by isiticov
Hello,

If you've meant to translate the text message displayed in MessageDlg() functions, then (if you consider to reduce the size of translations and easier manintainance of the code) I would suggest to create one common unit which will define all the strings used in the dialogs (this even could be a datamodule in order to simplify the translation), like:
var
sGlobalMsg1: string = 'Some message';
sGlobalMsg2: string = 'Another message';

Then translate this unit using TsiLang Expert and just refer to all these global strings from other units. This will centralize all these strings as well as will skip duplicates as the same string could be reused.

Hope this helps.

Posted: Tue Feb 22, 2011 11:11 am
by Pumper
Dear Isiticov,

Thank you for your help. I've tried to do as you described, but it seems something went wrong. Here is how my DM looks:

Code: Select all

unit Unit_Forditas;

interface

uses
  SysUtils, Classes, Unit_DM, siComp, siLngLnk;

type
  TForditas = class(TDataModule)
    siLangLinked: TsiLangLinked;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Forditas: TForditas;

// Általános stringek
  rsT1ReXIndulVarj: String = 'Kérem várjon, a rendszer indítása folyamatban van...';
  rsAdatbazis: String = 'Adatbázis';

...

//Form_Stat_SzamlaJegyzek
  rsFStat_SzamlaJegyzek_PDFFileNev: String = 'SzamlakJegyzeke';
  rsFStat_SzamlaJegyzek_PDFCim: String = 'Számlák jegyzéke';
  rsFStat_SzamlaJegyzek_DatumSzures: String = 'Dátum szűrés: ';

implementation

{$R *.dfm}

end.
Unfortunately when I open the Translation Editor I can't find these strings in General Translations. None of them. :(

Have I made something wrong? All of other forms are working properly.

Thank you.

Regards,
Pumper

Posted: Thu Feb 24, 2011 1:32 pm
by isiticov
Hello,

Source strings won't be picked up automatically into Tsilang. You will need to perform some additional steps.
Please use Tsilang Expert (Delphi menu Tools) and then in TsiLang Expert's menu please use File | Const section | With form.
This will scan the source of the unit and add the necessary code for translating the strings.
You can find detailed description of this in TsiLang Manual as well as at http://www.tsilang.com/press/en/how_to_ ... ation.html (Step 4).
Hope this helps.

Posted: Wed Mar 09, 2011 4:58 pm
by Pumper
Dear Igor,

Thank you for your answer. It is working as you described but I won't use because it makes me big mess in the source code.

I decided to use arrays in the string unit because it much cleaner. I have to change my source either ways. Like this:

Code: Select all

unit Unit_Forditas;

interface

const
  NySz = 2; // Number of translations


  rsT1ReXIndulVarj: array [1..NySz] of string = (
    'Kérem várjon, a rendszer indítása folyamatban van...',
    'Please wait the system is starting up...');

  rsAdatbazis: array [1..NySz] of string = (
    'Adatbázis',
    'Database');
...
And the changes in the code:

Code: Select all

if InputQuery(rsFReg_EmailCimModositas[siLangDispatcher.ActiveLanguage], rsFReg_EmailCimKerdes[siLangDispatcher.ActiveLanguage], S) then begin
...

Have a nice day