Ga naar inhoud

TP2WScraper

TP2WScraper extracts all strings that are a candidate for getting translated from your project.

How does this thing work?

  1. Open a (TMS Web Core) project
  2. Drop a TP2WScraper instance on your main form
  3. Run your project in the IDE (F9)
  4. Click on the button labelled Extract
  5. A dialog appears, asking you for a filename
  6. A file (with every string that is a candidate for getting translated) is getting saved in your Downloads directory.
  7. Delete the TP2WScraper instance from your main form (optional)

Note: TP2WScraper will scrape ALL strings in your project, even those that aren't in your main form but in other forms/units.

What is getting scraped?

  1. resourcestrings
  2. HTML elements with innerText, for example:
    <a id="myId">dit is de text</a>
    
  3. HTML elements with a data-translate attribute, for example:
    <input id="myId" placeholder="doorzoek assortiment" data-translate="placeholder" type="text" />
    

How do I scrape other HTML documents that aren't necessarily associated with a unit?

You can create an event handler for TP2WScraper.OnBeforeScrapeComplete:

function TForm1.P2WScraper1BeforeScrapeComplete(Sender: TObject): TJSPromise;
begin
  Result := P2WScraper1.Scrape('Template', 'Template.html');
end;

Where Template is the scope (probably the name of your HTML document without the extension) and Template.html is the filename of your HTML document relative to your project's Output directory (probably TMSWeb/Debug or TMSWeb/Release).

Great! But what can I do with the generated file?

  • The file is compatible with gettext, an internationalization and localization (i18n and l10n) standard for writing multilingual programs.
  • The file can get uploaded to crowdin.com where translators can translate it for you, or you can open the file with a PO editor, for example Poedit.
  • You can read a translated file back into TP2WTranslator and have it translate your project at runtime (yes, you can change the language at runtime)