Example #1
1
 /**
  * Translates definition regex to provided language (if possible).
  *
  * @param   string  $regex      regex to translate
  * @param   string  $language   language
  *
  * @return  string
  */
 public function translateDefinitionRegex($regex, $language)
 {
     return $this->translator->trans($regex, array(), 'behat.definitions', $language);
 }
Example #2
0
 public function initExtension($extension, \Twig_Environment $render, \Twig_Loader_Filesystem $fileSystemLoader)
 {
     if (false === strpos($extension, "\\")) {
         $extension = "\\" . $extension;
     }
     $config = $this->getConfig();
     switch ($extension) {
         case "\\TranslationExtension":
             $config = isset($config["translationExtension"]) ? $config["translationExtension"] : [];
             $lang = isset($config["lang"]) ? $config["lang"] : "ru";
             $locale = isset($config["locale"]) ? $config["locale"] : "ru_RU";
             $translator = new \Symfony\Component\Translation\Translator($locale);
             $translator->addLoader('xlf', new \Symfony\Component\Translation\Loader\XliffFileLoader());
             $vendorFormDir = VENDOR_DIR . '/symfony/form/Symfony/Component/Form';
             $vendorValidatorDir = VENDOR_DIR . '/symfony/validator/Symfony/Component/Validator';
             $translator->addResource('xlf', $vendorFormDir . "/Resources/translations/validators.{$lang}.xlf", $locale, 'validators');
             $translator->addResource('xlf', $vendorValidatorDir . "/Resources/translations/validators.{$lang}.xlf", $locale, 'validators');
             $extension = new \Symfony\Bridge\Twig\Extension\TranslationExtension($translator);
             break;
         case "\\FormExtension":
             $config = isset($config["formExtension"]) ? $config["formExtension"] : [];
             $templates = $config["templates"] ?: "/vendor/symfony/twig-bridge/Resources/views/Form";
             $templates = $this->getRootDir() . "/" . $templates;
             $fileSystemLoader->addPath($templates);
             $formTemplate = $config["formTheme"] ?: "form_div_layout.html.twig";
             $formTemplate = (array) $formTemplate;
             $formEngine = new \Symfony\Bridge\Twig\Form\TwigRendererEngine($formTemplate);
             $formEngine->setEnvironment($render);
             $extension = new \Symfony\Bridge\Twig\Extension\FormExtension(new \Symfony\Bridge\Twig\Form\TwigRenderer($formEngine, $this->getFormCsrfProvider()));
             break;
         default:
             $extension = new $extension();
     }
     return $extension;
 }
Example #3
0
 /** @test */
 public function it_can_validate_the_user_and_database_data()
 {
     $translator = new \Symfony\Component\Translation\Translator('en', new \Symfony\Component\Translation\MessageSelector());
     $translator->addLoader('array', new \Symfony\Component\Translation\Loader\ArrayLoader());
     $translator->addResource('array', ['validation.required' => ':attribute is required!'], 'en', 'messages');
     $this->app['validator'] = new \Illuminate\Validation\Factory($translator);
     $this->assertCount(3, $this->installer->validate());
 }
Example #4
0
/**
 * @param Symfony\Component\Translation\Translator $translator
 * @return null|string
 */
