本文整理汇总了PHP中Translations::merge_with方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::merge_with方法的具体用法?PHP Translations::merge_with怎么用?PHP Translations::merge_with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translations
的用法示例。
在下文中一共展示了Translations::merge_with方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
function test_digit_and_merge()
{
$entry_digit_1 = new Translation_Entry(array('singular' => 1, 'translations' => array('1')));
$entry_digit_2 = new Translation_Entry(array('singular' => 2, 'translations' => array('2')));
$domain = new Translations();
$domain->add_entry($entry_digit_1);
$domain->add_entry($entry_digit_2);
$dummy_translation = new Translations();
$this->assertEquals('1', $domain->translate('1'));
$domain->merge_with($dummy_translation);
$this->assertEquals('1', $domain->translate('1'));
}
示例2: Translations
function test_translations_merge()
{
$host = new Translations();
$host->add_entry(new Translation_Entry(array('singular' => 'pink')));
$host->add_entry(new Translation_Entry(array('singular' => 'green')));
$guest = new Translations();
$guest->add_entry(new Translation_Entry(array('singular' => 'green')));
$guest->add_entry(new Translation_Entry(array('singular' => 'red')));
$host->merge_with($guest);
$this->assertEquals(3, count($host->entries));
$this->assertEquals(array(), array_diff(array('pink', 'green', 'red'), array_keys($host->entries)));
}
示例3: 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);
}