TP2WTranslator
TP2WTranslator is TP2WScraper's brother. Where TP2WScraper extracts all strings from your project, TP2WTranslator reads them back in and translates your project at runtime.
How does this thing work?
- Open a (TMS Web Core) project
- Drop
TP2WTranslator
on your base form (if you are using form inheritance, otherwise on every form you want translated) - Run your project (F9)
- Let's assume for a moment your web browser’s locale is set to
de
(aka Germany) TP2WTranslator
will look for a file namedlocale/de/LC_MESSAGES/default.po
relative to your Output directory.- Assuming a file named
locale/de/LC_MESSAGES/default.po
exists, your project will get translated at runtime.
Alternatively, you yourself can set the language (without depending on your web browser's locale) via property Translator.Language
. This property allows for you to change the language and switch from one language to another at runtime.
Important note: every unit that wants to get translated MUST...
- have a
TP2WTranslator
component on it’s form, or - include
pas2web.translator
with it’s uses clause, example:
uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls,
pas2web.translator; // MUST be after WEBLib.Forms
Alternatively, you can have your forms descend from your own custom TWebForm, and include TP2WTranslator
or pas2web.translator
with your base class.