weasty/exercise-google-translate-bundle

此包包含使用Google Translate进行翻译的服务,以及将消息翻译为你的包中的命令

安装: 27

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 7

类型:symfony-bundle

v1.0 2016-02-15 15:26 UTC

This package is not auto-updated.

Last update: 2024-09-20 17:32:51 UTC


README

关于包

此包包含使用Google Translate进行翻译的服务,以及将消息翻译为你的包中的命令

安装

A) 将GoogleTranslateBundle添加到你的composer.json文件中

{
    "require": {
        "exercise/google-translate-bundle": "*"
    }
}

B) 启用包

在kernel中启用包

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Exercise\GoogleTranslateBundle\ExerciseGoogleTranslateBundle(),
    );
}

C) 配置

在配置中输入你的私有API密钥

# app/config/config.yml
exercise_google_translate:
    api_key: your_api_key

使用

你可以将其用作服务

// Acme/DemoBundle/Controller/WelcomeController.php

public function indexAction() {

    ...

    $translator = $this->get('exercise_google_translate.translator');
    $translatedString = $translator->translate('Hello World!', 'en', 'fr');

    // Bonjour tout le monde!
    return new Response($translatedString);
}

或者你可以使用控制台命令来翻译消息

app/console gtranslate:translate en fr AcmeDemoBundle

错误跟踪

GoogleTranslateBundle使用GitHub issues。如果您发现了错误,请创建一个问题。

许可证

此包遵循MIT许可证。请参阅LICENSE.md文件中的完整许可证。

License