<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dkesberg / slim-twig-translation-extension example snippets
$view->parserExtensions = array(
new \Dkesberg\Slim\Twig\Extension\TranslationExtension(),
);
use Illuminate\Translation\Translator;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Translation\FileLoader;
$translator = new Translator(new FileLoader(new Filesystem(), __DIR__ . '/lang'), 'en');
$translator->setFallback('en');
$app->translator = $translator;
use Illuminate\Translation\Translator;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Translation\FileLoader;
$app->container->singleton('translator', function() {
return new Translator(new FileLoader(new Filesystem(), __DIR__ . '/lang'), 'en');
});
$app->translator->setFallback('en');
use Illuminate\Translation\Translator;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Translation\FileLoader;
// detect language and set translator
$app->hook('slim.before', function() use ($app) {
$env = $app->environment();
// Extract locale
$locale = Locale::acceptFromHttp($env['HTTP_ACCEPT_LANGUAGE']);
$app->locale = substr($locale,0,2);
// Set translator instance
$app->container->singleton('translator', function($app) {
return new Translator(new FileLoader(new Filesystem(), __DIR__ . '/lang'), $app->locale);
});
$app->translator->setFallback('en');
});