From e5408d5aed5266fd16e60a91636f60eeba87904e Mon Sep 17 00:00:00 2001 From: SWEETIS Date: Tue, 18 Jul 2023 00:20:50 +0300 Subject: [PATCH 1/3] feat(Localization): Translatable labels --- lang/en/ui.php | 12 ++++++++++++ src/LaravelSiteSettingsProvider.php | 6 ++++++ src/MoonShine/Resources/SettingResource.php | 16 ++++++++-------- 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 lang/en/ui.php diff --git a/lang/en/ui.php b/lang/en/ui.php new file mode 100644 index 0000000..3ff2595 --- /dev/null +++ b/lang/en/ui.php @@ -0,0 +1,12 @@ + 'Main', + 'group' => 'Group', + 'slug' => 'Slug', + 'hint' => 'Hint', + 'not_used' => 'Not used on the site, only for ease of administration!', + 'value' => 'Value', + 'created_at' => 'Created at', + 'updated_at' => 'Updated at', +]; \ No newline at end of file diff --git a/src/LaravelSiteSettingsProvider.php b/src/LaravelSiteSettingsProvider.php index 3b5b89b..62d6e97 100644 --- a/src/LaravelSiteSettingsProvider.php +++ b/src/LaravelSiteSettingsProvider.php @@ -47,6 +47,12 @@ public function boot() Setting::observe(LSSObserver::class); SettingGroup::observe(LSSObserver::class); + $this->loadTranslationsFrom(__DIR__.'/../lang', 'laravel-site-settings'); + + $this->publishes([ + __DIR__.'/../lang' => $this->app->langPath('vendor/laravel-site-settings'), + ]); + } } \ No newline at end of file diff --git a/src/MoonShine/Resources/SettingResource.php b/src/MoonShine/Resources/SettingResource.php index d61e7a7..a69a3fa 100644 --- a/src/MoonShine/Resources/SettingResource.php +++ b/src/MoonShine/Resources/SettingResource.php @@ -34,11 +34,11 @@ class SettingResource extends Resource public function fields(): array { return [ - Block::make('Main', [ + Block::make(__('laravel-site-settings::ui.main'), [ ID::make()->sortable(), BelongsTo::make( - 'Group', + __('laravel-site-settings::ui.group'), 'settingGroup', new SettingGroupResource() ) @@ -46,28 +46,28 @@ public function fields(): array ->sortable() ->showOnExport(), - Text::make('Slug', 'slug') + Text::make(__('laravel-site-settings::ui.slug'), 'slug') ->required() ->sortable() ->hint('a-z, 0-9, -, _') ->showOnExport(), - Text::make('Hint', 'hint') + Text::make(__('laravel-site-settings::ui.hint'), 'hint') ->nullable() ->sortable() - ->hint('Не используется на сайте, только для удобства администрирования!') + ->hint(__('laravel-site-settings::not_used')) ->showOnExport(), - Textarea::make('Value', 'value')->nullable()->sortable() + Textarea::make(__('laravel-site-settings::ui.value'), 'value')->nullable()->sortable() ->showOnExport(), - NoInput::make('Created at', 'created_at', + NoInput::make(__('laravel-site-settings::ui.created_at'), 'created_at', fn(Setting $item) => $item->created_at->isoFormat('lll')) ->sortable() ->hideOnForm() ->showOnExport(), - NoInput::make('Updated at', 'updated_at', + NoInput::make(__('laravel-site-settings::ui.updated_at'), 'updated_at', fn(Setting $item) => $item->updated_at->isoFormat('lll')) ->sortable() ->hideOnForm() From 8b28e6bfb5df5e1f7d12fc4ef8b7eebaaae98ba2 Mon Sep 17 00:00:00 2001 From: SWEETIS Date: Tue, 18 Jul 2023 00:43:15 +0300 Subject: [PATCH 2/3] feat(Localization): Translatable labels for Moonshine in EN/RU/RO --- lang/en/ui.php | 5 +++- lang/ro/ui.php | 15 +++++++++++ lang/ru/ui.php | 15 +++++++++++ src/LaravelSiteSettingsProvider.php | 2 +- .../Resources/SettingGroupResource.php | 25 +++++++++---------- src/MoonShine/Resources/SettingResource.php | 13 +++++----- 6 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 lang/ro/ui.php create mode 100644 lang/ru/ui.php diff --git a/lang/en/ui.php b/lang/en/ui.php index 3ff2595..7cebaf5 100644 --- a/lang/en/ui.php +++ b/lang/en/ui.php @@ -9,4 +9,7 @@ 'value' => 'Value', 'created_at' => 'Created at', 'updated_at' => 'Updated at', -]; \ No newline at end of file + 'count_settings' => 'Count settings', + 'settings_groups' => 'Settings groups', + 'settings' => 'Settings' +]; diff --git a/lang/ro/ui.php b/lang/ro/ui.php new file mode 100644 index 0000000..1138031 --- /dev/null +++ b/lang/ro/ui.php @@ -0,0 +1,15 @@ + 'Principala', + 'group' => 'Grupul', + 'slug' => 'Slug', + 'hint' => 'Indiciu', + 'not_used' => 'Nu este folosit pe site, doar pentru ușurința de administrare!', + 'value' => 'Valoare', + 'created_at' => 'Creat la', + 'updated_at' => 'Actualizat la', + 'count_settings' => 'Numărul de setări', + 'settings_groups' => 'Grupuri de setări', + 'settings' => 'Setări' +]; diff --git a/lang/ru/ui.php b/lang/ru/ui.php new file mode 100644 index 0000000..16a979d --- /dev/null +++ b/lang/ru/ui.php @@ -0,0 +1,15 @@ + 'Главная', + 'group' => 'Группа', + 'slug' => 'Slug', + 'hint' => 'Подсказка', + 'not_used' => 'Не используется на сайте, только для удобства администрирования!', + 'value' => 'Значение', + 'created_at' => 'Создано в', + 'updated_at' => 'Обновлено на', + 'count_settings' => 'Счетчик настроек', + 'settings_groups' => 'Группы настроек', + 'settings' => 'Настройки' +]; diff --git a/src/LaravelSiteSettingsProvider.php b/src/LaravelSiteSettingsProvider.php index 62d6e97..a4da3db 100644 --- a/src/LaravelSiteSettingsProvider.php +++ b/src/LaravelSiteSettingsProvider.php @@ -55,4 +55,4 @@ public function boot() } -} \ No newline at end of file +} diff --git a/src/MoonShine/Resources/SettingGroupResource.php b/src/MoonShine/Resources/SettingGroupResource.php index 756c227..1ed921e 100644 --- a/src/MoonShine/Resources/SettingGroupResource.php +++ b/src/MoonShine/Resources/SettingGroupResource.php @@ -22,43 +22,42 @@ class SettingGroupResource extends Resource public static array $activeActions = ['create', 'show', 'edit']; - // TODO Add translation - //public function title(): string - //{ - // return trans('moonshine::ui.resource.admins_title'); - //} + public function title(): string + { + return __('laravel-site-settings::ui.settings_groups'); + } public function fields(): array { return [ - Block::make('Main', [ + Block::make(__('laravel-site-settings::ui.main'), [ ID::make()->sortable(), - Text::make('Slug', 'slug') + Text::make(__('laravel-site-settings::ui.slug'), 'slug') ->required() ->sortable() ->hint('a-z, 0-9, -, _') ->showOnExport(), - Text::make('Hint', 'hint') + Text::make(__('laravel-site-settings::ui.hint'), 'hint') ->nullable() ->sortable() - ->hint('Не используется на сайте, только для удобства администрирования!') + ->hint(__('laravel-site-settings::ui.not_used')) ->showOnExport(), - NoInput::make('Created at', 'created_at', + NoInput::make(__('laravel-site-settings::ui.created_at'), 'created_at', fn(SettingGroup $item)=>$item->created_at->isoFormat('lll')) ->sortable() ->hideOnForm() ->showOnExport(), - NoInput::make('Updated at', 'updated_at', + NoInput::make(__('laravel-site-settings::ui.updated_at'), 'updated_at', fn(SettingGroup $item)=>$item->updated_at->isoFormat('lll')) ->sortable() ->hideOnForm() ->showOnExport(), - NoInput::make('Count settings', 'settings_count') + NoInput::make(__('laravel-site-settings::ui.count_settings'), 'settings_count') ->sortable() ->hideOnForm() ->hideOnDetail() @@ -95,7 +94,7 @@ public function filters(): array public function actions(): array { return [ - + ]; } diff --git a/src/MoonShine/Resources/SettingResource.php b/src/MoonShine/Resources/SettingResource.php index a69a3fa..22cea3d 100644 --- a/src/MoonShine/Resources/SettingResource.php +++ b/src/MoonShine/Resources/SettingResource.php @@ -25,11 +25,10 @@ class SettingResource extends Resource public static array $activeActions = ['create', 'show', 'edit']; - // TODO Add translation - //public function title(): string - //{ - // return trans('moonshine::ui.resource.admins_title'); - //} + public function title(): string + { + return __('laravel-site-settings::ui.settings'); + } public function fields(): array { @@ -55,7 +54,7 @@ public function fields(): array Text::make(__('laravel-site-settings::ui.hint'), 'hint') ->nullable() ->sortable() - ->hint(__('laravel-site-settings::not_used')) + ->hint(__('laravel-site-settings::ui.not_used')) ->showOnExport(), Textarea::make(__('laravel-site-settings::ui.value'), 'value')->nullable()->sortable() @@ -118,7 +117,7 @@ public function filters(): array public function actions(): array { return [ - + ]; } From 7ae49eacd4ea6dede11ba6eb99a835ee9ab29e4e Mon Sep 17 00:00:00 2001 From: SWEETIS Date: Tue, 18 Jul 2023 15:05:15 +0300 Subject: [PATCH 3/3] style(Localization): Change function trans --- .../Resources/SettingGroupResource.php | 16 ++++++++-------- src/MoonShine/Resources/SettingResource.php | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/MoonShine/Resources/SettingGroupResource.php b/src/MoonShine/Resources/SettingGroupResource.php index 1ed921e..3f366d6 100644 --- a/src/MoonShine/Resources/SettingGroupResource.php +++ b/src/MoonShine/Resources/SettingGroupResource.php @@ -24,40 +24,40 @@ class SettingGroupResource extends Resource public function title(): string { - return __('laravel-site-settings::ui.settings_groups'); + return trans('laravel-site-settings::ui.settings_groups'); } public function fields(): array { return [ - Block::make(__('laravel-site-settings::ui.main'), [ + Block::make(trans('laravel-site-settings::ui.main'), [ ID::make()->sortable(), - Text::make(__('laravel-site-settings::ui.slug'), 'slug') + Text::make(trans('laravel-site-settings::ui.slug'), 'slug') ->required() ->sortable() ->hint('a-z, 0-9, -, _') ->showOnExport(), - Text::make(__('laravel-site-settings::ui.hint'), 'hint') + Text::make(trans('laravel-site-settings::ui.hint'), 'hint') ->nullable() ->sortable() - ->hint(__('laravel-site-settings::ui.not_used')) + ->hint(trans('laravel-site-settings::ui.not_used')) ->showOnExport(), - NoInput::make(__('laravel-site-settings::ui.created_at'), 'created_at', + NoInput::make(trans('laravel-site-settings::ui.created_at'), 'created_at', fn(SettingGroup $item)=>$item->created_at->isoFormat('lll')) ->sortable() ->hideOnForm() ->showOnExport(), - NoInput::make(__('laravel-site-settings::ui.updated_at'), 'updated_at', + NoInput::make(trans('laravel-site-settings::ui.updated_at'), 'updated_at', fn(SettingGroup $item)=>$item->updated_at->isoFormat('lll')) ->sortable() ->hideOnForm() ->showOnExport(), - NoInput::make(__('laravel-site-settings::ui.count_settings'), 'settings_count') + NoInput::make(trans('laravel-site-settings::ui.count_settings'), 'settings_count') ->sortable() ->hideOnForm() ->hideOnDetail() diff --git a/src/MoonShine/Resources/SettingResource.php b/src/MoonShine/Resources/SettingResource.php index 22cea3d..b976c23 100644 --- a/src/MoonShine/Resources/SettingResource.php +++ b/src/MoonShine/Resources/SettingResource.php @@ -27,17 +27,17 @@ class SettingResource extends Resource public function title(): string { - return __('laravel-site-settings::ui.settings'); + return trans('laravel-site-settings::ui.settings'); } public function fields(): array { return [ - Block::make(__('laravel-site-settings::ui.main'), [ + Block::make(trans('laravel-site-settings::ui.main'), [ ID::make()->sortable(), BelongsTo::make( - __('laravel-site-settings::ui.group'), + trans('laravel-site-settings::ui.group'), 'settingGroup', new SettingGroupResource() ) @@ -45,28 +45,28 @@ public function fields(): array ->sortable() ->showOnExport(), - Text::make(__('laravel-site-settings::ui.slug'), 'slug') + Text::make(trans('laravel-site-settings::ui.slug'), 'slug') ->required() ->sortable() ->hint('a-z, 0-9, -, _') ->showOnExport(), - Text::make(__('laravel-site-settings::ui.hint'), 'hint') + Text::make(trans('laravel-site-settings::ui.hint'), 'hint') ->nullable() ->sortable() - ->hint(__('laravel-site-settings::ui.not_used')) + ->hint(trans('laravel-site-settings::ui.not_used')) ->showOnExport(), - Textarea::make(__('laravel-site-settings::ui.value'), 'value')->nullable()->sortable() + Textarea::make(trans('laravel-site-settings::ui.value'), 'value')->nullable()->sortable() ->showOnExport(), - NoInput::make(__('laravel-site-settings::ui.created_at'), 'created_at', + NoInput::make(trans('laravel-site-settings::ui.created_at'), 'created_at', fn(Setting $item) => $item->created_at->isoFormat('lll')) ->sortable() ->hideOnForm() ->showOnExport(), - NoInput::make(__('laravel-site-settings::ui.updated_at'), 'updated_at', + NoInput::make(trans('laravel-site-settings::ui.updated_at'), 'updated_at', fn(Setting $item) => $item->updated_at->isoFormat('lll')) ->sortable() ->hideOnForm()