Telegram_2023-10-02T15

<< Click to Display Table of Contents >>

Navigation:  Telegram > 2023 > 10 > 02 >

Telegram_2023-10-02T15

Telegram link

 

2023-10-02T15:01:08

 

usually the translation tools take the resource strings contained within the EXE and create one or more files containing translations of it that are loaded at runtime.

 

In the case of a server, you need to have a per-session language/translation. Resource strings are global and can't be used otherwise all sessions will receive the same language.

 

Anything that is not in templates need to be changed via code. I would create a translation file for each supported language, load it at runtime when session is created.

 

The UserSession.Clipboard object can be handy to store this. Let's say you need to support English and Italian languages, right? And you have an error message that needs to be translated, something like \An error occurred\.

 

So you have a file named lang-en.dat (English) like this:

 

ERROR_OCCURRED=An error occurred

 

and another file named lang-it.dat (Italian) like this:

 

ERROR_OCCURRED=Si è verificato un errore

 

When session is created and a language is selected you load the specific language file into UserSession.Clipboard, like this:

 

var

 

i: Integer;

 

clipboard: TIWClipboard;

 

list: TStringList;

 

begin

 

list := TStringList.Create;

 

try

 

list.LoadFromFile('lang-' + language_code + '.dat');

 

clibboard := UserSession.Clipboard;

 

for i := 0 to list.Count - 1 do

 

clipboard.put(list.Names[i], list.ValueByIndex[i]);

 

finally

 

list.Free;

 

end;

 

end;

 

now you have all localized strings into your UserSession.Clipboard.

 

Now you can access them as:

 

var

 

s: string;

 

begin

 

s := UserSession.Clipboard['ERROR_OCCURRED'].S; (S property = AsString)

 

raise Exception.Create(s); // <- the user will receive an error message in his own language

 


 

Telegram link

 

2023-10-02T15:07:28

 

another option is to use the actual string in the default language as the

 

ame\ (or ID) of the string.

 

Then in your italian file you would have:

 

An error occurred=Si è verificato un errore

 

Then in your code you have a function that takes the original in English and looks for the translation (using the same clipboard strategy).

 

in your code you would have something like:

 

raise Exception.Create(Translate(('An error occurred'));