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'));
 }
Exemplo n.º 2
0
 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)));
 }
Exemplo n.º 3
0
/**
 * 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);
}