statikbe / laravel-nova-chained-translation-manager
Laravel Nova Chained Translation Manager 允许您轻松编辑和自定义当前 Laravel 环境的翻译。
Requires
- php: ^8.0|^8.1|^8.2
- illuminate/validation: ^8.0|^9.0|^10.0|^11.0
- laravel/nova: ^4.0
- statikbe/laravel-chained-translator: ^2.0
README
Laravel Nova Chained Translation Manager
注意:如果您正在寻找 nova 3,请查看 3.0 分支
Laravel Nova Chained Translation Manager 允许您轻松编辑当前 Laravel 环境的翻译。此翻译管理器使用 Laravel Chained Translator,它允许您使用特定环境的翻译覆盖默认翻译,例如,内容管理器可以独立编辑并覆盖生产环境中的翻译文件,而不是开发人员提供的翻译。
通常在开发阶段某个时候,内容管理器希望翻译或微调开发人员添加的翻译字符串。这通常会导致合并和版本冲突问题,当开发人员和内容管理器同时处理翻译文件时。
Chained Translator 包允许开发人员创建的翻译与内容管理器编辑的翻译(自定义翻译)在单独的 lang 目录中分开存在。该库合并了两个语言目录的翻译,其中内容管理器的翻译(自定义翻译)覆盖了开发人员的翻译(默认翻译)。有关更多信息,请查看 Laravel Chained Translator 的文档。
功能
- 将当前环境的翻译保存到单独的语言目录中的单独翻译文件,以避免版本冲突。
- 立即保存翻译
- 搜索翻译和翻译键
- 过滤特定组和语言的翻译
- 仅显示缺少翻译的键
- 支持 Nova 4
目前,此工具不提供添加新翻译键的功能,因为我们的目标用户是翻译人员和内容管理器,我们希望避免他们添加不必要的翻译键。
安装
可以通过 Composer 安装此包。
composer require statikbe/laravel-nova-chained-translation-manager
Nova 4 支持从版本 v3.0.0 开始。如果您仍在使用 Nova 3,请使用 v2 版本。
composer require statikbe/laravel-nova-chained-translation-manager:~2
接下来在 Nova 中启用此工具。转到 app/Providers/NovaServiceProvider.php 并将 TranslationManager 添加到工具中。
use Statikbe\NovaTranslationManager\TranslationManager; public function tools() { return [ new TranslationManager, ]; }
配置
您可以配置自定义语言目录名称并扩展或微调 Laravel Chained Translator 的服务提供者。请查看 Laravel Chained Translator 库 的配置选项。
支持的地区
有两种方法可以更改支持的地区。
选项 1
使用以下命令发布配置文件,并使用您支持的地区和编辑器首选项进行配置。
php artisan vendor:publish --tag=nova-chained-translation-manager
例如。
/* |-------------------------------------------------------------------------- | 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' ],
选项 2
如果您的应用程序已经有一个配置,声明了您的地区,则您可以在任何服务提供者中设置支持的地区。创建一个新的或使用 app/Providers/AppServiceProvider.php 并在 boot 函数中将支持的地区作为数组设置如下
use Statikbe\NovaTranslationManager\TranslationManager; public function boot() { TranslationManager::setLocales(['en', 'nl']); }
更改您的编辑器
还可以更改您的编辑器,有时翻译值可能会很大,如果您有一个更大的区域来编辑它们或者在编辑时添加粗体/下划线效果会更好。您可以使用3个支持的值:input、textarea、trix。它们的名字具有自解释性。
注意:我们不推荐使用Trix作为编辑器,因为如果您在HTML中的翻译中使用变量,例如用于锚标签的url,Trix将会移除它 :-(。请在使用Trix时记住,您还应该配置您允许的HTML标签。
不要忘记更改这些设置后清除缓存,并刷新您的页面以查看结果 :-)
例如。
/* |-------------------------------------------------------------------------- | Editor to use |-------------------------------------------------------------------------- | | Choose what type of editor you want to use while editing your translations | input - For really dead simple input | textarea - For a larger textarea to deal with | trix - Will use Trix Editor for editing locales supporting some HTML on it. | | Note : Please keep in mind while using Trix to configure your allowed HTML | tags. Otherwise it may pose XSS attacks risk if field could be edited by the end user. | | Values : trix, input, textarea | */ 'editor' => 'input', 'trix_allowed_tags' => '<code><p><b><u><a><br><ul><li><ol><pre><h2><h3><h4><h5><del><blockquote><dl><dd><strong>',
忽略分组
您还可以忽略某些翻译分组在Nova UI中显示。创建一个包含您想忽略的键的数组
例如。
/* |-------------------------------------------------------------------------- | Ignore Groups |-------------------------------------------------------------------------- | This will ignore certain groups from the translations UI | Supports an array of keys | */ 'ignore_groups' => ['auth','pagination','passwords','routes','nova','nova/validation'],
合并翻译
您可以通过运行由Laravel Chained Translator库提供的命令,将当前环境的自定义翻译与默认翻译文件合并。
致谢
我们使用了Joe Dixon的翻译库作为技术专业知识和灵感的来源
@nelumoraru和@FrittenKeeZ为Nova 4升级了库。
非常感谢你们出色的作品!
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。



