Closed arturasfrontit closed 1 year ago
It does not work because you are currently loading your translations after your gettext calls. Callback that you pass into Nova::serving
will fire after NovaSettings::addSettingsFields
which you don't want.
Move your NovaSettings::addSettingsFields
call into callback that is passed to Nova::serving
and it will work.
Whose translations is for frontend custom packages and etc: https://nova.laravel.com/docs/4.0/customization/localization.html#frontend
I can remove that code and menu will stil have correct translations.
after Nova serving I got declared Nova menu and it works out of the box.
Nova::serving(function (ServingNova $event) {
app()->setLocale('lt');
});
Nova::mainMenu(function (Request $request) {
return [
MenuSection::dashboard(Main::class)->icon('chart-bar'),
MenuSection::make(__('E-commerce'), [
MenuItem::resource(Subscription::class),
];
});
Also published translations doesn't translate UI:
{
"novaSettings.navigationItemTitle": "Settings",
"novaSettings.saveButtonText": "Save settings",
"novaSettings.noSettingsFieldsText": "No settings fields have been defined.",
"novaSettings.settingsSuccessToast": "Settings successfully updated!",
"novaSettings.general": "General"
}
Not sure what you are saying exactly but your code you provided still was not correct - in your code you called gettext (__ function) for field names before you included your translation file but you will have to include your translation file before using gettext calls.
I tried it out on my project, created new language file and included it like so:
// resources/lang/vendor/nova/en.json
{
"novaSettings.navigationItemTitle": "My custom settings",
"novaSettings.saveButtonText": "My custom save settings",
"novaSettings.noSettingsFieldsText": "My custom no settings fields have been defined.",
"novaSettings.settingsSuccessToast": "My custom settings successfully updated!",
"novaSettings.general": "My custom general",
"novaSettings.myPanelTitle": "My custom panel title",
"novaSettings.myTextField": "My custom text field label"
}
// NovaServiceProvider.php
public function boot()
{
parent::boot();
Nova::serving(function () {
Nova::translations(lang_path('vendor/nova/en.json'));
NovaSettings::addSettingsFields([
Panel::make(__('novaSettings.myPanelTitle'), [
Text::make(__('novaSettings.myTextField'), 'my_text_field'),
]),
], [] );
});
}
And this is the result https://d.pr/i/TWhmve
thank you!
working solution:
Nova::serving(function (ServingNova $event) {
app()->setLocale('lt');
Nova::translations(array_merge(
json_decode(file_get_contents(lang_path('lt.json')), true),
json_decode(file_get_contents(lang_path('vendor/nova/lt.json')), true),
json_decode(file_get_contents(lang_path('vendor/nova-settings/lt.json')), true),
));
resolve(Settings::class)();
});
lt.json