OctoberCMS translate YAML default texts

371 Views Asked by At

As an example I have a translatable model:

class Settings extends Model {
    public $implement = [
        'System.Behaviors.SettingsModel',
        'RainLab.Translate.Behaviors.TranslatableModel'
    ];

    public $settingsCode = 'zollerboy_customtheme_settings';
    public $settingsFields = 'fields.yaml';

    public $translatable = [
        'site_name',
        //I have a lot more here
    ];
}

My fields.yaml looks like this:

tabs:
    fields:
        site_name:
            tab: Info
            label: Website Name
            type: text

        # And so on ...

Is it possible, that I give the field site_name a default value for each language?

I tried it with

default: name.plugin::lang.settings.default.site_name

but that seems to just work with labels but not with default values.

1

There are 1 best solutions below

4
On

Yes, the default option does not work with translations, but you can display this field through of the widget form, getting the default value in the visualization method.

public function render() {
    $value= Lang::get('name.plugin::lang.settings.default.site_name');
    return $this->makePartial('site_name', ['value' => $value, 'name' => 
    'site_name']);
}

Register form widgets by overriding the registerFormWidgets method inside the Plugin registration class.

public function registerFormWidgets() {
    return [
          'Name\Plugin\FormWidgets\SiteName' => 'site_name'

    ];
}

Example fields.yaml:

tabs:
fields:
    site_name:
        tab: Info
        label: Website Name
        type: site_name

    # And so on ...