Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.23k stars 156 forks source link

Fallback is not being found #225

Closed KhurshidYakubov closed 3 years ago

KhurshidYakubov commented 3 years ago

I have 4 locales. And I want to loop through my locales from top to bottom until one existing is found or end of list reached.

My app/config/translatable.php file context looks like this:

'locales' => [
        'ru',
        'uz',
        'oz',
        'en',
    ],

'locale' => null,

'use_fallback' => true,

'use_property_fallback' => true,

'fallback_locale' => null,

Controller:

$list_types = ListType::paginate(5);

return view('admin.list_types.index', compact('list_types'));

And index.blade.php:

<p>{{ $list_type->translateOrDefault()->title}}</p>

In my opinion, I follwed all instructions which are mentioned in documentation. However, it is keeping to return only the first locale. How can I deal with this ?

Gummibeer commented 3 years ago

Hey, And which translations exist and which one is returned?

KhurshidYakubov commented 3 years ago

Firstly, creation order in store() function is like oz, uz, ru (en for future usage), as you can see below:

 $data = [
            'slug' => $get_slug_element,
            'oz' => [
                'title' => $request->oz_title,
            ],
            'uz' => [
                'title' => $request->uz_title,
            ],
            'ru' => [
                'title' => $request->ru_title,
            ],
            'status' => $request->status,
            'creator_id' => $user->id ?? 1,
        ];

        $list_type = ListType::create($data);

Data was inserted only for 'uz' . But it is returning 'oz' (which means the first one from table).

Gummibeer commented 3 years ago

And what's your app locale? app()->getLocale() and/or in app.php config.

KhurshidYakubov commented 3 years ago

In app.php locale is oz. And app()->getLocale() shows dependently what I choose. If I change the locale to uz title appears. if I change to oz or ru it shows nothing because they are empty.

github-actions[bot] commented 3 years ago

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