outl1ne / nova-settings

A Laravel Nova tool for editing custom settings using native Nova fields.
MIT License
274 stars 96 forks source link

Broken Translation?! #35

Closed mstaack closed 3 years ago

mstaack commented 3 years ago

Seeing novaSettings.navigationItemTitle in Settings View:

image

I am on latest 2.5.6 and have all translations published.

$ composer -i show | grep settings
A script named bin would override a Composer command and has been skipped
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
optimistdigital/nova-settings            2.5.6    A Laravel Nova tool for editing custom settings using native Nova fields.
$ php artisan vendor:publish --provider="OptimistDigital\NovaSettings\ToolServiceProvider" --tag="translations"
Copied Directory [/vendor/optimistdigital/nova-settings/resources/lang] To [/resources/lang/vendor/nova-settings]
Publishing complete.
$ ls resources/lang/vendor/nova-settings
en.json  et.json
mathiasonea commented 3 years ago

@mstaack is it possible you have a different locale set than the default "en" ?

mstaack commented 3 years ago

no using locale="en" has the same effect for some weird reason. the menu item is correctly translated, its just the panel header.

RomkaLTU commented 3 years ago

Same here

bastihilger commented 3 years ago

I think I can at least help a bit with finding the solution (if I had the whole solution I'd PR it, but unfortunately I don't): In your SettingsController's get method you call the translations, but for some reason the vendor translations are not yet loaded at that point. As a proof of concept try making a json file in your resources/lang folder (in my case de.json) and put the translation for novaSettings.navigationItemTitle in there. That will work. So the "regular" translations are loaded when the controller ist fired, but the vendor translations are not yet loaded... or so it seems.


class SettingsController extends Controller
{
    use ResolvesFields, ConditionallyLoadsAttributes;

    public function get(Request $request)
    {
        $fields = $this->assignToPanels(__('novaSettings.navigationItemTitle'), $this->availableFields());
        $panels = $this->panelsWithDefaultLabel(__('novaSettings.navigationItemTitle'), app(NovaRequest::class));

        // more code
    }
}
Tarpsvo commented 3 years ago

What version of Laravel and Nova are you guys running? I can't reproduce this issue.

I'm on Laravel 8.11.2 and Nova 3.14.0

bastihilger commented 3 years ago

I am on Nova 3.15.0 and Laravel 8.14.0

If you cannot reproduce it with those versions, I will try with a fresh install.

mstaack commented 3 years ago
laravel/framework                        v8.14.0
laravel/nova                             3.15.0
optimistdigital/nova-settings            2.5.6
Tarpsvo commented 3 years ago

Ah yes, I think I finally fixed it. It's due to Laravel Translator not working as intended. I worked around it for now, but I also opened up an issue here: https://github.com/laravel/framework/issues/35244

Try out version 2.5.7 and let me know if it works now. :) Thanks!

mstaack commented 3 years ago

thanks for your effort, butthis broke only the menu item translation:

  - Upgrading optimistdigital/nova-settings (2.5.6 => 2.5.7)
  - Upgrading optimistdigital/nova-translations-loader (2.0.0 => 2.0.1)

also published translations again...

image

mstaack commented 3 years ago

some context: image

gives:

"novaSettings.navigationItemTitle"
"de"

of course en and de translations published.

Maybe something with the hints in app('translator') instance? i am not really into laravel's translation logic/engine

Illuminate\Translation\Translator {#563
  #loader: Illuminate\Translation\FileLoader {#562
    #files: Illuminate\Filesystem\Filesystem {#38}
    #path: "/Users/user/project/resources/lang"
    #jsonPaths: array:3 [
      0 => "/Users/user/project/resources/lang/vendor/nova"
      1 => "/Users/user/project/vendor/optimistdigital/nova-multiselect-field/src/../resources/lang"
      2 => "/Users/user/project/resources/lang/vendor/nova-settings"
    ]
    #hints: array:5 [
      "auth-checker" => "/Users/user/project/vendor/lab404/laravel-auth-checker/src/../lang/"
      "backup" => "/Users/user/project/vendor/spatie/laravel-backup/src/../resources/lang/"
      "enum" => "/Users/user/project/vendor/spatie/laravel-enum/src/../resources/lang/"
      "nova-permission-tool" => "/Users/user/project/vendor/vyuldashev/nova-permission/src/../resources/lang"
      "nova" => "/Users/user/project/vendor/laravel/nova/src/../resources/lang"
    ]
  }
  #locale: "de"
  #fallback: "en"
mstaack commented 3 years ago

maybe going with php arrays instead of json files is needed here!?

similar to: https://github.com/vyuldashev/nova-permission/tree/master/resources/lang/en

bastihilger commented 3 years ago

Going with php arrays is a clean way to do this (I do this in my Nova packages, too). You also would need less boilerplate code, as it is only two lines in your service provider.

But on the other hand this will be a breaking change for those who already use the json files to translate to their own language.

Tarpsvo commented 3 years ago

The problem with that is the fact that Nova doesn't know how to load translations for the front-end from the arrays.

Tarpsvo commented 3 years ago

Alright, released a new version - 2.5.8. Let me know if it's any better now. Seemed to work for me.

mstaack commented 3 years ago

great! all working fine for me. 👍

ifaniqbal commented 3 years ago

Hi. I just want to share that the working version, for me, if used with Nova v2.12 is 2.5.0. Tried 2.5.8 but still got translation error.

miguel-serrano commented 2 years ago

My solution was:

create this file from en.json and translate!!! (for spanish)

resources/lang/vendor/nova-settings/es.json

https://github.com/optimistdigital/nova-settings