Add translateability
This commit is contained in:
parent
b017306382
commit
f687ce8e1e
4 changed files with 121 additions and 21 deletions
25
index.php
25
index.php
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
$app = new Silex\Application();
|
||||
|
||||
$app['debug'] = true;
|
||||
|
@ -9,15 +11,26 @@ $app->register(new Silex\Provider\TwigServiceProvider(), array(
|
|||
'twig.path' => __DIR__.'/templates',
|
||||
));
|
||||
|
||||
$app->get('/', function () use ($app) {
|
||||
return $app['twig']->render('index.twig', array(
|
||||
));
|
||||
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
|
||||
'locale_fallback' => 'de',
|
||||
));
|
||||
|
||||
$app['translator'] = $app->share($app->extend('translator', function($translator, $app) {
|
||||
$translator->addResource('xliff', __DIR__.'/locales/de.xml', 'de');
|
||||
$translator->addResource('xliff', __DIR__.'/locales/en.xml', 'en');
|
||||
|
||||
return $translator;
|
||||
}));
|
||||
|
||||
$app->before(function(Request $request) use ($app){
|
||||
$lang = $request->getPreferredLanguage(array('en', 'de'));
|
||||
$app['translator']->setLocale($lang);
|
||||
});
|
||||
|
||||
$app->post('/', function () use ($app) {
|
||||
return $app['twig']->render('index.twig', array(
|
||||
$app->get('/', function (Request $request) use ($app) {
|
||||
return $app['twig']->render('registration_form.twig', array(
|
||||
'errors' => array(),
|
||||
));
|
||||
});
|
||||
|
||||
|
||||
$app->run();
|
||||
|
|
Reference in a new issue