knone/translate-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

knone/translate-bundle

Composer 安装命令:

composer require knone/translate-bundle

包简介

Translate bundle

README 文档

README

This bundle for Symfony2 applications, which translate some text in your application using different translator-services

Latest Stable Version Total Downloads License

Build Status Scrutinizer Code Quality

Installation

Download using composer:

php composer.phar require knone/translate-bundle '1.0.*'

Enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new KNone\TranslateBundle\KNoneTranslateBundle(),
    );
}

Configure the KNoneTranslateBundle

KNoneTranslateBundle have two translator-providers:

  1. google_web (use http://translate.google.com)
  2. yandex_api (http://api.yandex.com/translate/)

You need to set default provider in config.yml:

//app/config/config.yml
k_none_translate:
    default_provider: google_web

If you want to use Yandex Api you need set api key (get api key):

//app/config/config.yml
k_none_translate:
    default_provider: yandex_api
    providers:
        yandex_api:
            key: <api_key>

Using the KNoneTranslateBundle

You just can use service k_none_translate.translator. Example:

<?php
...
// Some action in controller
public function someAction()
{
    /** @var KNone\TranslateBundle\Provider\ProviderInterface $translator */
    $translator = $this->get('k_none_translate.translator');
    $translation = $translator->translate('hello world', 'en', 'fr');
    // you can set 'auto' as source language and translator will detect it
    //$translation = $translator->translate('hello world', 'auto', 'fr');

    $result = (string)$translation; // $result contains 'bonjour tout le monde'
    $result = $translation->getResult(); // $result contains 'bonjour tout le monde'
    $source = $translation->getSource(); // $source contains 'hello world'
    $sourceLanguage = $translation->getSourceLanguage() // $sourceLanguage contains 'en'
    $resultLanguage = $translation->getResultLanguage() // $resultLanguage contains 'fr'
}

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-06-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固