Version: current

# Class i18nTextCollector

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 `i18nEntityProvider` interface to get dynamically defined entities by executing the 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. sapphire/lang/en_US.php.

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/i18nTextCollectorTast 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

Requires PHP 5.1+ due to class_implements() limitations

  Object
  i18nTextCollector

Package: sapphire\i18n
Author: Bernat Foj Capell <bernat@silverstripe.com>
Author: Ingo Schommer <FIRSTNAME@silverstripe.com>
Uses: ``i18nEntityProvider``
Uses: ``i18n``
Located at sapphire/core/i18nTextCollector.php

## Methods summary

`public` | # `__construct( mixed $locale = null )` #### Parameters $locale $locale #### Overrides `Object::__construct`
`public` | # `run( array $restrictToModules = null )` 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. 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. #### Parameters $restrictToModules array $restrictToModules #### Uses DataObject->collectI18nStatics()
`protected` | # `processModule( string $module )` Build the module's master string table Build the module's master string table #### Parameters $module string $module Module's name
`public` | # `collectFromCode( mixed $content, mixed $module )`
`public` | # `collectFromTemplate( mixed $content, mixed $module, mixed $fileName )`
`public` | # `collectFromEntityProviders( mixed $filePath )` #### Uses ``i18nEntityProvider`` #### Used by ``i18nEntityProvider``
`protected` | # `entitySpecFromRegexMatches( mixed $regs, mixed $_namespace = null )`
`public` | # `langArrayCodeForEntitySpec( string $entityFullName, mixed $entitySpec )` Input for langArrayCodeForEntitySpec() should be suitable for insertion into single-quoted strings, so needs to be escaped already. Input for langArrayCodeForEntitySpec() should be suitable for insertion into single-quoted strings, so needs to be escaped already. #### Parameters $entityFullName string $entity The entity name, e.g. CMSMain.BUTTONSAVE $entitySpec
`protected` | # `writeMasterStringFile( mixed $entitiesByModule )` Write the master string table of every processed module Write the master string table of every processed module
`protected` | # `getFilesRecursive( string $folder, array & $fileList = null )` Helper function that searches for potential files to be parsed Helper function that searches for potential files to be parsed #### Parameters $folder string $folder base directory to scan (will scan recursively) $fileList array $fileList Array where potential files will be added to
`public` | # `getDefaultLocale( )`
`public` | # `setDefaultLocale( mixed $locale )`

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `create()`, `createMethod()`, `create_from_string()`, `defineMethods()`, `exists()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Magic methods summary

## Properties summary

`protected mixed` | $defaultLocale | #
`public string` | $basePath | # $basePath The directory base on which the collector should act. Usually the webroot set through `Director::baseFolder()`. $basePath The directory base on which the collector should act. Usually the webroot set through `Director::baseFolder()`.
`public string` | $baseSavePath | # $basePath The directory base on which the collector should create new lang folders and files. Usually the webroot set through `Director::baseFolder()`. Can be overwritten for testing or export purposes. $basePath The directory base on which the collector should create new lang folders and files. Usually the webroot set through `Director::baseFolder()`. Can be overwritten for testing or export purposes.

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -