rainlab/translate-plugin

How to get the translated file from the Model

chaturadilan opened this issue · 4 comments

          Now I tested in Translate v2.2.7 and OctoberCMS v3.4.11, Now I'm not getting the translated attachment field at all

Originally posted by @chaturadilan in #722 (comment)

Hey @chaturadilan

Can you share some more detail, precisely how we reproduce it?

Hi

I have created a translatable file like following,

public $implement = [ \RainLab\Translate\Behaviors\TranslatableModel::class];

 public $translatable = ['image'];
 public $with = ['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

$model->lang('fr')

for translated model it does not return the attachment

Hey @chaturadilan

#722 has a working example of this. You can test this by installing the test plugin here:

https://github.com/octobercms/test-plugin

Navigate to "Pages" and upload a file to the "Photo" field.

I hope this helps.

the problem is in retrieving records

https://github.com/rainlab/location-plugin/blob/master/models/Country.php#L71

when we call directly using ->lists('name', 'id'); translation relation is not loaded.

but if you change this line from

return self::$nameList = self::isEnabled()
->orderBy('is_pinned', 'desc')->lists('name', 'id');
to

return self::$nameList = self::isEnabled()
->orderBy('is_pinned', 'desc')->get()->lists('name', 'id');
It load translation relations and works fine.

I suggest editing these lines in the plugin so we don't worry about update