nova-slug-field icon indicating copy to clipboard operation
nova-slug-field copied to clipboard

Compatible with translatable

Open trawen opened this issue 6 years ago • 9 comments

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.

trawen avatar Jan 18 '19 23:01 trawen

Any update on this? It would be very useful to support translatable

thanoseleftherakos avatar Feb 06 '19 10:02 thanoseleftherakos

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.

tomhatzer avatar Apr 11 '19 09:04 tomhatzer

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. :)

benjaminhirsch avatar Apr 21 '19 12:04 benjaminhirsch

@trawen is there any progression? I am also looking forward to a solution.

Grunkhead avatar Sep 11 '19 12:09 Grunkhead

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 avatar Oct 21 '19 12:10 Casper-Bastiaan-Net

@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

ghost avatar Nov 09 '19 06:11 ghost

@asharma16891 have you tried changing app's locale? This might work.

Grunkhead avatar Nov 13 '19 13:11 Grunkhead

@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 avatar Mar 10 '20 18:03 sanneterpstra

@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')

image

Grunkhead avatar Mar 19 '20 14:03 Grunkhead