Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
an edit-in-place, i18n translator bundle for Symfony2
PHP JavaScript
branch: master
Failed to load latest commit information.
Controller handle multiple trans tags on a DOM element nodeValue and its attribu…
DependencyInjection added a enabled option
Exception changed namespace to Knp
Features changed namespace to Knp
Listener Edited Listener/ResponseListener.php via GitHub
Resources added optional highlight of untranslated strings
Templating fixed break with twin node visitor
Tests using templating to wrap trans texts; see #7
.gitignore introduced .gitignore
LICENSE added license fix typo; close #18
composer.json Add composer.json


This bundle's purpose is to provide an interface for edition, addition and deletion of translations messages.

Currently supported formats:

  • YAML
  • CSV

Install & setup the bundle

  1. Fetch the source code

    Using Git to control your project from project root directory:

    git submodule add git:// vendor/bundles/Knp/Bundle/TranslatorBundle

    By cloning repository:

    mkdir -p vendor/bundles/Knp/Bundle
    cd !$
    git clone git://

    By including into deps file:

  2. Add the bundle to your AppKernel class

    // app/AppKernerl.php
    public function registerBundles()
        $bundles = array(
            // ...
            new Knp\Bundle\TranslatorBundle\KnpTranslatorBundle,
            // ...
        // ...
  3. Add the Knp namespace to your autoloader

    // app/autoload.php
        'Knp' => __DIR__.'/../vendor/bundles',
        // your other namespaces
  4. Add routing

    // app/config/routing.yml
        resource: @KnpTranslatorBundle/Resources/config/routing/edition.yml
            prefix:   /trans/admin
        resource: @KnpTranslatorBundle/Resources/config/routing/routing.yml
            prefix:   /trans

These route files provide the following routes:

[router] Current routes
Name                     Method  Pattern
knplabs_translator_list  GET    /trans/admin/list
knplabs_translator_get   GET    /trans/{id}/{domain}/{locale}
knplabs_translator_put   PUT    /trans/

Minimal configuration

This bundle requires the activation of the core translator:

``` yaml

// app/config/config.yml
    # ...
    translator:    { fallback: en }
    # ...


Additional configuration

This bundle relies on the Ext Core library. You can decide wheter or not it will be included automatically.

``` yaml

    include_vendor_assets: false # defaults to true



This bundle introduces those services:

translator.dumper.csv                    container Knp\Bundle\TranslatorBundle\Dumper\CsvDumper
translator.dumper.xliff                  container Knp\Bundle\TranslatorBundle\Dumper\XliffDumper
translator.dumper.yaml                   container Knp\Bundle\TranslatorBundle\Dumper\YamlDumper
translator.writer                        container Knp\Bundle\TranslatorBundle\Translation\Translator

controllers are services too:

knplabs_translator.controller.edition    request   Knp\Bundle\TranslatorBundle\Controller\EditionController
knplabs_translator.controller.translator request   Knp\Bundle\TranslatorBundle\Controller\TranslatorController


``` php

class Knp\Bundle\TranslatorBundle\Translation\Translator extends Symfony\Bundle\FrameworkBundle\Translation\Translator

    public function isTranslated($id, $domain, $locale);

    public function update($id, $value, $domain, $locale);

    public function getResources($locale, $domain);

    public function getFallbackLocale();

    public function getCatalog($locale);

    public function getLocales();

    public function all();


Updating a given translation key is really simple:

``` php

$this->get('translator.writer')->update('the key to translate', 'the translated string', 'messages', 'en');


Rest API

  • Update english translations files for domain tests with translated value for key

    curl -X PUT http://project-url/trans/  \
        -F '' \
        -F 'domain=messages' \
        -F 'locale=en' \
        -F 'value=translate value' 
  • Get the translated value of key for english locale for tests domain

    curl http://project-url/trans/
Something went wrong with that request. Please try again.