Closed PetroGromovo closed 1 year ago
Looking at this docs : https://docs.astrotomic.info/laravel-translatable/package/scopes#translatedin-string-usdlocale-null
I see some examples, like :
Post::translatedIn('en')->get();
and
$post = Post::first();
But example :
$banner = Banner::first();
$bannerText = $banner->translate('fr')->text;
```also returns default value in ‘en’, not 'fr'
In my model
app/Models/Banner.php
I added :
protected $translationForeignKey = 'banner_id';
But it did not help and I got all text value in default ‘en’.
I suppose I misconfigure something in my model definitions, but what ?
1) I found some strange for me decision as to work properly
I need in file config/translatable.php to set
'locale' => null,
and with this option then getting data as
$bannersInFrench = Banner
::translatedIn('fr')
->orderBy('id', 'asc')
->get();
I got french labels.
2) Why I got ‘translations’ subarray in resulting list of data ? That is not really what I need...
This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days
On laravel 9 site I added astrotomic/laravel-translatable and getting set of data I see a bit different results I expected As I have 2 languages defined in config/translatable.php with default 'en' :
I do request with 'fr' locale:
I check logs :
)
Text in text, description fields(of banner, not translations] subarray...) are in ‘en’, not in 'fr', as I expected...
In file app/Models/Banner.php I have :
and in app/Models/BannerTranslation.php :
Seems I did not miss any config options, but what is wrong ?
Thanks in advance!