Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

ModelAdmin and Tabs translation in French (or another language)


Reply


3 Posts   1549 Views

Avatar
Myrdhin

Community Member, 67 Posts

15 January 2010 at 3:49am

Edited: 15/01/2010 3:50am

(With SilverStripe v2.3.4)

I used ModelAdmin class to create a configuration interface but i would like to translate ModelAdmin Titles tab in french.

For example, i have 3 classes : Period, Level and Topic.
I used ModelAdmin like this :

class ConfigurationAdmin extends ModelAdmin {
static $url_segment = 'configuration';

static $managed_models = array(
'Period',
'Level',
'Topic'
);
}

But titles tabs were in English : "Period", "Level" and "Topic". I would like to have "Période", "Niveau" and Thème" titles. I had lang/fr_FR.php with good entries...

In the cms/code/ModelAdmin.php, function getModelForms(), line 200, i saw this :

'Title' => singleton($modelClass)->singular_name(),

I could modify this line :

'Title' => singleton($modelClass)->i18n_singular_name(),

But i don't want to modify cms PHP files.

So i create a mysite/code/ModifiedModelAdmin.php like this :

class ModifiedModelAdmin extends ModelAdmin {

protected function getModelForms() {
$forms = parent::getModelForms();
$formsItemsIterator = $forms->getIterator();

foreach($formsItemsIterator as $arrayDataObj) {
$arrayDataObj->setField('Title', singleton($arrayDataObj->getField('ClassName'))->i18n_singular_name());
}

return $forms;
}
}

And i modified my ConfigurationAdmin class like this :

class ConfigurationAdmin extends ModifiedModelAdmin {
static $url_segment = 'configuration';

static $managed_models = array(
'Period',
'Level',
'Topic'
);

}

And it works.
Hope it helps somebody :)

Avatar
Ingo

Forum Moderator, 801 Posts

25 January 2010 at 12:21pm

That was actually fixed a while ago, see http://open.silverstripe.org/changeset/85279
Should be in 2.4 beta soon :)

Avatar
Myrdhin

Community Member, 67 Posts

29 January 2010 at 10:11pm

Oki, Thanks :)