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


PHP Translations::getPluralForms方法代码示例

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


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

示例1: toArray

 /**
  * Returns a multidimensional array.
  * 
  * @param Translations $translations
  * @param bool         $includeHeaders
  * @param bool         $forceArray
  *
  * @return array
  */
 private static function toArray(Translations $translations, $includeHeaders, $forceArray = false)
 {
     $pluralForm = $translations->getPluralForms();
     $pluralSize = is_array($pluralForm) ? $pluralForm[0] - 1 : null;
     $messages = [];
     if ($includeHeaders) {
         $messages[''] = ['' => [self::generateHeaders($translations)]];
     }
     foreach ($translations as $translation) {
         $context = $translation->getContext();
         $original = $translation->getOriginal();
         if (!isset($messages[$context])) {
             $messages[$context] = [];
         }
         if ($translation->hasPluralTranslations(true)) {
             $messages[$context][$original] = $translation->getPluralTranslations($pluralSize);
             array_unshift($messages[$context][$original], $translation->getTranslation());
         } elseif ($forceArray) {
             $messages[$context][$original] = [$translation->getTranslation()];
         } else {
             $messages[$context][$original] = $translation->getTranslation();
         }
     }
     return ['domain' => $translations->getDomain(), 'plural-forms' => $translations->getHeader('Plural-Forms'), 'messages' => $messages];
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:34,代码来源:MultidimensionalArrayTrait.php

示例2: toString

 /**
  * {@parentDoc}.
  */
 public static function toString(Translations $translations, array $options = [])
 {
     $pluralForm = $translations->getPluralForms();
     $pluralSize = is_array($pluralForm) ? $pluralForm[0] - 1 : null;
     $lines = ['msgid ""', 'msgstr ""'];
     foreach ($translations->getHeaders() as $name => $value) {
         $lines[] = sprintf('"%s: %s\\n"', $name, $value);
     }
     $lines[] = '';
     //Translations
     foreach ($translations as $translation) {
         if ($translation->hasComments()) {
             foreach ($translation->getComments() as $comment) {
                 $lines[] = '# ' . $comment;
             }
         }
         if ($translation->hasExtractedComments()) {
             foreach ($translation->getExtractedComments() as $comment) {
                 $lines[] = '#. ' . $comment;
             }
         }
         if ($translation->hasReferences()) {
             foreach ($translation->getReferences() as $reference) {
                 $lines[] = '#: ' . $reference[0] . (!is_null($reference[1]) ? ':' . $reference[1] : null);
             }
         }
         if ($translation->hasFlags()) {
             $lines[] = '#, ' . implode(',', $translation->getFlags());
         }
         if ($translation->hasContext()) {
             $lines[] = 'msgctxt ' . self::convertString($translation->getContext());
         }
         self::addLines($lines, 'msgid', $translation->getOriginal());
         if ($translation->hasPlural()) {
             self::addLines($lines, 'msgid_plural', $translation->getPlural());
             self::addLines($lines, 'msgstr[0]', $translation->getTranslation());
             foreach ($translation->getPluralTranslations($pluralSize) as $k => $v) {
                 self::addLines($lines, 'msgstr[' . ($k + 1) . ']', $v);
             }
         } else {
             self::addLines($lines, 'msgstr', $translation->getTranslation());
         }
         $lines[] = '';
     }
     return implode("\n", $lines);
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:49,代码来源:Po.php

示例3: buildMessages

 /**
  * Generates an array with all translations.
  * 
  * @param Translations $translations
  *
  * @return array
  */
 private static function buildMessages(Translations $translations)
 {
     $pluralForm = $translations->getPluralForms();
     $pluralSize = is_array($pluralForm) ? $pluralForm[0] - 1 : null;
     $messages = [];
     $context_glue = '\\u0004';
     foreach ($translations as $translation) {
         $key = ($translation->hasContext() ? $translation->getContext() . $context_glue : '') . $translation->getOriginal();
         if ($translation->hasPluralTranslations(true)) {
             $message = $translation->getPluralTranslations($pluralSize);
             array_unshift($message, $translation->getTranslation());
         } else {
             $message = [$translation->getTranslation()];
         }
         $messages[$key] = $message;
     }
     return $messages;
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:25,代码来源:Jed.php

示例4: mergeWith

 /**
  * Merges this translations with other translations.
  *
  * @param Translations $translations The translations instance to merge with
  * @param int|null     $method       One or various Translations::MERGE_* constants to define how to merge the translations
  */
 public function mergeWith(Translations $translations, $method = null)
 {
     if ($method === null) {
         $method = self::$mergeDefault;
     }
     if ($method & self::MERGE_HEADERS) {
         foreach ($translations->getHeaders() as $name => $value) {
             if (!$this->getHeader($name)) {
                 $this->setHeader($name, $value);
             }
         }
     }
     $add = (bool) ($method & self::MERGE_ADD);
     foreach ($translations as $entry) {
         if ($existing = $this->find($entry)) {
             $existing->mergeWith($entry, $method);
         } elseif ($add) {
             $this[] = clone $entry;
         }
     }
     if ($method & self::MERGE_REMOVE) {
         $filtered = array();
         foreach ($this as $entry) {
             if ($translations->find($entry)) {
                 $filtered[] = $entry;
             }
         }
         $this->exchangeArray($filtered);
     }
     if ($method & self::MERGE_LANGUAGE) {
         $language = $translations->getLanguage();
         $pluralForm = $translations->getPluralForms();
         if (!$pluralForm) {
             if (!empty($language)) {
                 $this->setLanguage($language);
             }
         } else {
             if (!empty($language)) {
                 $this->setHeader(self::HEADER_LANGUAGE, $language);
             }
             $this->setPluralForms($pluralForm[0], $pluralForm[1]);
         }
     }
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:50,代码来源:Translations.php


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