youneselbarnoussi/nova-locale-switcher
Composer 安装命令:
composer require youneselbarnoussi/nova-locale-switcher
包简介
A simple locale switcher for Nova without any concrete localization implementation
README 文档
README
This tool provides a simple header dropdown to quickly switch between locales. This tool does not have any concrete implementation, so is up to you of what happens when a locale is selected from the dropdown.
Installation
composer require eolica/nova-locale-switcher
If you were using our tramuntana-studio/nova-locale-switcher package, please modify it accordingly.
Usage
We will demonstrate how tu use this tool with a simple example. First, you must register the tool in NovaServiceProvider under tools.
use Illuminate\Http\Request; public function tools() { return [ \Eolica\NovaLocaleSwitcher\LocaleSwitcher::make() ->setLocales(config('nova.locales')) ->onSwitchLocale(function (Request $request) { $locale = $request->post('locale'); if (array_key_exists($locale, config('nova.locales'))) { $request->user()->update(['locale' => $locale]); } }), ]; }
The setLocales method expects an associative array, the key being the locale code and the value the name of the locale. In this example, we set the locales from de nova.php config file:
return [ // Rest of Nova configuration ... /* |-------------------------------------------------------------------------- | Nova Locales |-------------------------------------------------------------------------- */ 'locales' => [ 'en' => 'English', 'de' => 'Deutsch', 'es' => 'Español', ], ];
For handling the locale switching we must pass a callable to the onSwitchLocale method, in this example we update the current user locale field (this is a custom field that we added to the model) with the locale that we receive from the Request object.
Now, for setting the application locale we can do it inside the boot method of the NovaServiceProvider by using the Nova::serving() method:
use Laravel\Nova\Events\ServingNova; final class NovaServiceProvider extends NovaApplicationServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { parent::boot(); Nova::serving(function (ServingNova $event) { $user = $event->request->user(); if (array_key_exists($user->locale, config('nova.locales'))) { app()->setLocale($user->locale); } }); } ... }
The last step is to display the language selector. For that we must publish Nova's views executing the next command:
php artisan nova:publish
Now we go to the file /resources/views/vendor/nova/layout.blade.php and right after the dropdown that includes the user's partial we add the locale-switcher Vue component:
<!-- Content --> <div> ... <dropdown class="ml-auto h-9 flex items-center dropdown-right"> @include('nova::partials.user') </dropdown> <!-- HERE! --> <locale-switcher></locale-switcher> </div>
And that should be it!
This is one of many solutions you can use, the important thing is that you can switch to another type of implementation without depending on an external package.
Changelog
Please see CHANGELOG for more information what has changed recently.
Security
If you discover a security vulnerability within this package, please send an email at dllobellmoya@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
youneselbarnoussi/nova-locale-switcher 适用场景与选型建议
youneselbarnoussi/nova-locale-switcher 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 338 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「locale」 「nova」 「laravel」 「switcher」 「eolica」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 youneselbarnoussi/nova-locale-switcher 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 youneselbarnoussi/nova-locale-switcher 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 youneselbarnoussi/nova-locale-switcher 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
Package for convenient work with Laravel's localization features
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
统计信息
- 总下载量: 338
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-29
