How to get the translated file from the Model
chaturadilan opened this issue · 3 comments
chaturadilan commented
Hi
I have created a translatable file like following,
public $implement = [ \RainLab\Translate\Behaviors\TranslatableModel::class];
public $translatable = ['image'];
public $attachOne = [
'image' => \System\Models\File::class,
];
I was able to add translated files using the Admin Backend, and I both see it in system_files.
But when I try to access the model like below, it always returns the file that is set for 'en' but nor 'fr'
$model->lang('fr')
daftspunk commented
Hey @chaturadilan
This will be fixed in Translate v2.2.6 / October CMS v3.4.11
Test plugin results:
> $a = October\Test\Models\Page::find(1);
= October\Test\Models\Page {#6468
id: 1,
title: "First Page",
}
> $a->secondimage;
= System\Models\File {#6480
id: 600,
disk_name: "64bf1a0eb1bab468315357.png",
file_name: "george.png",
file_size: 432616,
content_type: "image/png",
title: null,
description: null,
field: "secondimage",
#attachment_id: 1,
#attachment_type: "October\Test\Models\Page:en",
#is_public: 1,
sort_order: 600,
created_at: "2023-07-25 00:40:46",
updated_at: "2023-07-25 00:40:48",
+path: "http://localhost/storage/app/uploads/public/64b/f1a/0eb/64bf1a0eb1bab468315357.png",
+extension: "png",
}
> $a->lang('fr')->secondimage;
= System\Models\File {#6508
id: 601,
disk_name: "64bf1a1bd17be083766484.jpg",
file_name: "poker.jpg",
file_size: 133984,
content_type: "image/jpeg",
title: null,
description: null,
field: "secondimage",
#attachment_id: 1,
#attachment_type: "October\Test\Models\Page:fr",
#is_public: 1,
sort_order: 601,
created_at: "2023-07-25 00:40:59",
updated_at: "2023-07-25 00:41:00",
+path: "http://localhost/storage/app/uploads/public/64b/f1a/1bd/64bf1a1bd17be083766484.jpg",
+extension: "jpg",
}
chaturadilan commented
Thank you
chaturadilan commented
Now I tested in Translate v2.2.7 and OctoberCMS v3.4.11, Now I'm not getting the translated attachment field at all