bakerkretzmar / nova-settings-tool

Laravel Nova tool to view and edit application settings.
MIT License
167 stars 32 forks source link

Frontend string translations #32

Closed Paulsky closed 4 years ago

Paulsky commented 4 years ago

Thank you for this great package! I would like to translate the frontend strings. Like this:

'settings' => [
        [
            'key'   => 'twitter_url',
            'label' => 'novaSettingsTool.labels.twitter',
            'panel' => 'novaSettingsTool.panels.social',
        ],
]

Then, in resources/lang/vendor/nova-settings-tool/en.json

{
    "novaSettingsTool.panels.social": "Social settings",
    "novaSettingsTool.labels.twitter": "Twitter Profile"
}

Is this possible? Thank you in advance!

bakerkretzmar commented 4 years ago

It should be possible, yes—I think you'll want to put your translated strings in resources/lang/vendor/nova/en.json. Then what you have above should work. Let me know!

Paulsky commented 4 years ago

Thank you @bakerkretzmar . That works! I prefer to have a dedicated translation file though. It's cleaner and easier to find and maintain. Is this possible?

bakerkretzmar commented 4 years ago

Glad to hear it! Yes, you can put them in a separate file, you'll need to load that file explicitly.

Assuming your translations are in resources/lang/en.json, in the boot() method of your AppServiceProvider, add something like this:

public function boot()
{
    $this->loadJsonTranslationsFrom(resource_path('lang'));
}

You can see how Nova does it here.