Translate bundle

v1.0.0 2014-06-29 16:38 UTC


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


Download using composer:

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

Enable the bundle in the kernel:

// app/AppKernel.php

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

Configure the KNoneTranslateBundle

KNoneTranslateBundle have two translator-providers:

  1. google_web (use
  2. yandex_api (

You need to set default provider in config.yml:

    default_provider: google_web

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

    default_provider: yandex_api
            key: <api_key>

Using the KNoneTranslateBundle

You just can use service k_none_translate.translator. Example:

// 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'