当前位置: 首页>>代码示例>>PHP>>正文


PHP Translator::addLoader方法代码示例

本文整理汇总了PHP中Symfony\Component\Translation\Translator::addLoader方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::addLoader方法的具体用法?PHP Translator::addLoader怎么用?PHP Translator::addLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Translation\Translator的用法示例。


在下文中一共展示了Translator::addLoader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register

 public function register(Container $app)
 {
     $app['translator'] = function ($app) {
         if (!isset($app['locale'])) {
             throw new \LogicException('You must define \'locale\' parameter or register the LocaleServiceProvider to use the TranslationServiceProvider');
         }
         $translator = new Translator($app['locale'], $app['translator.message_selector'], $app['translator.cache_dir'], $app['debug']);
         $translator->setFallbackLocales($app['locale_fallbacks']);
         $translator->addLoader('array', new ArrayLoader());
         $translator->addLoader('xliff', new XliffFileLoader());
         // Register default resources
         foreach ($app['translator.resources'] as $resource) {
             $translator->addResource($resource[0], $resource[1], $resource[2], $resource[3]);
         }
         foreach ($app['translator.domains'] as $domain => $data) {
             foreach ($data as $locale => $messages) {
                 $translator->addResource('array', $messages, $locale, $domain);
             }
         }
         return $translator;
     };
     $app['translator.listener'] = function ($app) {
         return new TranslatorListener($app['translator'], $app['request_stack']);
     };
     $app['translator.message_selector'] = function () {
         return new MessageSelector();
     };
     $app['translator.resources'] = $app->protect(function ($app) {
         return [];
     });
     $app['translator.domains'] = [];
     $app['locale_fallbacks'] = ['en'];
     $app['translator.cache_dir'] = null;
 }
开发者ID:speedwork,项目名称:provider,代码行数:34,代码来源:TranslationServiceProvider.php

示例2: register

 public function register(Application $app, array $options = array())
 {
     $translator = new Translator('en', new MessageSelector());
     $translator->setFallbackLocale('en');
     $translator->addLoader('array', new ArrayLoader());
     $translator->addLoader('xliff', new XliffFileLoader());
     return $translator;
 }
开发者ID:ubick,项目名称:glue,代码行数:8,代码来源:TranslationProvider.php

示例3: __construct

 public function __construct($language)
 {
     $this->translator = new Translator(null);
     $this->translator->addLoader('array', new ArrayLoader());
     $this->translator->addResource('array', array('Hello World' => 'Olá mundo'), 'pt');
     $this->translator->addResource('array', array('Hello World' => 'Hola Mundo'), 'es');
     $this->translator->setLocale($language);
 }
开发者ID:thpoiani,项目名称:flisol-2015,代码行数:8,代码来源:Dicionario.php

示例4: setUp

 public function setUp()
 {
     $this->translator = new Translator("en_US");
     $this->translator->addLoader('array', new ArrayLoader());
     $this->translator->addResource('array', array('Hello %name%' => 'Ciao %name%'), 'it', 'dom');
     $loader = new \Twig_Loader_String();
     $this->twig = new \Twig_Environment($loader);
     $this->twig->addExtension(new TranslationExtension($this->translator));
     $this->twig->addExtension(new SafeTransExtension());
 }
开发者ID:arthens,项目名称:safe-translations,代码行数:10,代码来源:SafeTransTokenParserTest.php

示例5: __construct

 /**
  * Contructor
  */
 public function __construct()
 {
     if ($this->config()->exists('lang')) {
         $this->lang = $this->config()->get('lang');
     } else {
         $this->lang = 'en';
     }
     $this->adaptor = new Translator($this->lang);
     $this->adaptor->addLoader('array', new ArrayLoader());
 }
开发者ID:jarick,项目名称:bx,代码行数:13,代码来源:TranslateManager.php

示例6: register

 public function register(Application $app)
 {
     $app['translator'] = function ($app) {
         $translator = new Translator($app['config']['app.locale']);
         $translator->addLoader('mo', new MoFileLoader());
         $translator->addLoader('po', new PoFileLoader());
         $translator->addLoader('array', new ArrayLoader());
         return $translator;
     };
 }
开发者ID:jacobjjc,项目名称:PageKit-framework,代码行数:10,代码来源:TranslationServiceProvider.php

示例7: main

 /**
  * {@inheritdoc}
  */
 public function main(App $app)
 {
     $app['translator'] = function () {
         $translator = new Translator($this->getLocale());
         $translator->addLoader('php', new PhpFileLoader());
         $translator->addLoader('mo', new MoFileLoader());
         $translator->addLoader('po', new PoFileLoader());
         $translator->addLoader('array', new ArrayLoader());
         $this->loadLocale($this->getLocale(), $translator);
         return $translator;
     };
     require __DIR__ . '/../functions.php';
 }
开发者ID:pagekit,项目名称:pagekit,代码行数:16,代码来源:IntlModule.php

