Open phuthoma opened 4 years ago
I think this is the problem. The commented line is vendor's original and below is the line that "fix" the issue.
No, it does not solve the problem.
Faced with the same issue. If I set app locale to differ than default, I've got exception when trying to edit some other language.
For example: my current lang is "en". my default config lang is "de".
If I try to edit "en" language, it works ok. but if I try to edit "de", I get
"message": "Undefined index: en", "exception": "ErrorException", "file": "/var/www/import/vendor/joedixon/nova-translation/src/Http/Controllers/LanguageTranslationController.php", "line": 85,
I investigated this problem and could resolve it. For me it was connected with those fact, that I set locale depending on user's preferences. I'm using middleware which checks user's preferences and run App::setLocal($locale); But the main problem is that registering package service provider happens before setting locale in middleware. So every time it tooks from config, ignoring my middleware. So I did this workaround (I'm using laravel-translation with nova-translation package) in my middleware:
public function handle($request, Closure $next)
{
if (Auth::user()) {
App::setLocale(Auth::user()->language);
}
//rebind NovaServiceProvider workaround to have proper user locale
app()->bind(NovaServiceProvider::class);
return $next($request);
}
Having the same issue, but I don't use nova-translation. But I also set the locale based on the user preference with a middleware.
I found some time to look deeper into a problem, and it's pretty easy to fix the bug (misuse of variable in /vendor/translation/languages/translations/index.blade.php) - just change 'config('app.locale')' in lines 53 & 57 to '$language'. The fixed code should look like this:
@if(!is_array($value[$language]))
<tr>
<td>{{ $group }}</td>
<td>{{ $key }}</td>
<td>{{ $value[$language] }}</td>
<td>
<translation-input
initial-translation="{{ $value[$language] }}"
language="{{ $language }}"
group="{{ $group }}"
translation-key="{{ $key }}"
route="{{ config('translation.ui_url') }}">
</translation-input>
</td>
</tr>
@endif
Dear Joe,
The problem is when I change locale (localization) of my app to other than defined in config/app.php file (which id 'en' by default), the translation pages (other than actual locale value page) stop working.
So, basically:
Please see the below video for more details: https://streamable.com/b9qrb3
After a quick debug I found out that the problem seems to be that '$translations' array does not include the necessary index for the selected locale:
Best regards, Radoslaw