This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

stephenlch11122433
stephenlch11122433

Hi fellows, I am building a website that has two languages (Simplified Chinese and English), where I created some plugins to input datas from backends. And I would like to use Translate plugin for the locale feature. However, I followed the steps from the documentation and input the codes into myPlugin.php in myPlugin model directory as below:

public $implement = ['@RainLab.Translate.Behaviors.TranslatableModel'];
public $translatable = ['title'];

Both with and without @ before RainLab. So then I try to click on the backend menu of myPlugin and click create expecting that I can input for other language but seems to have nothing changed.

Am I expecting the wrong thing? (Because I see there should be a little letters shorthand of the language (e.g. EN) to click to choose the language you want to input.) Is there anything that I did wrongly? If thats the case, what should be the steps to take in order to allow me to choose the language to input from the backend?

ev.werkz
ev.werkz

same problem by User Plugin. I added custom fields and added to boot function

$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel'; $model->translatable = ['about', 'preview_text'];

fields not translated on backend. :(

office32100
office32100

Having the same issue - Any solution?

ev.werkz
office32100
office32100

ev.werkz said:

office32100 said:

Having the same issue - Any solution?

Yes, look there: https://stackoverflow.com/questions/58641718/how-i-can-on-october-cms-use-translate-plugin-after-extend-new-fields-to-user-pl

Hi, thanks for your fast reply. I'm trying to extend the SEO Manager plugin model behavior.

Where have you added the following code? \Event::listen('backend.form.extendFieldsBefore', function($widget) {
// You should always check to see if you're extending correct model if (!$widget->model instanceof \RainLab\User\Models\User) { return; }

// we will merge current fields with fields we want to add
// we used shorthand + plus operator for this
$widget->tabs['fields'] = $widget->tabs['fields'] + Config::get('rms.secis::user_fields');

// here Config::get('rms.secis::user_fields') is just returning field array
// Fo ref. Ex: 
// return [
//     'gender' => [
//         'label'   => 'Gender',
//         'tab'     => 'Security Island',
//         'type'    => 'radio',
//         'options' => [
//             'male'   => 'Male',
//             'female' => 'Female'
//         ],
//         'span'    => 'auto'
//     ],
// ];

});

ev.werkz
ev.werkz

office32100 said:

you add the code on your plugin "public function boot()" function. this is example of my code:

// Add fields to controller
Event::listen('backend.form.extendFieldsBefore', function($widget) {
    if (!$widget->model instanceof \RainLab\User\Models\User) {
        return;
    }
    $widget->tabs['fields'] = $widget->tabs['fields'] + Config::get('rms.secis::user_fields');
 });

if (class_exists("\RainLab\User\Models\User")) {
    // add to model class
    \RainLab\User\Models\User::extend(function ($model) {
        $model->bindEvent('model.saveInternal', function() use($model) {
            $model->purgeAttributes('translatable');
        });

        $model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel';
        $model->addDynamicProperty('translatable', ['about', 'preview_text']);
    });
}

Last updated

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.