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


PHP Translator::has方法代码示例

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


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

示例1: handle

 /**
  * Handle the fields.
  *
  * @param PermissionFormBuilder $builder
  * @param AddonCollection       $addons
  * @param Translator            $translator
  * @param Repository            $config
  */
 public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Translator $translator, Repository $config)
 {
     /* @var UserInterface $user */
     $user = $builder->getEntry();
     $fields = [];
     $namespaces = ['streams'];
     /* @var Addon $addon */
     foreach ($addons->withConfig('permissions') as $addon) {
         $namespaces[] = $addon->getNamespace();
     }
     foreach ($namespaces as $namespace) {
         foreach ($config->get($namespace . '::permissions', []) as $group => $permissions) {
             $label = $namespace . '::permission.' . $group . '.name';
             if (!$translator->has($warning = $namespace . '::permission.' . $group . '.warning')) {
                 $warning = null;
             }
             if (!$translator->has($instructions = $namespace . '::permission.' . $group . '.instructions')) {
                 $instructions = null;
             }
             $fields[$namespace . '::' . $group] = ['label' => $label, 'warning' => $warning, 'instructions' => $instructions, 'type' => 'anomaly.field_type.checkboxes', 'value' => function () use($user, $namespace, $group) {
                 return array_map(function ($permission) use($user, $namespace, $group) {
                     return str_replace($namespace . '::' . $group . '.', '', $permission);
                 }, $user->getPermissions());
             }, 'config' => ['options' => function () use($group, $permissions, $namespace) {
                 return array_combine($permissions, array_map(function ($permission) use($namespace, $group) {
                     return $namespace . '::permission.' . $group . '.option.' . $permission;
                 }, $permissions));
             }]];
         }
     }
     $builder->setFields($fields);
 }
开发者ID:tobz-nz,项目名称:users-module,代码行数:40,代码来源:PermissionFormFields.php

示例2: guess

 /**
  * Guess the sections title.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $sections = $builder->getSections();
     foreach ($sections as &$section) {
         // If title is set then skip it.
         if (isset($section['title'])) {
             continue;
         }
         $module = $this->modules->active();
         $title = $module->getNamespace('section.' . $section['slug'] . '.title');
         if (!isset($section['title']) && $this->translator->has($title)) {
             $section['title'] = $title;
         }
         $title = $module->getNamespace('addon.section.' . $section['slug']);
         if (!isset($section['title']) && $this->translator->has($title)) {
             $section['title'] = $title;
         }
         if (!isset($section['title']) && $this->config->get('streams::system.lazy_translations')) {
             $section['title'] = ucwords($this->string->humanize($section['slug']));
         }
         if (!isset($section['title'])) {
             $section['title'] = $title;
         }
     }
     $builder->setSections($sections);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:31,代码来源:TitleGuesser.php

示例3: format

 /**
  * Format a timestamp based on translation
  *
  * @param  mixed $timestamp    accepts string, unix timestamp and DateTime object
  * @param  string $format
  * @return string
  */
 public function format($format = 'date', $timestamp = null)
 {
     $timestamp = is_numeric($timestamp) ? '@' . intval($timestamp) : $timestamp;
     $timestamp = is_a($timestamp, 'DateTime') ? $timestamp : new DateTime($timestamp);
     $key = $this->getTranslationKey("date.formats.{$format}");
     $format = $this->translator->has($key) ? $this->translator->get($key) : null;
     if (is_null($format)) {
         throw new \InvalidArgumentException('Date format is invalid or does not exists in current language');
     }
     return strftime($format, $timestamp->format('U'));
 }
开发者ID:intervention,项目名称:helper,代码行数:18,代码来源:Date.php

示例4: localized

 /**
  * Get localized name of zodiac sign
  *
  * @return string
  */
 public function localized()
 {
     if (!is_a($this->translator, 'Illuminate\\Translation\\Translator')) {
         return "zodiacs.{$this->name}";
     }
     if ($this->translator->has("zodiacs.{$this->name}")) {
         // return error message from validation translation file
         return $this->translator->get("zodiacs.{$this->name}");
     }
     // return packages default message
     return $this->translator->get("zodiacs::zodiacs.{$this->name}");
 }
开发者ID:Intervention,项目名称:zodiac,代码行数:17,代码来源:AbstractZodiac.php

示例5: shareTitle

 private function shareTitle()
 {
     $langKey = "titles.{$this->router->currentRouteName()}";
     if ($this->lang->has($langKey)) {
         $this->view->share('title', $this->lang->get($langKey));
     }
 }
开发者ID:reshadman,项目名称:hammihan-online,代码行数:7,代码来源:Settings.php

