Dynamic languages using spatie's package
I am saving a list of languages per entry in my articles table, so for example,
$article->languages
can be ['es','de']
and sometimes it can be ['fr','nl']
.. etc. Now, i worked with spatie/laravel-translatable
in the past with no problem at all, when getTranslatableLocales()
has a fixed set of languages, but when trying to populate the locale switcher dynamically by $article->languages
- it fallbacks to the default config once language is changed.
Here's how im trying to implement it at the moment on ArticleResource.php
-
I noticed that once i change the language in the locale switcher (a simple Actions\LocaleSwitcher::make()
on getHeaderActions()
) - the $recordId
is emptied, hence it retrieves the $defaultLnaguages
instead. I guess there's a more way to access the current record instead of request()->route('record')
1 Reply
* On the initial load - it populates the dynamic languages correctly. The problem is only happening once i select a different language.
i was able to patch it like this -
not very elegant, but it works..