vovacorgo / laravel-filament-chained-translation-manager
用于Laravel Filament的翻译管理工具,它利用了Laravel Chained Translator。
Requires
- php: ^8.1|^8.2
- filament/filament: ^2.17|^3.0
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.9
- statikbe/laravel-chained-translator: ^2.2
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.0
- nunomaduro/larastan: ^2.4
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.x-dev
- pestphp/pest-plugin-laravel: 2.x-dev
- phpstan/extension-installer: ^1.2
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-09-17 16:50:33 UTC
README
Laravel Filament Chained Translation Manager
Laravel Filament Chained Translation Manager 允许您轻松编辑当前 Laravel 环境的翻译。此翻译管理器使用 Laravel Chained Translator,它允许您覆盖默认翻译以特定环境的翻译,例如,内容管理器可以独立编辑并覆盖生产环境中的翻译文件,而无需依赖开发者的翻译。
通常,在开发阶段某个时候,内容管理器想要翻译或微调开发者添加的翻译字符串。这通常会导致开发者和内容管理器同时工作在翻译文件上时出现合并和版本问题。
Chained Translator 包允许开发者的翻译与内容管理器(自定义翻译)编辑的翻译在单独的 lang 目录中分离存在。库合并了两个语言目录的翻译,其中内容管理器的翻译(自定义翻译)覆盖了开发者的翻译(默认翻译)。有关更多信息,请参阅 Laravel Chained Translator 的文档。
此包还有 Laravel Nova 版本。
特性
- 将当前环境的翻译保存到单独的语言目录中的单独翻译文件中,以避免版本冲突。
- 立即保存翻译
- 搜索翻译和翻译键
- 过滤特定组和语言的翻译
- 仅显示缺少翻译的键
- 显示完全翻译的字段统计信息
此工具不提供添加新翻译键的功能,因为我们的目标用户是翻译人员和内容管理器,我们希望避免他们添加不必要的翻译键。
安装
您可以通过 composer 安装此包
composer require statikbe/laravel-filament-chained-translation-manager
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="filament-translation-manager-config"
这是发布配置文件的内容
return [ 'enabled' => true, /* |-------------------------------------------------------------------------- | Application Supported Locale Configuration |-------------------------------------------------------------------------- | | The application locale determines the possible locales that can be used. | You are free to fill this array with any of the locales which will be | supported by the application. | */ 'supported_locales' => [ 'en', 'nl', 'fr', ], /* |-------------------------------------------------------------------------- | Access |-------------------------------------------------------------------------- | | Limited = false (default) | Anyone can use the translation manager. | | Limited = true | The page will use the provided gate to see if the user has access. | - Default Laravel: you can define the gate in a service provider (https://laravel.net.cn/docs/10.x/authorization) | - Spatie permissions: set the 'gate' variable to a permission name you want to check against, see the example below. | | */ 'access' => [ 'limited' => false, //'gate' => 'view-filament-translation-manager', ], /* |-------------------------------------------------------------------------- | Ignore Groups |-------------------------------------------------------------------------- | | You can list the translation groups that you do not want users to translate. | Note: the JSON files are grouped in 'json-file' by default. (see config/laravel-chained-translator.php) */ 'ignore_groups' => [ // 'auth', ], /* |-------------------------------------------------------------------------- | Navigation Sort |-------------------------------------------------------------------------- | | You can specify the order in which navigation items are listed. | Accepts integer value according to filamnet documentation. | (visit: https://filamentphp.com/docs/2.x/admin/resources/getting-started#sorting-navigation-items) */ 'navigation_sort' => null, ];
可选,您可以使用以下命令发布视图
php artisan vendor:publish --tag="filament-translation-manager-views"
可选,您还可以使用以下命令发布翻译
php artisan vendor:publish --tag="filament-translation-manager-translations"
配置
您可以为自定义语言目录名称进行配置,并扩展或调整 Laravel Chained Translator 的服务提供者。请参阅 Laravel Chained Translator 库 的配置选项。
支持的地区
有两种方法可以更改支持的地区。
选项 1
使用以下命令发布配置文件,并使用您支持的地区和编辑器首选项(见上文)进行配置。然后配置 supported_locales
变量
/* |-------------------------------------------------------------------------- | Application Supported Locale Configuration |-------------------------------------------------------------------------- | | The application locale determines the possible locales that can be used. | You are free to fill this array with any of the locales which will be | supported by the application. | */ 'supported_locales' => [ 'en', 'nl', 'fr' ],
选项 2
如果你的应用程序已经有一个声明你本地化的配置,那么你可以在任何服务提供者中设置支持的本地化。创建一个新的或使用 app/Providers/AppServiceProvider.php
并在 boot 函数中设置支持的本地化数组,如下所示
use Statikbe\FilamentTranslationManager\FilamentTranslationManager; public function boot() { FilamentTranslationManager::setLocales(['en', 'nl']); }
访问
你可以通过配置 access
变量来限制对翻译管理器的访问。如果你将 limited
键设置为 true
,你可以设置 Laravel Gate 类或 Spatie Permissions 包的权限名称。
/* |-------------------------------------------------------------------------- | Access |-------------------------------------------------------------------------- | | Limited = false (default) | Anyone can use the translation manager. | | Limited = true | The page will use the provided gate to see if the user has access. | - Default Laravel: you can define the gate in a service provider (https://laravel.net.cn/docs/9.x/authorization) | - Spatie permissions: set the 'gate' variable to a permission name you want to check against, see the example below. | | */ 'access' => [ 'limited' => false, //'gate' => 'view-filament-translation-manager', ],
忽略组
你还可以忽略 Filament 中显示的某些翻译组。创建一个包含你想要忽略的键的数组
/* |-------------------------------------------------------------------------- | Ignore Groups |-------------------------------------------------------------------------- | | You can list the translation groups that you do not want users to translate. | Note: the JSON files are grouped in 'json-file' by default. (see config/laravel-chained-translator.php) */ 'ignore_groups' => [ 'auth', ],
用法
该库为新的翻译创建一个新目录,请参阅 Laravel Chained Translator。检查 Laravel Chained Translator 包的配置选项以更改此设置。
翻译管理器会自动添加到 Filament 菜单中。
合并翻译
你可以通过运行由 Laravel Chained Translator 库 提供的命令,将当前环境的自定义翻译与默认翻译文件合并。
变更日志
请参阅 CHANGELOG 以获取有关最近更改的更多信息。
贡献
请通过 Github issues 提交错误或功能请求。欢迎 Pull requests!谢谢!
安全漏洞
请查看我们如何报告安全漏洞的 安全策略。
鸣谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 获取更多信息。