Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to translate extended plugin fields #656

Closed
mskraban opened this issue Sep 20, 2021 · 1 comment
Closed

Unable to translate extended plugin fields #656

mskraban opened this issue Sep 20, 2021 · 1 comment

Comments

@mskraban
Copy link

I'm trying use translate plugin with my extended plugin fields. I tried to use translatable in model where it usually works when it's not extended and in controller (Plugin.php).

Model.php

    public $implement = ['@RainLab.Translate.Behaviors.TranslatableModel'];
    public $translatable = ['specs','featured_specs','features', 'fullspecs', 'optional_equipment', 'condition'];

Plugin.php

        ProductModel::extend(function($model) {
            $model->addJsonable([
                'featured_specs',
                'features',
                'specs',
            ]);

            $model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel';
            $model->translatable = ['specs','featured_specs','features', 'fullspecs', 'optional_equipment', 'condition'];

        });
@daftspunk
Copy link
Member

Hi @mskraban,

This looks good and should work. If you are having trouble, try to reproduce any problems using the test plugin so we can also test it.

One thing to check, if the translatable property is not available in the model, you may need to dynamically add it with code like this

ProductModel::extend(function($model) {
    if (!$model->propertyExists('translatable')) {
        $model->addDynamicProperty('translatable', []);
    }
    if (!$model->isClassExtendedWith('RainLab\Translate\Behaviors\TranslatableModel')) {
        $model->extendClassWith('RainLab\Translate\Behaviors\TranslatableModel');
    }
    $model->translatable = array_merge($model->translatable, ['title', 'description', 'meta_title', 'meta_description']);
});

I hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants