Translate File Field #60
Replies: 14 comments
-
Same issue here, I'm getting an error |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, Any updates ? |
Beta Was this translation helpful? Give feedback.
-
same error, looking for solution! |
Beta Was this translation helpful? Give feedback.
-
As a workaround, just add:
so your fields function will look like:
This needs to be done for each language you want to support (yeah... ugly). |
Beta Was this translation helpful? Give feedback.
-
when trying @tonci method I get: Trix images work fine without the wrapper. |
Beta Was this translation helpful? Give feedback.
-
@jrmadsen67 You have to use |
Beta Was this translation helpful? Give feedback.
-
Is there any update here? Both Trix and Froala fields don't work with spatie/nova-translatable when it comes to file uploads/attachments. |
Beta Was this translation helpful? Give feedback.
-
Same issue here. Seems like the call is of the wrong type. |
Beta Was this translation helpful? Give feedback.
-
Do not forget to place it in the main array within the fields method of het Resource. It acts like a hidden field. Just to be sure. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Keep in mind that this workaround seems to be working only with Trix field type. If you are using a different type of editor (eg Froala), this is not enough to make it work, unfortunately. |
Beta Was this translation helpful? Give feedback.
-
Had the same problem with file uploads using the // User Resource
public function fields(Request $request)
{
return [
//...
Translatable::make([
Trix::make('About')
->withFiles('public')
->alwaysShow(),
])
];
}
// Translatable field
namespace App\Nova\Fields;
use Laravel\Nova\Fields\Trix;
use Laravel\Nova\Fields\Field;
use Spatie\NovaTranslatable\Translatable as BaseTranslatable;
class Translatable extends BaseTranslatable
{
protected function createTranslatableFields()
{
parent::createTranslatableFields();
if ($this->onIndexPage()) {
return;
}
collect($this->locales)
->crossJoin($this->originalFields)
->eachSpread(function (string $locale, Field $field) {
if ($field instanceof Trix && $field->withFiles) {
$this->data[] = get_class($field)::make('translations_' . $field->attribute . '_' . $locale)
->onlyOnIndex()
->showOnIndex(false)
->withFiles($field->disk, $field->storagePath);
}
});
}
} @freekmurze I don't feel that this solution is clean in any way, but maybe it sparks an idea on your side on how to solve this in a more elegant way? Otherwise I am also open to create a PR with my fix if you want. |
Beta Was this translation helpful? Give feedback.
-
What about File fields ? |
Beta Was this translation helpful? Give feedback.
-
Any news ? |
Beta Was this translation helpful? Give feedback.
-
When I try to translate a Nova File Field I get error when saving. The File Field is trying to save the
translations_FIELDNAME_LANG
attribute and not theFIELDNAME
attribute.I don't really see through how
nova-translatable
and the File Field are working so I have no idea what the best approach would be to fix this. If you have a hint I'd be happy to do a PR.Beta Was this translation helpful? Give feedback.
All reactions