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
TP2WTranslatoron 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) TP2WTranslatorwill look for a file namedlocale/de/LC_MESSAGES/default.porelative to your Output directory.- Assuming a file named
locale/de/LC_MESSAGES/default.poexists, 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
TP2WTranslatorcomponent on it’s form, or - include
pas2web.translatorwith 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.