#1 2014-03-14 10:48:33

tech
Member
Registered: 2014-01-13
Posts: 107

can't localize and i18n my app

Hi,

First I've extracted all ressources and the .messages file was created then I've created a new file myapp.FR with some strings translation and set the language to FR

procedure TMainForm.FormShow(Sender: TObject);
begin
{$ifdef EXTRACTALLRESOURCES}
  ExtractAllResources(
    // first, all enumerations to be translated
    [TypeInfo(TFileEvent),TypeInfo(TFileAction){,TypeInfo(TPreviewAction)}],
    // then some class instances (including the TSQLModel will handle all TSQLRecord)
    [globalClient.Model],
    // some custom classes or captions
    [],[]);
  Close;
{$else}
  i18nLanguageToRegistry(lngFrench);
{$endif}

  Ribbon.ToolBar.ActivePageIndex := 0;
  i18nDateText := Iso2S;
end;

When I launch the project, the UI still not localized neither translated into french !

Offline

#2 2014-03-14 13:31:20

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: can't localize and i18n my app

See what is written at the beginning of the mORMoti18n.pas unit:

Two way of use:

  1. manual translation of every form
  + can change languages on the fly (no need to restart app)
  - must modify code
  . use SetCurrentLanguage() to set Language object and Delphi locale settings
  . add FormTranslate([MainForm, FormTwo, FormAbout]) in TMainForm.FormShow
      -> this forms will be translated again by any SetCurrentLanguage() call
      warning: none of this form must be free after it - use FormTranslateOne()
  . temporary forms must call FormTranslateOne(self) in their FormShow event

  2. TCustomForm.OnCreate hook
  + no code modification
  - can't change languages on the fly (need to restart app) and the language
    must be set in registry (because must be available before any form is
    created)
  . just define USEFORMCREATEHOOK
  . autocall FormTranslateOne() just before an OnCreate handler would be called
  . translate also TFrame
  . initialization.LangInit will call SetCurrentLanguage() once at startup:
      RegisterIO.Reg: CreateKey('User prefs') + WriteString('Language','FR')
      no Reg specified -> will use Win32 user locale

Just pickup one of the two possibilities.

Offline

#3 2014-03-14 14:30:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: can't localize and i18n my app

I've just updated the documentation (SAD 1.18 pdf), to be more precise about this point:

mORMot documentation wrote:



Language selection

User Interface language can be specified at execution.

There are two ways to change the application language:
- Manual translation of every form;
- Hook of the common TForm / TFrame classes, for automatic translation.

In manual translation mode:
- You can change languages on the fly, i.e. no need to restart the application;
- But you must modify your code to explicitly translate the forms after their creation;
- And you won't be able to translate dialogs without sources (e.g. third-party dialogs).

TForm/TFrame hook, on its side, has the following behavior:
- You do not need to modify your code, since it will be global to the application;
- It will work also for any third-party dialog, even if you do not have the source of it;
- But you can't change the language on the fly: you need to restart the application.


Manual transaction

Once for the application, you should call SetCurrentLanguage() to set the global Language object and all related Delphi locale settings.

The, in each OnShow event of any form, you should call FormTranslateOne() e.g.

procedure TMyForm.FormShow(Sender: TObject);
begin
  Language.FormTranslateOne(self);
end;

Another possibility may be to translate all already allocated forms at once, e.g. in the OnShow event of the application's main form:

Language.FormTranslate([MainForm, FormTwo, FormAbout]);

Note that a list of already translated forms is maintained by the unit, when you call FormTranslate().
Therefore:
- All specified forms will be translated again by any further SetCurrentLanguage() call;
- But none of these forms must be freed after a FormTranslate([]) call - use FormTranslateOne() instead to translate a given form once, e.g. for all temporary created forms.


TForm / TFrame hook

If the USEFORMCREATEHOOK conditional is defined, the mORMoti18n.pas unit will hook TCustomForm.OnCreate method to translate all its nested components. It will also intercept TCustomFrame.Create() to allow automatic translation of its content.

Since the language must be known at program startup, before any TForm is actually created, the language will be set in the Operating System registry. The HKEY_CURRENT_USERSoftwareCompanyName]i18n key should contain one value per application (i.e. the lowercase .exe file name without its path), which will identify the abbreviation of the expected language. If there is no entry in this registration key for the given application, the current Windows local will be used.

For instance, if you define USEFORMCREATEHOOK conditional for your project, and run at least e.g. once in !TMainForm.FormShow!LibMainDemoFileMain.pas, for the framework main demo:

i18nLanguageToRegistry(lngFrench);

.. then it will set the main application language as French. At next startup, the unit will search for a FR.msg file, which will be used to translate all screen layout, including all RTTI-generated captions.

Of course, for a final application, you'll need to change the language by a common setting. See i18nAddLanguageItems, i18nAddLanguageMenu and i18nAddLanguageCombo functions and procedures to create your own language selection dialog, using a menu or a combo box, for instance.

Offline

#4 2014-03-14 16:19:27

tech
Member
Registered: 2014-01-13
Posts: 107

Re: can't localize and i18n my app

Hi AB,

I used the USEFORMCREATEHOOK and it works but there is one issue with french è, é, à ....
e.i: Société is written like that: http://105.157.31.10:8888/mormot.png

Offline

#5 2014-03-14 16:22:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: can't localize and i18n my app

Your text file must be either:
- In WinAnsi / 1252 code page:
- UTF-8 encoded with BOM.

Offline

#6 2014-03-14 16:53:11

tech
Member
Registered: 2014-01-13
Posts: 107

Re: can't localize and i18n my app

Great I've convert the file into ANSI and it works fine now.

There's somethings that doesn't work. The resourcestrings was not extracted into .messages !

Last edited by tech (2014-03-14 17:10:48)

Offline

#7 2014-03-14 18:02:23

tech
Member
Registered: 2014-01-13
Posts: 107

Re: can't localize and i18n my app

After i18n i got a stackoverflow when :

StrToFloat(table.GetS(X, 1))

The field 1 on the table is a double.
Which conversion function we must use without i18n ?

Offline

#8 2014-03-15 15:24:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: can't localize and i18n my app

About resourcestrings, we just identified and fixed an issue with EXTRACTALLRESOURCES process for multi-platform Delphi versions.
See http://synopse.info/fossil/info/814b361fa0

About your issue with StrToFloat()..
I don't know what's up there...
In all cases, StrToFloat() is IMHO not the good function to provide a shortstring content (as GetS() does). You are forcing an unneeded conversion.
I've just added TSQLTable.GetAsFloat() and GetAsCurrency() methods, which may help.
See http://synopse.info/fossil/info/abc7498a3a

Offline

Board footer

Powered by FluxBB