mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Reverted auto-detection of i18n statics like $db in DataObject through provideI18nEntities() - was getting too complicated with decorated properties. Overload DataObject->fieldLabels() or DataObjectDecorator->updateFieldLabels() instead
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@65071 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
30f8c74283
commit
eb4c950655
@ -2543,6 +2543,7 @@ class DataObject extends ViewableData implements DataObjectInterface,i18nEntityP
|
|||||||
}
|
}
|
||||||
|
|
||||||
$labels = array_merge((array)$autoLabels, (array)$customLabels);
|
$labels = array_merge((array)$autoLabels, (array)$customLabels);
|
||||||
|
|
||||||
$this->extend('updateFieldLabels', $labels);
|
$this->extend('updateFieldLabels', $labels);
|
||||||
|
|
||||||
return $labels;
|
return $labels;
|
||||||
@ -2832,33 +2833,6 @@ class DataObject extends ViewableData implements DataObjectInterface,i18nEntityP
|
|||||||
public function provideI18nEntities() {
|
public function provideI18nEntities() {
|
||||||
$entities = array();
|
$entities = array();
|
||||||
|
|
||||||
$db = eval("return {$this->class}::\$db;");
|
|
||||||
if($db) foreach($db as $name => $type) {
|
|
||||||
$entities["{$this->class}.db_{$name}"] = array(
|
|
||||||
$name,
|
|
||||||
PR_MEDIUM,
|
|
||||||
'Name of the object property, mainly used for automatically generating forms'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$has_many = eval("return {$this->class}::\$has_many;");
|
|
||||||
if($has_many) foreach($has_many as $name => $class) {
|
|
||||||
$entities["{$this->class}.has_many_{$name}"] = array(
|
|
||||||
$name,
|
|
||||||
PR_MEDIUM,
|
|
||||||
'Name of an object relation, mainly used for automatically generating forms'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$many_many = eval("return {$this->class}::\$many_many;");
|
|
||||||
if($many_many) foreach($many_many as $name => $class) {
|
|
||||||
$entities["{$this->class}.many_many_{$name}"] = array(
|
|
||||||
$name,
|
|
||||||
PR_MEDIUM,
|
|
||||||
'Name of an object relation, mainly used for automatically generating forms'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$entities["{$this->class}.SINGULARNAME"] = array(
|
$entities["{$this->class}.SINGULARNAME"] = array(
|
||||||
$this->singular_name(),
|
$this->singular_name(),
|
||||||
PR_MEDIUM,
|
PR_MEDIUM,
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage model
|
* @subpackage model
|
||||||
*/
|
*/
|
||||||
abstract class DataObjectDecorator extends Extension implements i18nEntityProvider {
|
abstract class DataObjectDecorator extends Extension {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statics on a {@link DataObject} subclass
|
* Statics on a {@link DataObject} subclass
|
||||||
@ -163,21 +163,6 @@ abstract class DataObjectDecorator extends Extension implements i18nEntityProvid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function provideI18nEntities() {
|
|
||||||
$entities = array();
|
|
||||||
$fields = $this->extraStatics();
|
|
||||||
$translatableAttributes = array('db','has_one','has_many','many_many');
|
|
||||||
if($fields) foreach($fields as $att => $spec) {
|
|
||||||
if(!in_array($att, $translatableAttributes)) continue;
|
|
||||||
|
|
||||||
if($spec) foreach($spec as $name => $type) {
|
|
||||||
$entities["{$this->class}.{$att}_{$name}"] = array($name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $entities;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -16,36 +16,15 @@ class i18nTest extends SapphireTest {
|
|||||||
i18n::set_locale('de_DE');
|
i18n::set_locale('de_DE');
|
||||||
$obj = new i18nTest_DataObject();
|
$obj = new i18nTest_DataObject();
|
||||||
|
|
||||||
$lang['en_US']['i18nTest_DataObject']['db_MyProperty'] = 'MyProperty';
|
$lang['en_US']['i18nTest_DataObject']['MyProperty'] = 'MyProperty';
|
||||||
$lang['de_DE']['i18nTest_DataObject']['db_MyProperty'] = 'Mein Attribut';
|
$lang['de_DE']['i18nTest_DataObject']['MyProperty'] = 'Mein Attribut';
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$obj->fieldLabel('MyProperty'),
|
$obj->fieldLabel('MyProperty'),
|
||||||
'Mein Attribut'
|
'Mein Attribut'
|
||||||
);
|
);
|
||||||
|
|
||||||
$lang['en_US']['i18nTest_DataObject']['has_one_HasOneRelation'] = 'HasOneRelation';
|
$lang['en_US']['i18nTest_DataObject']['MyUntranslatedProperty'] = 'MyUntranslatedProperty';
|
||||||
$lang['de_DE']['i18nTest_DataObject']['has_one_HasOneRelation'] = 'Eins zu eins';
|
|
||||||
$this->assertEquals(
|
|
||||||
$obj->fieldLabel('HasOneRelation'),
|
|
||||||
'Eins zu eins'
|
|
||||||
);
|
|
||||||
|
|
||||||
$lang['en_US']['i18nTest_DataObject']['has_many_HasManyRelation'] = 'HasManyRelation';
|
|
||||||
$lang['de_DE']['i18nTest_DataObject']['has_many_HasManyRelation'] = 'Viel zu eins';
|
|
||||||
$this->assertEquals(
|
|
||||||
$obj->fieldLabel('HasManyRelation'),
|
|
||||||
'Viel zu eins'
|
|
||||||
);
|
|
||||||
|
|
||||||
$lang['en_US']['i18nTest_DataObject']['many_many_ManyManyRelation'] = 'ManyManyRelation';
|
|
||||||
$lang['de_DE']['i18nTest_DataObject']['many_many_ManyManyRelation'] = 'Viel zu viel';
|
|
||||||
$this->assertEquals(
|
|
||||||
$obj->fieldLabel('ManyManyRelation'),
|
|
||||||
'Viel zu viel'
|
|
||||||
);
|
|
||||||
|
|
||||||
$lang['en_US']['i18nTest_DataObject']['db_MyUntranslatedProperty'] = 'MyUntranslatedProperty';
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$obj->fieldLabel('MyUntranslatedProperty'),
|
$obj->fieldLabel('MyUntranslatedProperty'),
|
||||||
'My Untranslated Property'
|
'My Untranslated Property'
|
||||||
@ -106,6 +85,13 @@ class i18nTest_DataObject extends DataObject implements TestOnly {
|
|||||||
'ManyManyRelation' => 'Member'
|
'ManyManyRelation' => 'Member'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function fieldLabels() {
|
||||||
|
$labels = parent::fieldLabels();
|
||||||
|
$labels['MyProperty'] = _t('i18nTest_DataObject.MyProperty', 'My Property');
|
||||||
|
|
||||||
|
return $labels;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class i18nTest_Object extends Object implements TestOnly, i18nEntityProvider {
|
class i18nTest_Object extends Object implements TestOnly, i18nEntityProvider {
|
||||||
|
@ -380,10 +380,6 @@ PHP;
|
|||||||
"\$lang['en_US']['i18nTestModule']['WITHNAMESPACE'] = 'Include Entity with Namespace';",
|
"\$lang['en_US']['i18nTestModule']['WITHNAMESPACE'] = 'Include Entity with Namespace';",
|
||||||
$moduleLangFileContent
|
$moduleLangFileContent
|
||||||
);
|
);
|
||||||
$this->assertContains(
|
|
||||||
"\$lang['en_US']['i18nTestModule']['db_MyField']",
|
|
||||||
$moduleLangFileContent
|
|
||||||
);
|
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
"\$lang['en_US']['i18nTestModuleInclude.ss']['NONAMESPACE'] = 'Include Entity without Namespace';",
|
"\$lang['en_US']['i18nTestModuleInclude.ss']['NONAMESPACE'] = 'Include Entity without Namespace';",
|
||||||
$moduleLangFileContent
|
$moduleLangFileContent
|
||||||
@ -416,77 +412,13 @@ PHP;
|
|||||||
array(
|
array(
|
||||||
'i18nTextCollectorTestMyObject.PLURALNAME',
|
'i18nTextCollectorTestMyObject.PLURALNAME',
|
||||||
'i18nTextCollectorTestMyObject.SINGULARNAME',
|
'i18nTextCollectorTestMyObject.SINGULARNAME',
|
||||||
'i18nTextCollectorTestMyObject.db_FirstProperty',
|
|
||||||
'i18nTextCollectorTestMyObject.db_SecondProperty',
|
|
||||||
'i18nTextCollectorTestMyObject.has_many_Relation',
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
|
||||||
'FirstProperty',
|
|
||||||
$matches['i18nTextCollectorTestMyObject.db_FirstProperty'][0]
|
|
||||||
);
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'My Object',
|
'My Object',
|
||||||
$matches['i18nTextCollectorTestMyObject.SINGULARNAME'][0]
|
$matches['i18nTextCollectorTestMyObject.SINGULARNAME'][0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testCollectFromEntityProvidersInCustomSubClass() {
|
|
||||||
$c = new i18nTextCollector();
|
|
||||||
|
|
||||||
$filePath = Director::baseFolder() . '/sapphire/tests/i18n/i18nTextCollectorTestMySubObject.php';
|
|
||||||
$matches = $c->collectFromEntityProviders($filePath);
|
|
||||||
$this->assertEquals(
|
|
||||||
array_keys($matches),
|
|
||||||
array(
|
|
||||||
'i18nTextCollectorTestMySubObject.PLURALNAME',
|
|
||||||
'i18nTextCollectorTestMySubObject.SINGULARNAME',
|
|
||||||
'i18nTextCollectorTestMySubObject.db_SubProperty',
|
|
||||||
'i18nTextCollectorTestMySubObject.has_many_SubRelation',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->assertEquals(
|
|
||||||
'SubProperty',
|
|
||||||
$matches['i18nTextCollectorTestMySubObject.db_SubProperty'][0]
|
|
||||||
);
|
|
||||||
$this->assertEquals(
|
|
||||||
'My Sub Object',
|
|
||||||
$matches['i18nTextCollectorTestMySubObject.SINGULARNAME'][0]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCollectDecoratedFields() {
|
|
||||||
$c = new i18nTextCollector();
|
|
||||||
$c->basePath = $this->alternateBasePath;
|
|
||||||
$c->baseSavePath = $this->alternateBaseSavePath;
|
|
||||||
$c->run();
|
|
||||||
|
|
||||||
$moduleLangFile = "{$this->alternateBaseSavePath}/i18ntestmodule/lang/" . $c->getDefaultLocale() . '.php';
|
|
||||||
$moduleLangFileContent = file_get_contents($moduleLangFile);
|
|
||||||
$this->assertNotContains(
|
|
||||||
"\$lang['en_US']['i18nTestModuleDecorator']['db_MyExtraField'] = 'MyExtraField';",
|
|
||||||
$moduleLangFileContent,
|
|
||||||
'Decorated fields are not stored in the module of the decorated file if the decorator is located in another module'
|
|
||||||
);
|
|
||||||
$this->assertNotContains(
|
|
||||||
"\$lang['en_US']['i18nTestModuleDecorator']['has_one_Page'] = 'Page';",
|
|
||||||
$moduleLangFileContent,
|
|
||||||
'Decorated fields are not stored in the module of the decorated file if the decorator is located in another module'
|
|
||||||
);
|
|
||||||
|
|
||||||
$otherModuleLangFile = "{$this->alternateBaseSavePath}/i18nothermodule/lang/" . $c->getDefaultLocale() . '.php';
|
|
||||||
$otherModuleLangFileContent = file_get_contents($otherModuleLangFile);
|
|
||||||
$this->assertContains(
|
|
||||||
"\$lang['en_US']['i18nTestModuleDecorator']['db_MyExtraField'] = 'MyExtraField';",
|
|
||||||
$otherModuleLangFileContent,
|
|
||||||
'Decorated fields are stored in the module in which the decorator is placed'
|
|
||||||
);
|
|
||||||
$this->assertContains(
|
|
||||||
"\$lang['en_US']['i18nTestModuleDecorator']['has_one_Page'] = 'Page';",
|
|
||||||
$otherModuleLangFileContent,
|
|
||||||
'Decorated fields are stored in the module in which the decorator is placed'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -15,6 +15,5 @@ class i18nTextCollectorTestMySubObject extends i18nTextCollectorTestMyObject imp
|
|||||||
static $singular_name = "My Sub Object";
|
static $singular_name = "My Sub Object";
|
||||||
|
|
||||||
static $plural_name = "My Sub Objects";
|
static $plural_name = "My Sub Objects";
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
x
Reference in New Issue
Block a user