krushnaghodke/translation-bundle

一个帮助使用Yandex API进行翻译的symfony2 bundle

安装: 3

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

类型:symfony-bundle

dev-master 2024-03-04 19:47 UTC

This package is not auto-updated.

Last update: 2024-09-25 01:57:26 UTC


README

一个利用Yandex API进行字符串翻译的包。目前,它仅支持Yandex翻译服务。未来计划集成Google翻译API。

安装

要在您的Symfony2项目中使用此bundle,请将以下内容添加到您的 composer.json

{
    "require": {
        // ...
       "krushnaghodke/translation-bundle": "dev-master"
    }
}

然后,您可以通过在您的 composer.json 文件所在目录运行Composer的 update 命令来安装新的依赖项

.. code-block :: bash

$ php composer.phar install

现在,Composer将自动下载所有必需的文件,并为您安装它们。剩下的只是更新您的 AppKernel.php 文件,并注册新的bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
       new Krushnaghodke\TranslationBundle\KrushnaghodkeTranslationBundle(),
    );
}

配置

在config.yml中更新以下代码。

# app/config.yml
krushnaghodke_translation:
    api_key: %yandex_api_key%

用法

以下是一个使用Yandex API翻译初始字符串的简要演示。假设配置已经正确设置

<?php

$translation = $this->get('krushnaghodke.translation.manager');
$result = $translation->translate("This is testing string", 'en-hi');