本文整理汇总了PHP中LanguageConverter::translate方法的典型用法代码示例。如果您正苦于以下问题:PHP LanguageConverter::translate方法的具体用法?PHP LanguageConverter::translate怎么用?PHP LanguageConverter::translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LanguageConverter
的用法示例。
在下文中一共展示了LanguageConverter::translate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: translate
function translate($text, $toVariant)
{
if ($toVariant == 'uz-cyrl') {
$text = str_replace('ye', 'е', $text);
$text = str_replace('Ye', 'Е', $text);
$text = str_replace('YE', 'Е', $text);
// "е" after consonants, otherwise "э" (see above)
$text = preg_replace('/([BVGDJZYKLMNPRSTFXCWQʻ‘H])E/u', '$1Е', $text);
$text = preg_replace('/([bvgdjzyklmnprstfxcwqʻ‘h])e/ui', '$1е', $text);
}
return parent::translate($text, $toVariant);
}
示例2: translate
/**
* It translates text into variant, specials:
* - ommiting roman numbers
*/
function translate($text, $toVariant)
{
$breaks = '[^\\w\\x80-\\xff]';
// regexp for roman numbers
$roman = 'M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})';
$reg = '/^' . $roman . '$|^' . $roman . $breaks . '|' . $breaks . $roman . '$|' . $breaks . $roman . $breaks . '/';
$matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
$m = array_shift($matches);
$ret = $this->mTables[$toVariant]->replace($m[0]);
$mstart = $m[1] + strlen($m[0]);
foreach ($matches as $m) {
$ret .= substr($text, $mstart, $m[1] - $mstart);
$ret .= parent::translate($m[0], $toVariant);
$mstart = $m[1] + strlen($m[0]);
}
return $ret;
}
示例3: translate
/**
* It translates text into variant, specials:
* - ommiting roman numbers
*
* @param string $text
* @param bool $toVariant
*
* @throws MWException
* @return string
*/
function translate($text, $toVariant)
{
$this->loadTables();
/* From Kazakh interface, maybe we need it later
$breaks = '[^\w\x80-\xff]';
// regexp for roman numbers
$roman = 'M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})';
$roman = '';
$reg = '/^'.$roman.'$|^'.$roman.$breaks.'|'.$breaks.$roman.'$|'.$breaks.$roman.$breaks.'/';
$matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
$m = array_shift($matches);
if( !isset( $this->mTables[$toVariant] ) ) {
throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
}
$ret = $this->mTables[$toVariant]->replace( $m[0] );
$mstart = $m[1]+strlen($m[0]);
foreach($matches as $m) {
$ret .= substr($text, $mstart, $m[1]-$mstart);
$ret .= parent::translate($m[0], $toVariant);
$mstart = $m[1] + strlen($m[0]);
}
return $ret;
*/
if (!isset($this->mTables[$toVariant])) {
throw new MWException("Broken variant table: " . implode(',', array_keys($this->mTables)));
}
return parent::translate($text, $toVariant);
}
示例4: translate
/**
* It translates text into variant
*
* @param string $text
* @param string $toVariant
*
* @return string
*/
function translate($text, $toVariant)
{
$text = parent::translate($text, $toVariant);
switch ($toVariant) {
case 'kk-cyrl':
case 'kk-kz':
$letters = KK_L_UC . KK_L_LC . 'ʺʹ#0123456789';
break;
case 'kk-latn':
case 'kk-tr':
$letters = KK_C_UC . KK_C_LC . '№0123456789';
break;
case 'kk-arab':
case 'kk-cn':
$letters = KK_C_UC . KK_C_LC . ',;\\?%\\*№0123456789';
break;
default:
return $text;
}
// disable conversion variables like $1, $2...
$varsfix = '\\$[0-9]';
$matches = preg_split('/' . $varsfix . '[^' . $letters . ']+/u', $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
$mstart = 0;
$ret = '';
foreach ($matches as $m) {
$ret .= substr($text, $mstart, $m[1] - $mstart);
$ret .= $this->regsConverter($m[0], $toVariant);
$mstart = $m[1] + strlen($m[0]);
}
return $ret;
}