mmoreram / translation-server
PHP翻译服务器
Requires
- php: >=7.1
- stichoza/google-translate-php: ^3.1
- symfony/console: ^3.2
- symfony/event-dispatcher: ^3.2
- symfony/filesystem: ^3.2
- symfony/finder: ^3.2
- symfony/process: ^3.2
- symfony/property-access: ^3.2
- symfony/stopwatch: ^3.2
- symfony/yaml: ^3.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.12.4
- mmoreram/php-formatter: ^1.3.1
- phpunit/phpunit: ^5.6.4
This package is auto-updated.
Last update: 2024-08-29 03:21:05 UTC
README
本翻译服务器旨在为项目提供一种非常简单、直观且快速的方式添加新的翻译,遵循Symfony标准,并使用控制台作为界面。
标签
安装
以这种方式安装Translation Server
$ composer global require mmoreram/translation-server=dev-master
如果您是第一次全局安装依赖项,请确保将~/.composer/vendor/bin
添加到$PATH中,如此处所示。
始终确保Translation Server安装更新
$ composer global update mmoreram/translation-server
.phar文件
您还可以使用已构建的最新.phar
。
$ git clone git@github.com:mmoreram/translation-server.git
$ cd translation-server
$ php build/translation-server.phar
您可以将.phar
文件作为全局脚本复制
$ cp build/translation-server.phar /usr/local/bin/translation-server
编译
最后,您还可以编译自己版本的包。(您需要在php.ini中设置phar.readonly = Off
)。
$ git clone git@github.com:mmoreram/translation-server.git
$ cd translation-server
$ composer update
$ php bin/compile
$ sudo chmod +x build/translation-server.phar
$ build/translation-server.phar
您可以将.phar
文件作为全局脚本复制
$ cp build/translation-server.phar /usr/local/bin/translation-server
配置
如果您的项目希望支持本项目,请确保在一个名为.translation.yml
的文件中放置有关翻译位置、主语言以及您支持哪些语言的定义。
此文件具有以下格式(无需解释,对吧?^^)
master_language: en languages: - en - es - ca - fr - de - it - fi - eu - gl - eo - nl paths: - src/Folder/*/Resources/translations
您还可以使用--config|-c
选项定义搜索.translation.yml
文件的位置
$ translation-server translation:server:view --config="src/"
命令
此服务器提供了一组对项目有用的命令。让我们逐个查看这些命令。
Console Tool Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages --version -V Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction -n Do not ask any interactive question. Available commands: help Displays help for a command list Lists commands translation translation:server:add Add new translation translation:server:sort Sort translations translation:server:view View statics about the server
翻译统计
您可以通过此命令查看所有翻译统计。在没有额外配置的情况下,您将能够查看项目的所有统计。
$ translation-server translation:server:view [Trans Server] Command started at Thu, 08 Oct 2015 00:52:41 +0200 [Trans Server] Translations for [en] is 100% completed. 0 missing [Trans Server] Translations for [ca] is 99.57% completed. 4 missing [Trans Server] Translations for [es] is 99.57% completed. 4 missing [Trans Server] Translations for [fr] is 78.34% completed. 203 missing [Trans Server] Translations for [de] is 68.84% completed. 292 missing [Trans Server] Translations for [it] is 0.11% completed. 936 missing [Trans Server] Translations for [nl] is 0% completed. 937 missing [Trans Server] Translations for [eo] is 0% completed. 937 missing [Trans Server] Translations for [gl] is 0% completed. 937 missing [Trans Server] Translations for [eu] is 0% completed. 937 missing [Trans Server] Translations for [fi] is 0% completed. 937 missing [Trans Server] Command finished in 932 milliseconds [Trans Server] Max memory used: 13893632 bytes
按语言过滤
您可以使用所有命令中的[--language|-l]选项按语言过滤所有结果。这只是一个掩码,因此如果您定义一个或多个语言,将简单地掩码所有提供给您的结果。
$ translation-server translation:server:view --language es -l ca [Trans Server] Command started at Thu, 08 Oct 2015 00:54:09 +0200 [Trans Server] Translations for [en] is 100% completed. 0 missing [Trans Server] Translations for [ca] is 99.57% completed. 4 missing [Trans Server] Translations for [es] is 99.57% completed. 4 missing [Trans Server] Command finished in 917 milliseconds [Trans Server] Max memory used: 13893632 bytes
如您所见,您可以提供多个语言
按域过滤
您可以使用所有命令中的[--domain|-d]选项按域过滤所有结果。这只是一个掩码,因此如果您定义一个或多个域,将简单地掩码所有提供给您的结果。
$ translation-server translation:server:view --domain routes [Trans Server] Command started at Thu, 08 Oct 2015 00:56:16 +0200 [Trans Server] Translations for [de] is 100% completed. 0 missing [Trans Server] Translations for [en] is 100% completed. 0 missing [Trans Server] Translations for [ca] is 100% completed. 0 missing [Trans Server] Translations for [es] is 100% completed. 0 missing [Trans Server] Translations for [eo] is 0% completed. 38 missing [Trans Server] Translations for [nl] is 0% completed. 38 missing [Trans Server] Translations for [gl] is 0% completed. 38 missing [Trans Server] Translations for [it] is 0% completed. 38 missing [Trans Server] Translations for [fr] is 0% completed. 38 missing [Trans Server] Translations for [fi] is 0% completed. 38 missing [Trans Server] Translations for [eu] is 0% completed. 38 missing [Trans Server] Command finished in 842 milliseconds [Trans Server] Max memory used: 13369344 bytes
您也可以提供多个域,甚至可以混合语言和域。
请求新翻译
这个工具的强大之处在于,只需告诉您希望使用哪种语言,工具就会交互式地询问一些翻译。
让我们看一个例子。在这种情况下,我们将请求一些巴斯克语的翻译,但我们只想添加标记为routes
的路线翻译。
$ translation-server translation:server:add --language eu --domain routes [Trans Server] Command started at Thu, 08 Oct 2015 00:59:43 +0200 [Trans Server] Language : eu [Trans Server] Key : store_cart_nav [Trans Server] Original : /cart/nav [Trans Server] Translation : []
此时,提示将等待您的响应。一旦您输入了翻译,只需按Enter键,您的翻译就会被存储在其位置。
这意味着如果必须创建新文件以存储您的翻译,例如如果您正在创建新语言,则该过程将创建它。
$ translation-server translation:server:add --language eu --domain routes [Trans Server] Command started at Thu, 08 Oct 2015 00:59:43 +0200 [Trans Server] Language : eu [Trans Server] Key : store_cart_nav [Trans Server] Original : /cart/nav [Trans Server] Translation : /saskia/nab [Trans Server] Command started at Thu, 08 Oct 2015 01:00:25 +0200 [Trans Server] Language : eu [Trans Server] Key : store_checkout_address [Trans Server] Original : /cart/address [Trans Server] Translation : []
一旦值被保存,系统将请求另一个翻译。只要您不按Ctrl+C,系统就会一次又一次地请求。
猜测缺失的翻译
对于懒惰的人来说,你甚至可以使用谷歌翻译来翻译你的网站。当然,我们强烈建议你小心使用此功能,并在翻译后进行检查。
$ translation-server translation:server:guess --language eu [Trans Server] Command started at Thu, 08 Oct 2015 00:59:43 +0200 [Trans Server] Language : eu [Trans Server] Key : store_cart_nav [Trans Server] Original : /cart/nav [Trans Server] Translation : /saskia/nab
该命令将开始猜测你的缺失翻译,直到你决定使用Ctrl+C停止。
该项目使用库Stichoza/google-translate-php。简单易用。非常感谢!
当然,你可以通过语言和域名进行筛选。
排序翻译
你也可以使用这个优秀的命令来对所有翻译进行排序。
$ translation-server translation:server:sort
[Trans Server] Command started at Thu, 08 Oct 2015 01:06:15 +0200
[Trans Server] Your translations have been sorted successfuly
[Trans Server] Command finished in 1288 milliseconds
[Trans Server] Max memory used: 13631488 bytes
再次提醒,你可以通过语言和域名进行筛选。