示例8: __construct

 /**
  * Block constructor.
  * @throws InvalidArgumentException
  */
 private function __construct()
 {
     self::$translator = new Translator('en', new MessageSelector());
     self::$translator->addLoader('php', new PhpFileLoader());
     foreach (glob(__DIR__ . '/../../locales/messages.*.php') as $file) {
         if (preg_match('/\\.([\\w-]+)\\.php$/', basename($file), $fileLocaleMatch)) {
             /** @noinspection ExceptionsAnnotatingAndHandlingInspection */
             self::$translator->addResource('php', $file, $fileLocaleMatch[1]);
         }
     }
     self::configureLocale();
     // Reconfigure locale if it was changed.
     EventListener::$global->on('rentalhost.validation::option.set.locale', [self::class, 'configureLocale']);
 }
开发者ID:VanillaPackage,项目名称:vanilla-validation,代码行数:18,代码来源:ValidationLocalize.php

示例9: register

 public function register(Container $app)
 {
     $app['translator'] = function ($app) {
         if (!isset($app['locale'])) {
             throw new \LogicException('You must define \'locale\' parameter or register the LocaleServiceProvider to use the TranslationServiceProvider');
         }
         $translator = new Translator($app['locale'], $app['translator.message_selector'], $app['translator.cache_dir'], $app['debug']);
         $translator->setFallbackLocales($app['locale_fallbacks']);
         $translator->addLoader('array', new ArrayLoader());
         $translator->addLoader('xliff', new XliffFileLoader());
         if (isset($app['validator'])) {
             $r = new \ReflectionClass('Symfony\\Component\\Validator\\Validation');
             $file = dirname($r->getFilename()) . '/Resources/translations/validators.' . $app['locale'] . '.xlf';
             if (file_exists($file)) {
                 $translator->addResource('xliff', $file, $app['locale'], 'validators');
             }
         }
         if (isset($app['form.factory'])) {
             $r = new \ReflectionClass('Symfony\\Component\\Form\\Form');
             $file = dirname($r->getFilename()) . '/Resources/translations/validators.' . $app['locale'] . '.xlf';
             if (file_exists($file)) {
                 $translator->addResource('xliff', $file, $app['locale'], 'validators');
             }
         }
         // Register default resources
         foreach ($app['translator.resources'] as $resource) {
             $translator->addResource($resource[0], $resource[1], $resource[2], $resource[3]);
         }
         foreach ($app['translator.domains'] as $domain => $data) {
             foreach ($data as $locale => $messages) {
                 $translator->addResource('array', $messages, $locale, $domain);
             }
         }
         return $translator;
     };
     if (isset($app['request_stack'])) {
         $app['translator.listener'] = function ($app) {
             return new TranslatorListener($app['translator'], $app['request_stack']);
         };
     }
     $app['translator.message_selector'] = function () {
         return new MessageSelector();
     };
     $app['translator.resources'] = $app->protect(function ($app) {
         return array();
     });
     $app['translator.domains'] = array();
     $app['locale_fallbacks'] = array('en');
     $app['translator.cache_dir'] = null;
 }
开发者ID:cordje,项目名称:Silex,代码行数:50,代码来源:TranslationServiceProvider.php

示例10: testTransChoice

 /**
  * @dataProvider getTransChoiceTests
  */
 public function testTransChoice($expected, $id, $translation, $number, $parameters, $locale, $domain)
 {
     $translator = new Translator('en', new MessageSelector());
     $translator->addLoader('array', new ArrayLoader());
     $translator->addResource('array', array($id => $translation), $locale, $domain);
     $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters, $domain, $locale));
 }
开发者ID:netixpro,项目名称:symfony,代码行数:10,代码来源:TranslatorTest.php

示例11: render

 public function render($route, $log = null)
 {
     $template_path = $route->join('/') . '/' . $this->context->template . '.tpl';
     $template_base_path = APP_ROOT . '/Views';
     $cache = false;
     if (isset(\Config\Base::$caching) && \Config\Base::$caching == true) {
         $cache = \Config\Base::$caching['twig'] ? APP_ROOT . '/cache' : false;
     }
     $loader = new \Bacon\Loader($template_base_path, $template_path);
     $twig = new \Twig_Environment($loader, ['cache' => $cache, 'auto_reload' => true]);
     if (!empty($this->context->template_base_paths)) {
         foreach ($this->context->template_base_paths as $path) {
             $loader->addPath($path);
         }
     }
     if (!empty($this->context->filters)) {
         foreach ($this->context->filters->getArrayCopy() as $name => $function) {
             $filter_function = new \Twig_Filter_Function($function, ['is_safe' => ['html']]);
             $twig->addFilter($name, $filter_function);
         }
     }
     if (!empty($this->context->locale)) {
         $locale = $this->context->locale;
         $translator = new Translator($locale, new MessageSelector());
         $translator->addLoader('po', new PoFileLoader());
         $translator->addResource('po', APP_ROOT . '/locales/' . $locale . '/' . $this->context->locale_file . '.po', $locale);
         $twig->addExtension(new \Symfony\Bridge\Twig\Extension\TranslationExtension($translator));
     }
     echo $twig->render($template_path, $this->context->getArrayCopy());
 }
