获取文本翻译{}

获取文本_翻译类。

方法

姓名描述
获取文本翻译::Gettext_select_plural_formselect_plural_form的gettext实现。
获取文本翻译::make_headers准备翻译标题。
获取文本翻译::make_plural_form_function创建一个函数,根据复数形式的标题返回正确的翻译索引。
获取文本翻译::nplurals_and_expression_from_header从plural-forms标头返回nplurals和复数形式表达式。
Gettext_Translations::括号_plural_exression在复数表达式中的三元运算符内部添加括号,因为PHP从左到右计算三元运算符-已弃用
获取文本翻译::set_header设置翻译标题。

来源

类Gettext_Translations扩展了Translations{/***复数形式的数量。**@var整数**@自2.8.0起*/公共$复数;/***Callback检索复数形式。**@var可调用**@自2.8.0起*/公共$_gettext_select_plural_form;/***select_plural_form的gettext实现。**它位于这个类中,因为有多个后代,它们将使用它和*他们无法有效地分享。**@自2.8.0起**@param int$count复数形式计数。*@return int复数形式。*/公共函数gettext_select_plural_form($count){如果(!isset($this->_gettext_select_plural_form){列表($nplurals,$expression)=$this->nplurals_and_expression_from_header($this->get_header,“多表单”);$this->_nplurals=$nplurals;$this->_gettext_select_plural_form=$this->生成plural_form_function($nplurals,$expression);}返回call_user_func($this->_gettext_select_plural_form,$count);}/***从plural-forms标头返回nplurals和复数形式表达式。**@自2.8.0起**@param字符串$header*@return数组{0:int,1:string}*/公共函数nplurals_and_expression_from_header($header){if(preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+复数\s*=\s*(.+)$/',$header,$matches)){$nplurals=(int)$matches[1];$expression=修剪($matches[2]);返回数组($nplurals,$expression);}其他{返回数组(2,'n!=1');}}/***根据*复数形式的标题。**@自2.8.0起**@param int$nplurals*@param字符串$表达式*@return可调用*/公共函数make_plural_form_function($nplurals,$expression){尝试{$handler=新的Plural_Forms(rtrim($expression,';'));返回数组($handler,'get');}catch(异常$e){//回退到默认的复数形式函数。返回$this->make_plural_form_function(2,'n!=1');}}/***在中三元运算符的内部添加括号*复数表达式,因为PHP从左到右计算三元运算符**@自2.8.0起*@deprecated 6.5.0改用Plural_Forms类。**@参见Plural_Forms**@param string$表达式不带括号的表达式*@return字符串添加了括号的表达式*/公共函数括号_plural_exression($expression){$expression.=“;”;$res=“”;$depth=0;for($i=0;$i<strlen($expression)++$i){$char=$表达式[$i];开关($char){案例“?”:$res.='?(';++$深度;断裂;案例“:”:$res.='):(';断裂;案例';':$资源=str_repeat(')',$depth)。';';$depth=0;断裂;违约:$资源=$烧焦;}}return rtrim($res,';');}/***准备翻译标题。**@自2.8.0起**@param string$翻译*@return数组<string,string>Translation头*/公共函数make_headers($translation){$headers=数组();//有时使用“”而不是真正的新行。$translation=str_replace('\n',“\n”,$translation);$lines=爆炸(“\n”,$translation);foreach($lines作为$line){$parts=爆炸(':',$line,2);if(!isset($部分[1])){继续;}$headers[trim($parts[0])]=修剪($parts[1]);}返回$headers;}/***设置翻译标题。**@自2.8.0起**@param字符串$header*@param字符串$value*/公共函数set_header($header,$value){父项::set_header($header,$value);if(“复数形式”===$header){列表($nplurals,$expression)=$this->nplurals_and_expression_from_header($this->get_header,“多表单”);$this->_nplurals=$nplurals;$this->_gettext_select_plural_form=$this->生成plural_form_function($nplurals,$expression);}}}

变更日志

版本描述
2.8.0介绍。

用户贡献的笔记

你必须登录在能够发表注释或反馈之前。