nova-slug-field
nova-slug-field copied to clipboard
Compatible with translatable
I tried two packages:
https://github.com/spatie/nova-translatable https://github.com/mrmonat/nova-translatable
and this package does not work with any of them.
Any update on this? It would be very useful to support translatable
The problem is basically that the field names have spaces when using them as translatable fields. The events emitted don't get triggered due to the spaces inside (invalid event names). There are a few other things that would need to be changed, but basically "slugifying" the field names before using them would be a big step forward.
Unfortunately this has to be done by the maintainers of those packages, there's nothing I can do on my side as far as I can see. Maybe you wanna ping @freekmurze and ask nicely or add the neccessary functionality by yourself to the translatable package and open an PR. :)
@trawen is there any progression? I am also looking forward to a solution.
I managed to get this package working with https://github.com/spatie/nova-translatable by changing the slug pointer on the text field from
TextWithSlug::make('field')
->slug('{my_slug_name}')
to
TextWithSlug::make('field')
->slug('translations_{my_slug_name}_{locale}')
as the spatie translation package adds those prefixes and suffixes to its translation field names
@Casper-Bastiaan-Net So did you get a slug in your respective language automated - e.g when you enter the title in Arabic letters then slug should become in Arabic letters too?
https://prnt.sc/puj69b
@asharma16891 have you tried changing app's locale? This might work.
@Casper-Bastiaan-Net Could you explain how you did this?
I have two locales: EN and NL. Currently my code looks like this:
Translatable::make([
TextWithSlug::make('title')->rules('required')->slug('translations_slug_nl'),
Slug::make('slug'),
]),
The NL field works like a charm but how can I get the EN slug field linked to the EN title field? Is there a variable you can use to replace 'translations_slug_nl' with 'translations_slug_$locale' or something?
@sanneterpstra
For the non translated version you have to just use the regular notation.
For the translated version you have to add the translations locale at the end of the name manually.
->slug('translations_slug_' . $locale')