示例6: translate

 /**
  * Translate a target array.
  *
  * @param array $target
  * @return array
  */
 public function translate($target)
 {
     if (is_string($target)) {
         return $this->translator->trans($target);
     }
     if (is_array($target)) {
         foreach ($target as &$value) {
             if (is_string($value) && $this->translator->has($value)) {
                 $value = $this->translator->trans($value);
             } elseif (is_array($value)) {
                 $value = $this->translate($value);
             }
         }
     }
     return $target;
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:22,代码来源:Translator.php

示例7: translateMessage

 /**
  * tries to translate the message if existing, otherwise returns the original message string
  *
  * @param string $message
  * @return string
  */
 private function translateMessage($message)
 {
     if ($this->translator->has($message)) {
         return $this->translator->get($message);
     }
     return $message;
 }
开发者ID:ipunkt,项目名称:laravel-notifications,代码行数:13,代码来源:FlashNotifier.php

示例8: guess

 /**
  * Guess the button from the hint.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $module = $this->modules->active();
     /**
      * This will break if we can't figure
      * out what the active module is.
      */
     if (!$module instanceof Module) {
         return;
     }
     foreach ($buttons as &$button) {
         if (!isset($button['button'])) {
             continue;
         }
         $text = $module->getNamespace('button.' . $button['button']);
         if (!isset($button['text']) && $this->translator->has($text)) {
             $button['text'] = $text;
         }
         $text = $module->getNamespace('button.' . $button['button']);
         if (!isset($button['text']) && $this->translator->has($text)) {
             $button['text'] = $text;
         }
         if ((!isset($button['text']) || !$this->translator->has($button['text'])) && $this->config->get('streams::system.lazy_translations')) {
             $button['text'] = $this->string->humanize(array_get($button, 'slug', $button['button']));
         }
     }
     $builder->setButtons($buttons);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:34,代码来源:TextGuesser.php

示例9: guess

 /**
  * Guess the sections description.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $sections = $builder->getSections();
     foreach ($sections as &$section) {
         // If description is set then skip it.
         if (isset($section['description'])) {
             continue;
         }
         $module = $this->modules->active();
         $description = $module->getNamespace('section.' . $section['slug'] . '.description');
         if ($this->translator->has($description)) {
             $section['description'] = $description;
         }
     }
     $builder->setSections($sections);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:21,代码来源:DescriptionGuesser.php

示例10: handle

 /**
  * Handle the command.
  *
  * @param Repository $config
  * @param Evaluator  $evaluator
  */
 public function handle(Repository $config, Evaluator $evaluator, Translator $translator)
 {
     if (!($fields = $config->get($this->fieldType->getNamespace('config/config')))) {
         $fields = $config->get($this->fieldType->getNamespace('config'), []);
     }
     $fields = $evaluator->evaluate($fields);
     foreach ($fields as $slug => $field) {
         /**
          * Determine the field label.
          */
         $label = $this->fieldType->getNamespace('config.' . $slug . '.label');
         if (!$translator->has($label)) {
             $label = $this->fieldType->getNamespace('config.' . $slug . '.name');
         }
         $field['label'] = array_get($field, 'label', $label);
         /**
          * Determine the instructions.
          */
         $instructions = $this->fieldType->getNamespace('config.' . $slug . '.instructions');
         if ($translator->has($instructions)) {
             $field['instructions'] = $instructions;
         }
         /**
          * Determine the placeholder.
          */
         $placeholder = $this->fieldType->getNamespace('config.' . $slug . '.placeholder');
         if ($translator->has($placeholder)) {
             $field['placeholder'] = $placeholder;
         }
         /**
          * Determine the warning.
          */
         $warning = $this->fieldType->getNamespace('config.' . $slug . '.warning');
         if ($translator->has($warning)) {
             $field['warning'] = $warning;
         }
         /**
          * Set the configuration value.
          */
         $field['value'] = array_get($this->fieldType->getConfig(), $slug);
         // Prefix the slugs.
         $field['field'] = 'config.' . $slug;
         $fields['config.' . $slug] = $field;
         $this->builder->addField($field);
     }
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:52,代码来源:GetConfigFields.php

示例11: handle

 /**
  * Handle the fields.
  *
  * @param PermissionFormBuilder $builder
  * @param AddonCollection       $addons
  * @param Translator            $translator
  * @param Repository            $config
  */
 public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Translator $translator, Repository $config)
 {
     /* @var UserInterface $user */
     $user = $builder->getEntry();
     $roles = $user->getRoles();
     $inherited = $roles->permissions();
     $fields = [];
     $namespaces = array_merge(['streams'], $addons->withConfig('permissions')->namespaces());
     /**
      * gather all the addons with a
      * permissions configuration file.
      *
      * @var Addon $addon
      */
     foreach ($namespaces as $namespace) {
         foreach ($config->get($namespace . '::permissions', []) as $group => $permissions) {
             /**
              * Determine the general
              * form UI components.
              */
             $label = $namespace . '::permission.' . $group . '.name';
             if (!$translator->has($warning = $namespace . '::permission.' . $group . '.warning')) {
                 $warning = null;
             }
             if (!$translator->has($instructions = $namespace . '::permission.' . $group . '.instructions')) {
                 $instructions = null;
             }
             /**
              * Gather the available
              * permissions for the group.
              */
             $available = array_combine(array_map(function ($permission) use($namespace, $group) {
                 return $namespace . '::' . $group . '.' . $permission;
             }, $permissions), array_map(function ($permission) use($namespace, $group) {
                 return $namespace . '::permission.' . $group . '.option.' . $permission;
             }, $permissions));
             /**
              * Build the checkboxes field
              * type to handle the UI.
              */
             $fields[$namespace . '::' . $group] = ['label' => $label, 'warning' => $warning, 'instructions' => $instructions, 'type' => 'anomaly.field_type.checkboxes', 'value' => array_merge($user->getPermissions(), $inherited), 'config' => ['disabled' => $inherited, 'options' => $available]];
         }
     }
     $builder->setFields($fields);
 }
开发者ID:jacksun101,项目名称:users-module,代码行数:53,代码来源:PermissionFormFields.php

示例12: formatLabel

 /**
  * Format the label to the proper format
  *
  * @param $name
  * @return string
  */
 public function formatLabel($name)
 {
     if (!$name) {
         return null;
     }
     if ($this->translator->has($name)) {
         return $this->translator->get($name);
     }
     return ucfirst(str_replace('_', ' ', $name));
 }
开发者ID:abelit,项目名称:laravel-form-builder,代码行数:16,代码来源:FormHelper.php

示例13: guess

 /**
  * Guess the button from the hint.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $module = $this->modules->active();
     /*
      * This will break if we can't figure
      * out what the active module is.
      */
     if (!$module instanceof Module) {
         return;
     }
     foreach ($buttons as &$button) {
         /*
          * If the button starts with "new_" just use
          * "new" and move the rest to the text.
          */
         if (isset($button['button']) && starts_with($button['button'], 'new_')) {
             if (!isset($button['text'])) {
                 $text = $module->getNamespace('button.' . $button['button']);
                 if ($this->translator->has($text)) {
                     $button['text'] = $text;
                 }
             }
             // Change this to slug for later.
             $button['slug'] = $button['button'];
             array_set($button, 'button', substr($button['button'], 0, 3));
         }
         /*
          * If the button starts with "add_" just use
          * "add" and move the rest to the text.
          */
         if (isset($button['button']) && starts_with($button['button'], 'add_')) {
             if (!isset($button['text'])) {
                 $button['text'] = $module->getNamespace('button.' . $button['button']);
             }
             // Change this to slug for later.
             $button['slug'] = $button['button'];
             array_set($button, 'button', substr($button['button'], 0, 3));
         }
     }
     $builder->setButtons($buttons);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:47,代码来源:TypeGuesser.php

示例14: create

 /**
  * Gera uma excecao e retorna o Exception
  * @param $msg
  * @return \Exception
  */
 public function create($msg)
 {
     // Verificar se mensagem pode ser traduzida pelo sistema da Lang do Laravel
     if (is_string($msg) && $this->lang->has($msg)) {
         $msg = $this->lang->get($msg);
     }
     // Se msg for um objeto ou array deve fazer um print_r
     if (is_object($msg) || is_array($msg)) {
         $msg = print_r($msg, true);
     }
     $args = func_get_args();
     $args[0] = $msg;
     $msg = trim(call_user_func_array('sprintf', $args));
     $code = $args[count($args) - 1];
     if (is_numeric($code)) {
         return new \Exception($msg, $code);
     } else {
         return new \Exception($msg);
     }
 }
开发者ID:consolle,项目名称:framework,代码行数:25,代码来源:Error.php

示例15: guess

 /**
  * Guess some table table filter placeholders.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $filters = $builder->getFilters();
     $stream = $builder->getTableStream();
     foreach ($filters as &$filter) {
         // Skip if we already have a placeholder.
         if (isset($filter['placeholder'])) {
             continue;
         }
         // Get the placeholder off the assignment.
         if ($stream && ($assignment = $stream->getAssignment(array_get($filter, 'field')))) {
             /**
              * Always use the field name
              * as the placeholder. Placeholders
              * that are assigned otherwise usually
              * feel out of context:
              *
              * "Choose an option..." in the filter
              * would just be weird.
              */
             $filter['placeholder'] = $assignment->getFieldName();
         }
         if (!($module = $this->modules->active())) {
             continue;
         }
         $placeholder = $module->getNamespace('field.' . $filter['slug'] . '.placeholder');
         if (!isset($filter['placeholder']) && $this->translator->has($placeholder)) {
             $filter['placeholder'] = $placeholder;
         }
         $placeholder = $module->getNamespace('field.' . $filter['slug'] . '.name');
         if (!isset($filter['placeholder']) && $this->translator->has($placeholder)) {
             $filter['placeholder'] = $placeholder;
         }
         if (!array_get($filter, 'placeholder')) {
             $filter['placeholder'] = $filter['slug'];
         }
     }
     $builder->setFilters($filters);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:44,代码来源:PlaceholdersGuesser.php


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