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


PHP TranslateUtils::getPlaceholder方法代码示例

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


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

示例1: unflattenPlural

 /**
  * Converts the special plural syntax to array or ruby style plurals
  *
  * @param string $key Message key prefix
  * @param string $message The plural string
  *
  * @return bool|array
  */
 public function unflattenPlural($key, $message)
 {
     // Quick escape.
     if (strpos($message, '{{PLURAL') === false) {
         return array($key => $message);
     }
     /*
      * Replace all variables with placeholders. Possible source of bugs
      * if other characters that given below are used.
      */
     $regex = '~\\{[a-zA-Z_-]+}~';
     $placeholders = array();
     $match = array();
     while (preg_match($regex, $message, $match)) {
         $uniqkey = TranslateUtils::getPlaceholder();
         $placeholders[$uniqkey] = $match[0];
         $search = preg_quote($match[0], '~');
         $message = preg_replace("~{$search}~", $uniqkey, $message);
     }
     // Then replace (possible multiple) plural instances into placeholders.
     $regex = '~\\{\\{PLURAL\\|(.*?)}}~s';
     $matches = array();
     $match = array();
     while (preg_match($regex, $message, $match)) {
         $uniqkey = TranslateUtils::getPlaceholder();
         $matches[$uniqkey] = $match;
         $message = preg_replace($regex, $uniqkey, $message, 1);
     }
     // No plurals, should not happen.
     if (!count($matches)) {
         return false;
     }
     // The final array of alternative plurals forms.
     $alts = array();
     /*
      * Then loop trough each plural block and replacing the placeholders
      * to construct the alternatives. Produces invalid output if there is
      * multiple plural bocks which don't have the same set of keys.
      */
     $pluralChoice = implode('|', array_keys(self::$pluralWords));
     $regex = "~({$pluralChoice})\\s*=\\s*(.+)~s";
     foreach ($matches as $ph => $plu) {
         $forms = explode('|', $plu[1]);
         foreach ($forms as $form) {
             if ($form === '') {
                 continue;
             }
             $match = array();
             if (preg_match($regex, $form, $match)) {
                 $formWord = "{$key}.{$match[1]}";
                 $value = $match[2];
             } else {
                 $formWord = "{$key}.other";
                 $value = $form;
             }
             if (!isset($alts[$formWord])) {
                 $alts[$formWord] = $message;
             }
             $string = $alts[$formWord];
             $alts[$formWord] = str_replace($ph, $value, $string);
         }
     }
     // Replace other variables.
     foreach ($alts as &$value) {
         $value = str_replace(array_keys($placeholders), array_values($placeholders), $value);
     }
     if (!isset($alts["{$key}.other"])) {
         wfWarn("Other not set for key {$key}");
         return false;
     }
     return $alts;
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:80,代码来源:RubyYamlFFS.php

示例2: sectionise

 /**
  * Splits the content marked with \<translate> tags into sections, which
  * are separated with with two or more newlines. Extra whitespace is captured
  * in the template and not included in the sections.
  * @param array $sections Array of placeholder => TPSection.
  * @param string $text Contents of one pair of \<translate> tags.
  * @return string Template with placeholders for sections, which itself are added to $sections.
  */
 protected function sectionise(&$sections, $text)
 {
     $flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE;
     $parts = preg_split('~(\\s*\\n\\n\\s*|\\s*$)~', $text, -1, $flags);
     $template = '';
     foreach ($parts as $_) {
         if (trim($_) === '') {
             $template .= $_;
         } else {
             $ph = TranslateUtils::getPlaceholder();
             $sections[$ph] = $this->shakeSection($_);
             $template .= $ph;
         }
     }
     return $template;
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:24,代码来源:TranslatablePage.php

示例3: splitPlural

 protected function splitPlural($text, $forms)
 {
     if ($forms === 1) {
         return $text;
     }
     $placeholder = TranslateUtils::getPlaceholder();
     # |/| is commonly used in KDE to support inflections
     $text = str_replace('|/|', $placeholder, $text);
     $plurals = array();
     $match = preg_match_all('/{{PLURAL:GETTEXT\\|(.*)}}/iUs', $text, $plurals);
     if (!$match) {
         throw new GettextPluralException("Failed to find plural in: {$text}");
     }
     $splitPlurals = array();
     for ($i = 0; $i < $forms; $i++) {
         # Start with the hole string
         $pluralForm = $text;
         # Loop over *each* {{PLURAL}} instance and replace
         # it with the plural form belonging to this index
         foreach ($plurals[0] as $index => $definition) {
             $parsedFormsArray = explode('|', $plurals[1][$index]);
             if (!isset($parsedFormsArray[$i])) {
                 error_log("Too few plural forms in: {$text}");
                 $pluralForm = '';
             } else {
                 $pluralForm = str_replace($pluralForm, $definition, $parsedFormsArray[$i]);
             }
         }
         $pluralForm = str_replace($placeholder, '|/|', $pluralForm);
         $splitPlurals[$i] = $pluralForm;
     }
     return $splitPlurals;
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:33,代码来源:GettextFFS.php

示例4: unflattenPlural

 /**
  * Converts the flattened plural into messages
  *
  * @param string $message
  * @return array
  */
 protected function unflattenPlural($message)
 {
     $regex = '~\\{\\{PLURAL\\|(.*?)}}~s';
     $matches = array();
     $match = array();
     while (preg_match($regex, $message, $match)) {
         $uniqkey = TranslateUtils::getPlaceholder();
         $matches[$uniqkey] = $match;
         $message = preg_replace($regex, $uniqkey, $message, 1);
     }
     // No plurals, should not happen.
     if (!count($matches)) {
         return array();
     }
     // The final array of alternative plurals forms.
     $alts = array();
     /*
      * Then loop trough each plural block and replacing the placeholders
      * to construct the alternatives. Produces invalid output if there is
      * multiple plural bocks which don't have the same set of keys.
      */
     $pluralChoice = implode('|', array_keys(self::$pluralWords));
     $regex = "~({$pluralChoice})\\s*=\\s*(.+)~s";
     foreach ($matches as $ph => $plu) {
         $forms = explode('|', $plu[1]);
         foreach ($forms as $form) {
             if ($form === '') {
                 continue;
             }
             $match = array();
             if (!preg_match($regex, $form, $match)) {
                 // No quantity key was provided
                 continue;
             }
             $formWord = $match[1];
             $value = $match[2];
             if (!isset($alts[$formWord])) {
                 $alts[$formWord] = $message;
             }
             $string = $alts[$formWord];
             $alts[$formWord] = str_replace($ph, $value, $string);
         }
     }
     return $alts;
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:51,代码来源:AndroidXmlFFS.php

示例5: __construct

 public function __construct()
 {
     parent::__construct('SearchTranslations');
     $this->hl = array(TranslateUtils::getPlaceholder(), TranslateUtils::getPlaceholder());
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:5,代码来源:SpecialSearchTranslations.php


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