Closed overclocked555 closed 9 months ago
Hey,
you can use $post->{'title:de'}
to get the attribute in a specific locale.
https://docs.astrotomic.info/laravel-translatable/usage/attributes
https://github.com/Astrotomic/laravel-translatable/blob/0ead23494acb289af594427503f3749513891749/src/Translatable/Translatable.php#L384-L391
Besides that you can also set the locale to be used on a per model level $post->setDefaultLocale('de')
- this will set a property on the model instance and won't affect anything else. To undo it just call the method with a null
argument.
https://github.com/Astrotomic/laravel-translatable/blob/0ead23494acb289af594427503f3749513891749/src/Translatable/Translatable.php#L353-L360
Thanks a lot for the tips!
Thanks a lot for the great package!
Is there a way to translate multiple model items into a specific language at once without using App::setLocale()? So far I only see this complicated method:
And after that I will have to prevent the models from being translated when converted to JSON or array.
Method with App::setLocale() :
But I doubt if such code is executed in Blade Anonymous Components, whether changing the locale will affect other parts of the application.
Any ideas?