rainlab / translate-plugin

Enables multi-lingual sites
Other
125 stars 88 forks source link

Translations of Setting model fields are not working in the update. #445

Closed hellomohsinhello closed 5 years ago

hellomohsinhello commented 5 years ago
Translations of Setting model fields are not working in the update.
The lang change button is working and saving translation but not output correct lang text.
//here is my model
<?php namespace Ibox\Services\Models;
use Model;
class Settings extends Model
{
    public $implement = ['@RainLab.Translate.Behaviors.TranslatableModel','System.Behaviors.SettingsModel'];
    public $translatable = [  'gm_message'  ];
    public $settingsCode = 'ibox_asas_settings';
    public $settingsFields = 'fields.yaml';
    public function initSettingsData()
    {
        $this->facebook = true;
    }
}

//page.htm
function onStart(){
   $this['gm_message'] = Settings::get('gm_message');
}
==
{{ gm_message|raw }} // here the translations should be output but no.
mjauvin commented 5 years ago

You are right, this is using the System.Behaviors.SettingsModel which is not currently translatable.

mjauvin commented 5 years ago

In the mean time, remove the TranslatableModel from your implements[] array and use Rainlab's "Translate Messages" with the twig "_" filter in your markup: {{ gmmessage | }}

hellomohsinhello commented 5 years ago

Thanks for your comment. Now I have two questions in my mind.

  1. translation of System.Behaviors.SettingsModel was supported in the previous versions. So, why you removed in the newer version.
  2. {{ gmmessage | }} is working but I need to have richeditor for gmmessage. so, richeditor will not available using | option. How I could resolve this issue.
hellomohsinhello commented 5 years ago

We ware making this setting option for our client where they dont understand the markup ".md" or using content file option in CMS menu. This option was easy for them to make changing in content using rich text editor.

hellomohsinhello commented 5 years ago

let me show you an example here. I copied this code from plugin GrofGraf\ContactMe which is working fine. I same when i'm doing in my model is not works.

class Settings extends Model
{
    use \October\Rain\Database\Traits\Validation;

    public $implement = [
      'System.Behaviors.SettingsModel',
      '@RainLab.Translate.Behaviors.TranslatableModel'
    ];
    public $translatable = [
      'name_label',
      'email_label',
      'attachment_label',
      'message_content',
      'message_label',
      'button_text',
      'captcha_label',
      'confirmation_message',
      'auto_reply_subject',
      'auto_reply_content',
      'maillist_subscribe_label'
    ];

    // A unique code
    public $settingsCode = 'contact_me_settings';

    // Reference to field configuration
    public $settingsFields = 'fields.yaml';
}
mjauvin commented 5 years ago

We did not remove any functionality.

You're saying it's working fine in the GrofGraf\ContactMe plugin with the latest version of Rainlab.Translate?

mjauvin commented 5 years ago

I was able to make this work. In your case, your onStart() method should look like below:

function onStart(){
   $this['gm_message'] = Settings::instance()->gm_message;
}
mjauvin commented 5 years ago

This can be closed as invalid as well.