function drawRequirements($translator)
{
    $requirements = getRequirements();
    $html = null;
    $html .= '<tr>
                <td>
                    ' . $translator->trans('Required') . '
                </td>
                <td>
                </td>
              </tr>';
    foreach ($requirements['required'] as $extension => $req) {
        $checkExtension = check_extension($extension, $translator->trans('Yes'), $translator->trans('No'));
        $html .= '<tr>
                    <td>
                        <a href="' . $req['url'] . '">' . $extension . '</a>
                    </td>
                    <td>
                        ' . $checkExtension . '
                    </td>
                  </tr>';
    }
    $html .= '<tr>
                <td>
                    ' . $translator->trans('Optional') . '
                </td>
                <td>
                </td>
              </tr>';
    foreach ($requirements['optional'] as $extension => $req) {
        $checkExtension = check_extension($extension, $translator->trans('Yes'), $translator->trans('No'));
        $html .= '<tr>
                    <td>
                        <a href="' . $req['url'] . '">' . $extension . '</a>
                    </td>
                    <td>
                        ' . $checkExtension . '
                    </td>
                  </tr>';
    }
    return $html;
}
Example #5
0
#!/usr/bin/php
<?php 
$config = ['git_urls' => ['https://github.com/symfony/Translation.git' => 'sf_translation/'], 'autoload_config' => ['sf_translation/' => 'Symfony\\Component\\Translation'], 'example' => function () {
    $translator = new \Symfony\Component\Translation\Translator('fr_FR', new Symfony\Component\Translation\MessageSelector());
    $translator->setFallbackLocales(['fr']);
    $translator->addLoader('array', new Symfony\Component\Translation\Loader\ArrayLoader());
    $translator->addResource('array', ['Hello World!' => 'Bonjour'], 'fr');
    echo $translator->trans('Hello World!') . "\n";
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);
    $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
    return $conn;
};
$c['doctrine.entity_manager'] = function ($c) {
    $isDevMode = true;
    $config = \Doctrine\ORM\Tools\Setup::createConfiguration($isDevMode);
    // This can also set cache or other things
    $config->addEntityNamespace('Eng', 'Eng\\Core\\Repository\\Entity');
    $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(new \Doctrine\Common\Annotations\AnnotationReader(), $c['res_dir'] . '/logs');
    \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
    $config->setMetadataDriverImpl($driver);
    $entityManager = \Doctrine\ORM\EntityManager::create($c['db.eng'], $config);
    return $entityManager;
};
$c['translator'] = function ($c) {
    $translator = new \Symfony\Component\Translation\Translator('en');
    $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
    $translator->addResource('yaml', $c['res_dir'] . '/lang/cn.yml', 'cn');
    $translator->addResource('yaml', $c['res_dir'] . '/lang/jpa.yml', 'jap');
    $translator->setLocale('cn');
    return $translator;
};
$c['wordVoiceDownloader'] = function ($c) {
    $wordVoiceDownloader = new \Eng\Core\Module\Words\Voice\VoiceDownloader($c['log.main'], $c['voice_save_path'] . '/words');
    $wordVoiceDownloader->addVendor(new \Eng\Core\Module\Words\Voice\Vendor\Google());
    $wordVoiceDownloader->addVendor(new \Eng\Core\Module\Words\Voice\Vendor\Merriam());
    $wordVoiceDownloader->addVendor(new \Eng\Core\Module\Words\Voice\Vendor\YouDao());
    //$wordVoiceDownloader->addVendor(new \Eng\Core\Module\Words\Voice\Vendor\JinShan());
    $wordVoiceDownloader->addVendor(new \Eng\Core\Module\Words\Voice\Vendor\CamBridge());
    return $wordVoiceDownloader;
};
Example #7
0
<?php

