ENHANCEMENT Added support for specifying target module in i18nEntitityProvider->provideEntities()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@68156 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-12-10 07:07:16 +00:00 committed by Sam Minnee
parent 98c00440ad
commit 3f189f3950
2 changed files with 28 additions and 1 deletions

View File

@ -44,6 +44,23 @@ interface i18nEntityProvider {
*
* Example usage in {@link DataObject->provideI18nEntities()}.
*
* You can ask textcollector to add the provided entity to a different module
* than the class is contained in by adding a 4th argument to the array:
* <code>
* class MyTestClass implements i18nEntityProvider {
* function provideI18nEntities() {
* $entities = array();
* $entities["MyOtherModuleClass.MYENTITY"] = array(
* $value,
* PR_MEDIUM,
* 'My context description',
* 'myothermodule'
* );
* }
* return $entities;
* }
* </code>
*
* @return array All entites in an associative array, with
* entity name as the key, and a numerical array of pseudo-arguments
* for _t() as a value.

View File

@ -84,6 +84,16 @@ class i18nTextCollector extends Object {
// we store the master string tables
$entitiesByModule[$module] = $this->processModule($module);
// extract all entities for "foreign" modules (fourth argument)
foreach($entitiesByModule[$module] as $fullName => $spec) {
if(isset($spec[3]) && $spec[3] != $module) {
$othermodule = $spec[3];
if(!isset($entitiesByModule[$othermodule])) $entitiesByModule[$othermodule] = array();
unset($spec[3]);
$entitiesByModule[$othermodule][$fullName] = $spec;
}
}
}
// Write the generated master string tables
@ -202,7 +212,7 @@ class i18nTextCollector extends Object {
if(class_exists($class) && in_array('i18nEntityProvider', class_implements($class))) {
$reflectionClass = new ReflectionClass($class);
if($reflectionClass->isAbstract()) continue;
$obj = singleton($class);
$entitiesArr = array_merge($entitiesArr,(array)$obj->provideI18nEntities());
}