ferdiunal / nova-translations
一个 Laravel Nova 翻译工具
Requires
- php: ^8.2|^8.3
- laravel/framework: ^11.0
- laravel/nova: ^4.0
- nyholm/psr7: ^1.8
- spatie/laravel-translatable: ^6.8
- spatie/laravel-translation-loader: ^2.8
- symfony/http-client: ^7.1
Requires (Dev)
- barryvdh/laravel-ide-helper: ^3.0
- laravel/pint: ^1.0
- spatie/laravel-ray: ^1.34
README
此包允许您使用 spatie/laravel-translation-loader 包在项目中查找和管理翻译键和语言文件。默认情况下,它包括免费翻译工具如 Google Translate、Bing Translate 和 MyMemory Translate,以及提供一定免费使用的付费工具,如 DeepL Translate 和 NLPCloud Translate。您还可以添加其他翻译工具,如下面的示例所示。
安装
要安装,请在项目目录中运行以下命令
composer require ferdiunal/nova-translations
配置
可选,您可以使用以下命令发布迁移文件
php artisan vendor:publish --tag nova-translations-migrations
可选,您可以使用以下命令发布配置文件
php artisan vendor:publish --tag nova-translations-config
使用
要将项目使用的翻译键和语言文件导入到表中,您可以运行以下命令。您可以使用 -T|--translater 参数指定此过程支持翻译工具。
php artisan nova-translations:import --help Description: Import translations from the language files Usage: nova-translation:import [options] Options: -T, --translater[=TRANSLATER] The translater to use: google,bing,deepl,mymemory,nlpcloud -h, --help Display help for the given command. When no command is given display help for the list command -q, --quiet Do not output any message -V, --version Display this application version --ansi|--no-ansi Force (or disable --no-ansi) ANSI output -n, --no-interaction Do not ask any interactive question --env[=ENV] The environment the command should run under -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
然后,按照以下方式更新 app/NovaServiceProvider 文件中的 tools 方法
// app/NovaServiceProvider.php class NovaServiceProvider extends NovaApplicationServiceProvider { /** * Get the tools that should be listed in the Nova sidebar. * * @return array */ public function tools() { return [ ... // Other Nova Tools new NovaTranslations, ]; } }
翻译器
Google Translate
如果您想在项目中使用 Google Translate,您需要添加以下包
composer require stichoza/google-translate-php
DeepL Translate
如果您想在项目中使用 DeepL Translate,您需要添加以下包
composer require deeplcom/deepl-php
然后,在环境文件中添加以下键
DEEPL_API_KEY=xxxxxxxx...
NLPCloud Translate
如果您想在项目中使用 NLP Translate,您需要添加以下包
composer require nlpcloud/nlpcloud-client
然后,在环境文件中添加以下键
NLPCLOUD_API_KEY=xxxxxxxx
对于不同语言,您需要将所需的语言代码添加到 config/nova-translations 配置文件中,请参阅 这里。
return [ .... 'services' => [ 'nlpcloud' => [ // https://nlpcloud.com/ 'api_key' => env('NLPCLOUD_API_KEY'), 'languages' => [ // https://docs.nlpcloud.com/#translation // Add the language code you want here ], ], ], ];
其他 Nova 包
-
此包提供了 Laravel Nova 中 Spatie 设置包的接口。它允许您轻松管理应用程序的配置设置。
-
此包将 Spatie 的媒体库包集成到 Laravel Nova 中,允许您有效地管理和组织媒体文件。
-
此包提供了一个 Nova 字段,用于控制数据库中加密数据的可访问性,并由模型转换管理。这确保了您的敏感数据被安全存储。
贡献
欢迎贡献,任何贡献者都必须遵守项目的行为准则和许可条款。
支持
对于支持,请在此 GitHub 存储库中提交问题。
许可
此项目是开源软件,许可协议为 MIT 许可。
