i18nTextCollector
class i18nTextCollector (View source)
SilverStripe-variant of the "gettext" tool: Parses the string content of all PHP-files and SilverStripe templates for occurrences 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/i18nTextCollectorTask Usage through URL (module-specific): http://localhost/dev/tasks/i18nTextCollectorTask/?module=mymodule Usage on CLI: sake dev/tasks/i18nTextCollectorTask Usage on CLI (module-specific): sake dev/tasks/i18nTextCollectorTask module=mymodule
Traits
A class that can be instantiated or replaced via DI
Constants
THEME_PREFIX |
|
Properties
string | $basePath | The directory base on which the collector should act. |
|
string | $baseSavePath | Save path |
Methods
An implementation of the factory method, allows you to create an instance of a class
Creates a class instance by the "singleton" design pattern.
No description
This is the main method to build the master string tables with the original strings. It will search for existent modules that use the i18n feature, parse the _t() calls and write the resultant files in the lang folder of each module.
Extract all strings from modules and return these grouped by module name
Extracts translatables from .php files.
Extracts translatables from .ss templates (Self referencing)
Allows classes which implement i18nEntityProvider to provide additional translation strings.
Extracts translations for ORM fields
No description
No description
No description
No description
Details
static Injectable
create(mixed ...$args)
An implementation of the factory method, allows you to create an instance of a class
This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.
This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();
static Injectable
singleton(string $class = null)
Creates a class instance by the "singleton" design pattern.
It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).
__construct($locale = null)
$this
setWriter(Writer $writer)
Assign a writer
Writer
getWriter()
Gets the currently assigned writer, or the default if none is specified.
Reader
getReader()
Get reader
$this
setReader(Reader $reader)
Set reader
run(array $restrictToModules = null, bool $mergeWithExisting = false)
This is the main method to build the master string tables with the original strings. It will search for existent modules that use the i18n feature, parse the _t() calls and write the resultant files in the lang folder of each module.
array
collect(array $restrictToModules = [], bool $mergeWithExisting = false)
Extract all strings from modules and return these grouped by module name
$this
write(Module $module, array $entities)
Write entities to a module
array
collectFromCode(string $content, string $fileName, Module $module)
Extracts translatables from .php files.
Note: Translations without default values are omitted.
array
collectFromTemplate(string $content, string $fileName, Module $module, array $parsedFiles = [])
Extracts translatables from .ss templates (Self referencing)
array
collectFromEntityProviders(string $filePath, Module $module = null)
Allows classes which implement i18nEntityProvider to provide additional translation strings.
Not all classes can be instantiated without mandatory arguments, so entity collection doesn't work for all SilverStripe classes currently
array
collectFromORM(string $filePath)
Extracts translations for ORM fields