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


PHP Translation\Translator类代码示例

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


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

示例1: 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

示例2: 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:makhloufi-lounis,项目名称:tuto_symfony,代码行数:26,代码来源:TranslationExtensionTest.php

示例3: 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

示例4: 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

示例5: loader

 public function loader($locale = 'es_ES')
 {
     $Translator = new Translator($locale);
     $Translator->addLoader('array', new ArrayLoader());
     $data = array();
     $part_locale = explode('_', $locale);
     $bundles = Service::getBundles();
     foreach ($bundles as $bundle) {
         $path_i18n = str_replace('\\', '/', $bundle->getPath() . '/i18n/' . $part_locale[0]);
         if (is_dir($path_i18n)) {
             $finder = new Finder();
             $finder->files()->name('*.i18n.php')->in($path_i18n);
             // Une todos los esquemas en un solo array
             foreach ($finder as $file) {
                 $_a = (require $file->getRealpath());
                 $data = array_merge($data, $_a);
             }
         }
     }
     $path_i18n = str_replace('\\', '/', Ki_APP . 'src/i18n/' . $part_locale[0]);
     if (is_dir($path_i18n)) {
         $finder = new Finder();
         $finder->files()->name('*.i18n.php')->in($path_i18n);
         // Une todos los esquemas en un solo array
         foreach ($finder as $file) {
             $_a = (require $file->getRealpath());
             $data = array_merge($data, $_a);
         }
     }
     $Translator->addResource('array', $data, $locale);
     $this->Translator = $Translator;
 }
开发者ID:kodazzi,项目名称:framework,代码行数:32,代码来源:TranslatorBuilder.php

示例6: addResourcesToTranslator

 /**
  * @return TranslatorInterface
  */
 private function addResourcesToTranslator(Translator $translator)
 {
     foreach ($this->resourceFinder->findInDirectory($this->translationDir) as $resource) {
         $translator->addResource($resource['format'], $resource['pathname'], $resource['locale'], $resource['domain']);
     }
     return $translator;
 }
开发者ID:TomasVotruba,项目名称:tomasvotruba.cz,代码行数:10,代码来源:TranslatorFactory.php

示例7: 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

示例8: ru

 /**
  * Plural rules for russian language.
  */
 public static function ru($string, $number)
 {
     $translator = new Translator('ru');
     $translated = $translator->trans(':count ' . $string, array(':count' => $number));
     $type = $number % 10 == 1 && $number % 100 != 11 ? 0 : ($number % 10 >= 2 && $number % 10 <= 4 && ($number % 100 < 10 || $number % 100 >= 20) ? 1 : 2);
     $translated_array = explode("|", $translated);
     return $translated_array[$type];
 }
开发者ID:SolidWeb,项目名称:Hagakure,代码行数:11,代码来源:PluralHelper.php

示例9: configure

function configure()
{
    $translator = new Translator("fr_FR", new MessageSelector());
    $translator->setFallbackLocales(array("fr"));
    $translator->addLoader("array", new ArrayLoader());
    $translator->addResource("array", array("Hello World!" => "Bonjour"), "fr");
    Yasc_App::config()->addOption("translator", $translator);
}
开发者ID:nebiros,项目名称:yasc,代码行数:8,代码来源:index.php

示例10: runTest

 public function runTest()
 {
     $translator = new Translator("fr_FR", new MessageSelector());
     $translator->addLoader("array", new ArrayLoader());
     $translator->addResource("array", array("Hello World!" => "Bonjour", "Symfony is great" => "Symfony est le meuilleur", "Hello %name%" => "Bonjour %name%", "apple.choice" => "Une pomme | %count% pommes"), "fr_FR");
     $translator->setFallbackLocales(array("en"));
     (new TranslationValidator($translator))->validate();
 }
开发者ID:jeanpasqualini-lesson,项目名称:lesson-translation,代码行数:8,代码来源:ArrayTest.php

示例11: 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

示例12: execute

 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $i18nPath = dirname(dirname(dirname(dirname(dirname(__DIR__))))) . DIRECTORY_SEPARATOR . 'i18n.php';
     foreach (require $i18nPath as $lang => $messages) {
         $this->translator->addResource('array', $messages, $lang, 'output');
     }
 }
开发者ID:OverByThere,项目名称:Behat,代码行数:10,代码来源:GherkinTranslationsController.php

示例13: get

 /**
  * @param FormView $formView
  *
  * @return string
  * @author Michaël VEROUX
  */
 public function get(FormView $formView)
 {
     $value = $formView->vars['value'];
     $display = array();
     $expanded = isset($formView->vars['expanded']) && $formView->vars['expanded'];
     $multiple = isset($formView->vars['multiple']) && $formView->vars['multiple'];
     if ($expanded && $multiple) {
         $value = array_filter($value, function ($val) {
             return $val;
         });
         $value = array_keys($value);
     }
     foreach ($formView->vars['choices'] as $key => $choiceView) {
         if ($multiple) {
             if ($expanded) {
                 $compare = $key;
             } else {
                 $compare = $choiceView->value;
             }
             if (in_array($compare, $value)) {
                 $display[] = $this->translator->trans($choiceView->label, array(), $formView->vars['translation_domain']);
             }
         } else {
             if ($value == $choiceView->value) {
                 return $this->translator->trans($choiceView->label, array(), $formView->vars['translation_domain']);
             }
         }
     }
     if (!count($display)) {
         return $formView->vars['placeholder'];
     }
     return implode(PHP_EOL, $display);
 }
开发者ID:phpmike,项目名称:MvExportFormBundle,代码行数:39,代码来源:ChoiceTypeDisplay.php

示例14: runJobs

 /**
  * @param $jobs
  * @throws UnauthorizedCommandException
  */
 protected function runJobs($jobs)
 {
     foreach ($jobs as $job) {
         /**
          * @var \WeavingTheWeb\Bundle\ApiBundle\Entity\Job $job
          */
         $command = $job->getValue();
         try {
             $this->validateCommand($command);
             $job->setStatus(JobInterface::STATUS_STARTED);
             $this->updateJob($job);
             $command = $this->getApplication()->get($command);
             $success = $command->run(new ArrayInput(['command' => $command, '--job' => $job->getId()]), $this->output);
             if (intval($success) === 0) {
                 $job->setStatus(JobInterface::STATUS_FINISHED);
             } else {
                 $job->setStatus(JobInterface::STATUS_FAILED);
             }
             $this->updateJob($job);
         } catch (UnauthorizedCommandException $exception) {
             $message = $this->translator->trans('job.run.unauthorized', ['{{ command }}' => $command], 'job');
             $this->logger->error($exception->getMessage());
             $this->output->writeln($message);
             $job->setStatus(JobInterface::STATUS_FAILED);
             $this->updateJob($job);
             continue;
         } catch (\Exception $exception) {
             $this->logger->error($exception->getMessage());
             continue;
         }
     }
 }
开发者ID:WeavingTheWeb,项目名称:devobs,代码行数:36,代码来源:RunJobCommand.php

示例15: execute

 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('lang')) {
         return;
     }
     $this->translator->setLocale($input->getOption('lang'));
 }
开发者ID:OverByThere,项目名称:Behat,代码行数:10,代码来源:LanguageController.php


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