Skip to content
Adapter to integrate PhraseApp into a Symfony2 application
Branch: master
Clone or download
Latest commit e1c3516 Nov 13, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
Acme/YourBundle/Translation Improved PhraseTranslator Nov 1, 2013
LICENSE Update Nov 13, 2018

PhraseApp In-Context Editor for Symfony2

The Symfony2 adapter lets you to connect the PhraseApp In-Context Editor to your Symfony2 application.

For more information, read the documentation.


We recommend creating a new environment in which the In-Context Editor is available. Let's call the new environment "translation":

Start by creating a new configuration file:

# app/config/config_translation.yml
    - { resource: config.yml }
    translator.class: Acme\YourBundle\Translation\PhraseTranslator

The environment should be accessible in the browser, so we should create a front controller for it:

# web/app_translation.php

require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';

use Symfony\Component\HttpFoundation\Request;

$kernel = new AppKernel('translation', false);

Add the "PhraseTranslator" class to your bundle. It will override the standard translation method to expose the translation keys to the In-Context Editor.

When everything is in place, add the JavaScript snippet to your layout:

# Acme/YourBundle/Resources/views/layout.html.twig
{% if app.environment == 'translation' %}
    projectId: "YOUR-PROJECT-ID"
(function() {
    var phraseapp = document.createElement('script'); phraseapp.type = 'text/javascript'; phraseapp.async = true;
    phraseapp.src = ['https://', '', new Date().getTime()].join('');
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phraseapp, s);
{% endif %}

You can find your Project-ID in the PhraseApp Translation Center.

Your application is connected to the In-Context Editor. Reload your application to start the translation process!

More Information

The code in this tutorial was originally created by Malte Marx from marxbeck

You can’t perform that action at this time.