Hi,
In my backend, i have a plugin which displays a list of products.
Those products can have a translated content into the creation form in other languages.
I would like to display in my backend list both languages.
I'm using a Partial column type but when i get back my datas, they are always in french, and even if i dump the $record to see the model used. It's not showing me the translation. Only translable fields.
Is there a way to retrieve all translation in a partial ?
thanks for your help
Yes, sure. Let's say you have a model like this:
use Model;
use RainLab\Translate\Behaviors\TranslatableModel;
class Item extends Model
{
public $implement = [TranslatableModel::class];
public $translatable = ['name'];
public $table = 'demo_demo_items';
// this gets the name in english
public function getNameEnAttribute()
{
return $this->noFallbackLocale()->lang('en')->name;
}
// this gets the name in french
public function getNameFrAttribute()
{
return $this->noFallbackLocale()->lang('fr')->name;
}
}
and in your columns.yaml
columns:
id:
label: ID
type: number
name:
label: name
type: text
sortable: true
name_en:
label: name (en)
type: text
sortable: false
name_fr:
label: name (fr)
type: text
sortable: false
note: you don't need to call noFallbackLocale() but if you don't, it'll fall back and display your default language which is usually not what you want in a list view.
hope this helps.
Thanks for the response @munxar :)
Thanks a lot @munxar :)
Most helpful comment
Yes, sure. Let's say you have a model like this:
and in your columns.yaml
note: you don't need to call
noFallbackLocale()but if you don't, it'll fall back and display your default language which is usually not what you want in a list view.hope this helps.