开发者ID:brainsware,项目名称:bacon,代码行数:30,代码来源:Html.php

示例12: register

 /**
  * Initialize translator services.
  *
  * @param Pimple\Container $container
  *
  * @return Pimple\Container
  */
 public function register(Container $container)
 {
     /**
      * This service have to be called once a controller has
      * been matched! Never before.
      */
     $container['translator.locale'] = function ($c) {
         if ($c['session']->get('_locale') != "") {
             return $c['session']->get('_locale');
         } else {
             return $c['request']->getLocale();
         }
     };
     $container['translator'] = function ($c) {
         $c['stopwatch']->start('initTranslations');
         $translator = new Translator($c['translator.locale'], null, ROADIZ_ROOT . '/cache/translations', (bool) $c['config']['devMode']);
         $translator->addLoader('xlf', new XliffFileLoader());
         /*
          * Chosen language translations
          */
         $this->addTranslatorResource($translator, ROADIZ_ROOT . '/src/Roadiz/CMS/Resources/translations', 'xlf', $c['translator.locale']);
         $this->addTranslatorResource($translator, ROADIZ_ROOT . '/themes/Install/Resources/translations', 'xlf', $c['translator.locale']);
         $classes = [$c['backendTheme']];
         $classes = array_merge($classes, $c['frontendThemes']);
         foreach ($classes as $theme) {
             if (null !== $theme) {
                 $themeClass = $theme->getClassName();
                 $this->addTranslatorResource($translator, $themeClass::getResourcesFolder() . '/translations', 'xlf', $c['translator.locale']);
             }
         }
         $c['stopwatch']->stop('initTranslations');
         return $translator;
     };
     return $container;
 }
开发者ID:bryanbanda,项目名称:roadiz,代码行数:42,代码来源:TranslationServiceProvider.php

示例13: register

 public function register()
 {
     $di = $this->getContainer();
     $config = $this->getConfig();
     $di->add($config['message_selector_class']);
     foreach ($config['loaders'] as $name => $class) {
         $di->add($class);
         $di->add('translation.loader.' . $name, $class);
     }
     $di->add('Symfony\\Component\\Translation\\Translator', function () use($di, $config) {
         $selector = $di->get($config['message_selector_class']);
         $translator = new Translator($config['locale'], $selector);
         $translator->setFallbackLocales($config['fallback_locales']);
         foreach ($config['loaders'] as $name => $class) {
             $translator->addLoader($name, $di->get('translation.loader.' . $name));
         }
         foreach ($config['resources'] as $locale => $resources) {
             foreach ($resources as $config) {
                 list($loader, $arg, $domain) = $config + ['array', [], 'messages'];
                 $translator->addResource($loader, $arg, $locale, $domain);
             }
         }
         return $translator;
     }, true);
     $di->add('Laasti\\SymfonyTranslationProvider\\TranslationArray')->withArgument('Symfony\\Component\\Translation\\Translator');
 }
开发者ID:laasti,项目名称:symfony-translation-provider,代码行数:26,代码来源:SymfonyTranslationProvider.php

示例14: create

 /**
  * Create translator
  *
  * @return Translator
  */
 public static function create(ServiceContainer $app)
 {
     $locale = $app->session->get('user.locale', 'en_US');
     $translator = new Translator($locale, new MessageSelector());
     $translator->addLoader('mo', new MoFileLoader());
     return $translator;
 }
开发者ID:odan,项目名称:molengo,代码行数:12,代码来源:TranslatorFactory.php

示例15: testDefaultTranslationDomain

    public function testDefaultTranslationDomain()
    {
        $templates = array('index' => '
                {%- extends "base" %}

                {%- trans_default_domain "foo" %}

                {%- block content %}
                    {%- trans %}foo{% endtrans %}
                    {%- trans from "custom" %}foo{% endtrans %}
                    {{- "foo"|trans }}
                    {{- "foo"|trans({}, "custom") }}
                    {{- "foo"|transchoice(1) }}
                    {{- "foo"|transchoice(1, {}, "custom") }}
                {% endblock %}
            ', 'base' => '
                {%- block content "" %}
            ');
        $translator = new Translator('en', new MessageSelector());
        $translator->addLoader('array', new ArrayLoader());
        $translator->addResource('array', array('foo' => 'foo (messages)'), 'en');
        $translator->addResource('array', array('foo' => 'foo (custom)'), 'en', 'custom');
        $translator->addResource('array', array('foo' => 'foo (foo)'), 'en', 'foo');
        $template = $this->getTemplate($templates, $translator);
        $this->assertEquals('foo (foo)foo (custom)foo (foo)foo (custom)foo (foo)foo (custom)', trim($template->render(array())));
    }
开发者ID:nicodmf,项目名称:symfony,代码行数:26,代码来源:TranslationExtensionTest.php


注:本文中的Symfony\Component\Translation\Translator::addLoader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。