You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think that it would be good (and coherent with how this plugin works) to have a fallback value for translated attachements, so the default language file is shown if no translations are uploaded.
The text was updated successfully, but these errors were encountered:
I agree with this. Technically it is very difficult to implement: the relation uses a key that includes the locale in it. This means the SQL engine is responsible for the fallback logic and this is where the difficulty arises.
edit:
After giving this some thought, we could introduce a second _fallback relation
The above would generate two relations called photo and photo_fallback, this should make it possible to check for a translated value explicitly and then use the fallback, if required.
public $translatable = ['title', 'image_ml_relation'];
public $attachOne = [
'image_ml_relation' => 'System\Models\File',
];
public function getImageMlAttribute()
{
$image = $this->image_ml_relation;
if (!$image) {
$currentLocale = \RainLab\Translate\Classes\Translator::instance()->getLocale();
$defaultLocale = \RainLab\Translate\Classes\Translator::instance()->getDefaultLocale();
if ($currentLocale != $defaultLocale) {
$image = $this->lang($defaultLocale)->image_ml_relation;
}
}
return $image;
}
And I get the image from the front with {{ model.image_ml.path }}
Maybe this could be integrated in the plugin somehow (change the name of the relation automatically to name+_relation, and then add a new accessor for the original attribute name, that gets the fallback if needed)
I think that it would be good (and coherent with how this plugin works) to have a fallback value for translated attachements, so the default language file is shown if no translations are uploaded.
The text was updated successfully, but these errors were encountered: