toriskint / auto-translate
4.0
2023-12-19 15:25 UTC
Requires
README
此软件包为您提供了一个简单的方法来自动生成翻译PHP文件。翻译是通过使用基于 stichoza/google-translate-php
包的Google翻译自动生成的,并使用 kkomelin/laravel-translatable-string-exporter
包从源代码中导出翻译字符串。
安装
您可以通过composer安装此软件包
composer require torskint/auto-translate
将包提供者添加到您的 config/app.php
文件中
//... 'providers' => [ // ... \Torskint\AutoTranslate\AutoTranslateServiceProvider::class, ], // ...
必需:您需要发布包配置文件,以便可以更新 base_locale
和 locales
列表
php artisan vendor:publish --tag=auto-translate-config
完成,您可以使用包命令生成缺失的翻译并自动使用Google翻译进行翻译
配置
此软件包的配置文件如下所示
<?php return [ /* * * Locales managed by auto-translation package, will be used by the * command "auto:translate" to generate a JSON file for each of this * locales, and by the command "translate:missing" to generate their * missing translations * */ 'locales' => [ 'en', 'de', 'ar' ], /* * * The base locale to use when using the command "translate:missing" to * generate missing translations for other JSON files * */ 'base_locale' => 'fr' ];
我认为它有很好的文档说明,我将让您自己检查。
用法
自动翻译生成
要从源代码生成翻译文件 torskint/*,您可以执行以下命令:要生成缺失的翻译,您可以执行以下命令
php artisan ts-translate:translate
要删除所有不带基础文件的翻译文件,请执行以下命令
php artisan ts-translate:reset
请确保要替换的单词数量(WEBSITE_NAME, %s, WEBSITE_URL, 等)与每个目标语言文件中的数量相匹配。
php artisan ts-translate:count
这些命令将检查您的配置 auto-translate.locales
,为列表中的每个区域生成基于源代码(@lang()
,__()
,...)的JSON文件,并根据Google翻译将字符串翻译成所需的区域。
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。