本文整理汇总了PHP中Translations::translate_plural方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::translate_plural方法的具体用法?PHP Translations::translate_plural怎么用?PHP Translations::translate_plural使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translations
的用法示例。
在下文中一共展示了Translations::translate_plural方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
function test_translate_plural()
{
$entry_incomplete = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas', 'translations' => array('babax')));
$entry_toomany = new Translation_Entry(array('singular' => 'wink', 'plural' => 'winks', 'translations' => array('winki', 'winka', 'winko')));
$entry_2 = new Translation_Entry(array('singular' => 'dyado', 'plural' => 'dyados', 'translations' => array('dyadox', 'dyadoy')));
$domain = new Translations();
$domain->add_entry($entry_incomplete);
$domain->add_entry($entry_toomany);
$domain->add_entry($entry_2);
$this->assertEquals('other', $domain->translate_plural('other', 'others', 1));
$this->assertEquals('others', $domain->translate_plural('other', 'others', 111));
// too few translations + cont logic
$this->assertEquals('babas', $domain->translate_plural('baba', 'babas', 2));
$this->assertEquals('babas', $domain->translate_plural('baba', 'babas', 0));
$this->assertEquals('babas', $domain->translate_plural('baba', 'babas', -1));
$this->assertEquals('babas', $domain->translate_plural('baba', 'babas', 999));
// proper
$this->assertEquals('dyadox', $domain->translate_plural('dyado', 'dyados', 1));
$this->assertEquals('dyadoy', $domain->translate_plural('dyado', 'dyados', 0));
$this->assertEquals('dyadoy', $domain->translate_plural('dyado', 'dyados', 18881));
$this->assertEquals('dyadoy', $domain->translate_plural('dyado', 'dyados', -18881));
}
示例2: format_plural
/**
* Format a string containing a count of items.
*
* This function ensures that the string is pluralized correctly. Since t() is
* called by this function, make sure not to pass already-localized strings to
* it.
*
* For example:
* @code
* $output = format_plural($node->comment_count, '1 comment', '@count comments');
* @endcode
*
* Example with additional replacements:
* @code
* $output = format_plural($update_count,
* 'Changed the content type of 1 post from %old-type to %new-type.',
* 'Changed the content type of @count posts from %old-type to %new-type.',
* array('%old-type' => $info->old_type, '%new-type' => $info->new_type)));
* @endcode
*
* @param $count
* The item count to display.
* @param $singular
* The string for the singular case. Please make sure it is clear this is
* singular, to ease translation (e.g. use "1 new comment" instead of "1 new").
* Do not use @count in the singular string.
* @param $plural
* The string for the plural case. Please make sure it is clear this is plural,
* to ease translation. Use @count in place of the item count, as in "@count
* new comments".
* @param $args
* An associative array of replacements to make after translation. Incidences
* of any key in this array are replaced with the corresponding value.
* Based on the first character of the key, the value is escaped and/or themed:
* - !variable: inserted as is
* - @variable: escape plain text to HTML (check_plain)
* - %variable: escape text and theme as a placeholder for user-submitted
* content (check_plain + theme_placeholder)
* Note that you do not need to include @count in this array.
* This replacement is done automatically for the plural case.
* @param $langcode
* Optional language code to translate to a language other than
* what is used to display the page.
* @return
* A translated string.
*/
function format_plural($count, $singular, $plural, $args = array(), $langcode = NULL, $context = NULL)
{
global $language, $cfg;
$args['@count'] = $count;
if ($count == 1) {
return _t($singular, $args, $langcode);
}
$po = new Translations();
$po->merge_with($language['translate']);
// Get the plural index through the gettext formula.
$plural = $po->translate_plural($singular, $plural, $count, $context);
return _t($plural, $args, $langcode);
}