Can somebody remove spammer batpurev...
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
- Previous 10 entries
- 1
- Page 22(current)
A note to self (as I have tried to Google this before, and now I did it again, and most definitively will do it again):
For some reason SilverStripe does not look for field translations in the lang files automatically. Or if it does, I don't know how I should define the fields in the language files so that SilverStripe would find them. I'm using SilverStripe 3.6.1.
Anyway, here is a workaround. Put this to any class inherited from DataObject:
public function fieldLabel($name)
{
$label = parent::fieldLabel($name);
$label = _t($this->class.'.'.$name, $label); //Try to translate the field
return $label;
}
And then you can translate your fields in your mysite/lang/en.yml (or whatever language file):
en:
Title: MyTitle
AnotherField: AnotherTranslation
Please do note that the fieldnames are case sensitive, so "Title", "AnotherField" or whatever you have must be written as-is. Also remember to run ?flush=all after editing your language file.
EDIT:
It seems that my workaround does not translate summary fields. But I found this:
http://www.balbuss.com/translating-statics-fields-and-labels/#TranslatingFieldlabels
class MyExample extends DataObject implements i18nEntityProvider {
static $db = array(
'Name' => 'Varchar',
...
);
function fieldLabels($includerelations = true) {
$labels = parent::fieldLabels($includerelations);
// add a translation to the $labels array for each db field
// if $includerelations == true (and it normally is) you need to add
// the db_ prefix, cause that's what SS will look for
foreach($this->stat('db') as $key => $value) {
$labels[$key] = _t("MyExample.db_{$key}", $key);
}
return $labels;
}
- Previous 10 entries
- 1
- Page 22(current)