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

README.md

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.

Installation

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
imports:
    - { resource: config.yml }
parameters:
    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
<?php

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

use Symfony\Component\HttpFoundation\Request;

$kernel = new AppKernel('translation', false);
$kernel->handle(Request::createFromGlobals())->send();

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' %}
<script>
window.PHRASEAPP_CONFIG = {
    projectId: "YOUR-PROJECT-ID"
};
(function() {
    var phraseapp = document.createElement('script'); phraseapp.type = 'text/javascript'; phraseapp.async = true;
    phraseapp.src = ['https://', 'phraseapp.com/assets/in-context-editor/2.0/app.js?', new Date().getTime()].join('');
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phraseapp, s);
})();
</script>
{% 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.