\TextCollector
SilverStripe-variant of the "gettext" tool: Parses the string content of all PHP-files and SilverStripe templates for ocurrences of the _t() translation method. Also uses the {@link i18nEntityProvider} interface to get dynamically defined entities by executing the {@link provideI18nEntities()} method on all implementors of this interface.
Collects all found entities (and their natural language text for the default locale)
into language-files for each module in an array notation. Creates or overwrites these files,
e.g. framework/lang/en.yml.
The collector needs to be run whenever you make new translatable
entities available. Please don't alter the arrays in language tables manually.
Usage through URL: http://localhost/dev/tasks/TextCollectorTask
Usage through URL (module-specific): http://localhost/dev/tasks/TextCollectorTask/?module=mymodule
Usage on CLI: sake dev/tasks/TextCollectorTask
Usage on CLI (module-specific): sake dev/tasks/TextCollectorTask module=mymodule
- Author: Bernat Foj Capell <bernat@silverstripe.com>
Synopsis
class TextCollector
extends Object
{
- // members
- protected $defaultLocale;
- public $basePath;
- public $baseSavePath;
- protected TextCollector_Writer $writer;
- // methods
- public void __construct()
- public void setWriter()
- public void getWriter()
- public void run()
- public void collect()
- public void write()
- protected array processModule()
- public array collectFromCode()
- public array collectFromTemplate()
- public void collectFromEntityProviders()
- protected string|boolean normalizeEntity()
- protected array getFilesRecursive()
- public void getDefaultLocale()
- public void setDefaultLocale()
Hierarchy
Extends
- Object
Tasks
Line | Task |
---|---|
+ | Fully support changing of basePath through {@link SSViewer} and {@link ManifestBuilder} |
213+ | Why the type juggling for $this->collectFromBlah()? They always return arrays. |
340+ | Why the type juggling for $this->collectFromTemplate()? It always returns an array. |
Members
Methods
protected
- getFilesRecursive() — Helper function that searches for potential files (templates and code) to be parsed
- normalizeEntity() — Normalizes enitities with namespaces.
- processModule() — Builds a master string table from php and .ss template files for the module passed as the $module param
public
- __construct()
- collect()
- collectFromCode() — Extracts translatables from .php files.
- collectFromEntityProviders()
- collectFromTemplate() — Extracts translatables from .ss templates (Self referencing)
- getDefaultLocale()
- getWriter()
- run() — This is the main method to build the master string tables with the original strings.
- setDefaultLocale()
- setWriter()
- write()