// Prepare view
$app->view(new \Slim\Views\Twig());
$app->view->parserOptions = array('charset' => 'utf-8', 'cache' => false, 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
$app->view->parserExtensions = array(new \Slim\Views\TwigExtension(), new ExtendedTwig());
// Prepare singletons
$app->container->singleton('session', function () use($app) {
    return new SessionManager($app->getMode());
});
$app->container->singleton('translator', function () {
    $trans = new Symfony\Component\Translation\Translator('es');
    $trans->addLoader('php', new Symfony\Component\Translation\Loader\PhpFileLoader());
    $trans->addResource('php', __DIR__ . '/../locales/es.php', 'es');
    return $trans;
});
$app->api = false;
// Prepare error handler
$app->error(function (Exception $e) use($app) {
    if ($app->api) {
        // TODO setar codigo de error correcto.
        $msg = array('code' => $e->getCode(), 'message' => $e->getMessage());
        if ($e instanceof TurnbackException) {
            $msg['errors'] = $e->getErrors();
        }
        echo json_encode($msg);
    } else {
        if ($e instanceof TurnbackException) {
            $app->flash('errors', $e->getErrors());
            ob_end_clean();
            $app->redirect($app->request->getReferrer());
Example #8
0
 protected function getRealValidator()
 {
     $trans = new \Symfony\Component\Translation\Translator('en', new \Symfony\Component\Translation\MessageSelector());
     $trans->addLoader('array', new \Symfony\Component\Translation\Loader\ArrayLoader());
     return new IlluminateValidator($trans);
 }
Example #9
0
if (file_exists(__DIR__ . "/config/config.php")) {
    require_once __DIR__ . "/config/config.php";
} else {
    throw new Exception("config.php not found (you might wanna start by copying config_new.php)");
}
// Init Slim
$app = new \Seriis\SeriisApp($config["slim"]);
// Session
$session = new SessionHandler();
session_set_save_handler($session, true);
session_cache_limiter(false);
session_start();
// Launch Whoops
$app->add(new WhoopsMiddleware());
// Load the translator
$translator = new \Symfony\Component\Translation\Translator("en_US", new \Symfony\Component\Translation\MessageSelector());
$translator->setFallbackLocales(array("en_US"));
$translator->addLoader("php", new \Symfony\Component\Translation\Loader\PhpFileLoader());
$languageFiles = glob(__DIR__ . "/lang/*.php");
foreach ($languageFiles as $langFile) {
    $translator->addResource("php", $langFile, str_replace(".php", "", basename($langFile)));
}
// Prepare view
$app->view(new Twig());
$app->view->parserExtensions = array(new \Slim\Views\TwigExtension(), new \Symfony\Bridge\Twig\Extension\TranslationExtension($translator));
$app->view->parserOptions = $config['twig'];
// Load the lib/Model loader
if (file_exists(__DIR__ . "/src/Loader.php")) {
    require_once __DIR__ . "/src/Loader.php";
} else {
    throw new Exception("Loader.php could not be found");
Example #10
0
<?php

return ['event_manager' => \DI\decorate(function ($eventManager, $container) {
    $eventManager->attach('ERROR_DISPATCH', [$container->get(\ClassicApp\EventListener\DispatcherExceptionListener::class), 'onError']);
    $eventManager->attach('*', [$container->get(\ClassicApp\EventListener\ExceptionListener::class), 'onError']);
    return $eventManager;
}), \ClassicApp\EventListener\ExceptionListener::class => \DI\object(\ClassicApp\EventListener\ExceptionListener::class)->constructor(\DI\get('template')), \ClassicApp\EventListener\DispatcherExceptionListener::class => \DI\object(\ClassicApp\EventListener\DispatcherExceptionListener::class)->constructor(\DI\get('template')), 'dispatcher' => \DI\factory(function (\DI\Container $c) {
    $dispatcher = new \ClassicApp\Dispatcher\SymfonyDispatcher($c->get('router'));
    return $dispatcher;
}), 'session' => \DI\factory(function (\DI\Container $c) {
    $session = new \Symfony\Component\HttpFoundation\Session\Session();
    $session->start();
    return $session;
}), 'translator' => \DI\factory(function () {
    $translator = new \Symfony\Component\Translation\Translator('en_US', new \Symfony\Component\Translation\MessageSelector());
    $translator->addLoader('php', new \Symfony\Component\Translation\Loader\PhpFileLoader());
    $translator->addResource('php', './app/Resources/translator/en_US.php', 'en_US');
    $translator->addResource('php', './app/Resources/translator/it_IT.php', 'it_IT');
    return $translator;
}), 'template' => \DI\factory(function (\DI\Container $c) {
    $twigBridgeViews = __DIR__ . '/../vendor/symfony/twig-bridge/Resources/views/Form';
    $loader = new Twig_Loader_Filesystem([$twigBridgeViews, './app/Resources/view']);
    $twig = new Twig_Environment($loader, $c->get('parameters')['twig']['loader_options']);
    $twig->addGlobal('show_exception_backtrace', $c->get('parameters')['twig']['show_exception_backtrace']);
    $twig->addGlobal('session', $c->get('session'));
    $formEngine = new \Symfony\Bridge\Twig\Form\TwigRendererEngine(['bootstrap_3_layout.html.twig']);
    $formEngine->setEnvironment($twig);
    $formExt = new \Symfony\Bridge\Twig\Extension\FormExtension(new \Symfony\Bridge\Twig\Form\TwigRenderer($formEngine));
    $twig->addExtension($formExt);
    $transExt = new \Symfony\Bridge\Twig\Extension\TranslationExtension($c->get('translator'));
    $twig->addExtension($transExt);
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('source', 'text')->add('destination', 'text')->add('statusCode', 'choice', array('choices' => array(301 => $this->trans->trans('status.301', array(), 'Redirect'), 307 => $this->trans->trans('status.307', array(), 'Redirect'), 308 => $this->trans->trans('status.308', array(), 'Redirect'))))->add('enabled', 'checkbox');
 }
 /**
  * Sets geolocation options
  *
  * @param point                                    $latitude    Latitude
  * @param point                                    $longitude   Longitude
  * @param array                                    $geoLocation Geolocation data
  * @param Symfony\Component\Translation\Translator $translator  Translator
  *
  * @return void|RedirectResponse
  */
 private function geolocation($latitude, $longitude, $geoLocation, $translator)
 {
     $preferencesService = $this->container->get('system_preferences_service');
     if ($latitude > 90 || $latitude < -90 || $longitude > 180 || $longitude < -180) {
         $this->get('session')->getFlashBag()->add('error', $translator->trans('newscoop.preferences.error.geolocation', array(), 'system_pref'));
         return $this->redirect($this->generateUrl('newscoop_newscoop_systempref_index'));
     } else {
         $preferencesService->MapCenterLatitudeDefault = $latitude;
         $preferencesService->MapCenterLongitudeDefault = $longitude;
     }
     foreach ($geoLocation as $key => $value) {
         $name = '';
         foreach (explode('_', $key) as $part) {
             $name .= ucfirst($part);
             $preferencesService->{$name} = $value;
         }
     }
 }
 protected function getRealTranslator()
 {
     $trans = new Symfony\Component\Translation\Translator('en', new Symfony\Component\Translation\MessageSelector());
     $trans->addLoader('array', new Symfony\Component\Translation\Loader\ArrayLoader());
     return $trans;
 }
Example #14
0
// Initialisation de Smarty
require_once dirname(__FILE__) . '/../../dependencies/smarty/Smarty.class.php';
$smarty = new Smarty();
$smarty->template_dir = array(dirname(__FILE__) . '/../../htdocs/templates/' . $sous_site . '/', dirname(__FILE__) . '/../../htdocs/templates/commun/');
$smarty->compile_dir = dirname(__FILE__) . '/../../htdocs/cache/templates';
$smarty->compile_id = $sous_site;
$smarty->use_sub_dirs = true;
$smarty->check_compile = true;
$smarty->php_handling = SMARTY_PHP_ALLOW;
$smarty->assign('url_base', 'http://' . $_SERVER['HTTP_HOST'] . '/');
$smarty->assign('chemin_template', $serveur . $conf->obtenir('web|path') . 'templates/' . $sous_site . '/');
$smarty->assign('chemin_javascript', $serveur . $conf->obtenir('web|path') . 'javascript/');
// Initialisation de la couche d'abstraction de la base de données
require_once dirname(__FILE__) . '/../../sources/Afup/AFUP_Base_De_Donnees.php';
$bdd = new AFUP_Base_De_Donnees($conf->obtenir('bdd|hote'), $conf->obtenir('bdd|base'), $conf->obtenir('bdd|utilisateur'), $conf->obtenir('bdd|mot_de_passe'));
$bdd->executer("SET NAMES 'utf8'");
// Inclusion de la classe permettant l envoi de mail
require_once dirname(__FILE__) . '/../../sources/Afup/AFUP_Mailing.php';
// Inclusion de l'autoload de composer
require_once dirname(__FILE__) . '/../../vendor/autoload.php';
// Configuration du composant de traduction
$lang = 'fr';
$langs = ['fr', 'en'];
if (isset($_GET['lang']) && in_array($_GET['lang'], $langs)) {
    $lang = $_GET['lang'];
}
$translator = new \Symfony\Component\Translation\Translator($lang);
$translator->addLoader('xliff', new \Symfony\Component\Translation\Loader\XliffFileLoader());
$translator->addResource('xliff', dirname(__FILE__) . '/../../translations/inscription.en.xlf', 'en');
$translator->setFallbackLocales(array('fr'));
$smarty->register_modifier('trans', [$translator, 'trans']);