Ga naar inhoud

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?

  1. Open a (TMS Web Core) project
  2. Drop TP2WTranslator on your base form (if you are using form inheritance, otherwise on every form you want translated)
  3. Run your project (F9)
  4. Let's assume for a moment your web browser’s locale is set to de (aka Germany)
  5. TP2WTranslator will look for a file named locale/de/LC_MESSAGES/default.po relative to your Output directory.
  6. 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...

  1. have a TP2WTranslator component on it’s form, or
  2. 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.