예제 #1
0
function ut_main()
{
    $res_str = '';
    $fmt = ut_msgfmt_create("en_US", "{0,number} monkeys on {1,number} trees");
    // Get default patten.
    $res_str .= "Default pattern: '" . ut_msgfmt_get_pattern($fmt) . "'\n";
    $res_str .= "Formatting result: " . ut_msgfmt_format($fmt, array(123, 456)) . "\n";
    // Set a new pattern.
    $pattern = "{0,number} trees hosting {1,number} monkeys";
    $res = ut_msgfmt_set_pattern($fmt, $pattern);
    if ($res === false) {
        $res_str .= ut_msgfmt_get_error_message($fmt) . " (" . ut_msgfmt_get_error_code($fmt) . ")\n";
    }
    // Check if the pattern has been changed.
    $res = ut_msgfmt_get_pattern($fmt);
    if ($res === false) {
        $res_str .= ut_msgfmt_get_error_message($fmt) . " (" . ut_msgfmt_get_error_code($fmt) . ")\n";
    }
    $res_str .= "New pattern: '" . ut_msgfmt_get_pattern($fmt) . "'\n";
    $res_str .= "Formatted message: " . ut_msgfmt_format($fmt, array(123, 456)) . "\n";
    ut_msgfmt_set_pattern($fmt, str_repeat($pattern, 10));
    $res_str .= "New pattern: '" . ut_msgfmt_get_pattern($fmt) . "'\n";
    $res_str .= "Formatted message: " . ut_msgfmt_format($fmt, array(123, 456)) . "\n";
    return $res_str;
}
예제 #2
0
function ut_main()
{
    $pattern = <<<_MSG_
{0, select,
  female {{1, plural, offset:1
      =0 {{2} does not give a party.}
      =1 {{2} invites {3} to her party.}
      =2 {{2} invites {3} and one other person to her party.}
     other {{2} invites {3} as one of the # people invited to her party.}}}
  male   {{1, plural, offset:1
      =0 {{2} does not give a party.}
      =1 {{2} invites {3} to his party.}
      =2 {{2} invites {3} and one other person to his party.}
     other {{2} invites {3} as one of the # other people invited to his party.}}}
  other {{1, plural, offset:1
      =0 {{2} does not give a party.}
      =1 {{2} invites {3} to their party.}
      =2 {{2} invites {3} and one other person to their party.}
      other {{2} invites {3} as one of the # other people invited to their party.}}}}
_MSG_;
    $args = array(array('female', 0, 'Alice', 'Bob'), array('male', 1, 'Alice', 'Bob'), array('none', 2, 'Alice', 'Bob'), array('female', 27, 'Alice', 'Bob'));
    $str_res = '';
    $fmt = ut_msgfmt_create('en_US', $pattern);
    if (!$fmt) {
        $str_res .= dump(intl_get_error_message()) . "\n";
        return $str_res;
    }
    foreach ($args as $arg) {
        $str_res .= dump(ut_msgfmt_format($fmt, $arg)) . "\n";
        $str_res .= dump(ut_msgfmt_format_message('en_US', $pattern, $arg)) . "\n";
    }
    return $str_res;
}
function ut_main()
{
    $pattern = <<<_MSG_
{gender_of_host, select,
  female {{num_guests, plural, offset:1
      =0 {{host} does not give a party.}
      =1 {{host} invites {guest} to her party.}
      =2 {{host} invites {guest} and one other person to her party.}
     other {{host} invites {guest} as one of the # people invited to her party.}}}
  male   {{num_guests, plural, offset:1
      =0 {{host} does not give a party.}
      =1 {{host} invites {guest} to his party.}
      =2 {{host} invites {guest} and one other person to his party.}
     other {{host} invites {guest} as one of the # people invited to his party.}}}
  other {{num_guests, plural, offset:1
      =0 {{host} does not give a party.}
      =1 {{host} invites {guest} to their party.}
      =2 {{host} invites {guest} and one other person to their party.}
     other {{host} invites {guest} as one of the # people invited to their party.}}}}
_MSG_;
    $args = array(array('gender_of_host' => 'female', 'num_guests' => 0, 'host' => 'Alice', 'guest' => 'Bob'), array('gender_of_host' => 'male', 'num_guests' => 1, 'host' => 'Alice', 'guest' => 'Bob'), array('gender_of_host' => 'none', 'num_guests' => 2, 'host' => 'Alice', 'guest' => 'Bob'), array('gender_of_host' => 'female', 'num_guests' => 27, 'host' => 'Alice', 'guest' => 'Bob'));
    $str_res = '';
    $fmt = ut_msgfmt_create('en_US', $pattern);
    if (!$fmt) {
        $str_res .= dump(intl_get_error_message()) . "\n";
        return $str_res;
    }
    foreach ($args as $arg) {
        $str_res .= dump(ut_msgfmt_format($fmt, $arg)) . "\n";
        $str_res .= dump(ut_msgfmt_format_message('en_US', $pattern, $arg)) . "\n";
    }
    return $str_res;
}
예제 #4
0
function ut_main()
{
    $locales = array('en_US' => "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree", 'ru_UA' => "{0,number,integer} мавп на {1,number,integer} деревах це {2,number} мавпи на кожному деревi", 'de' => "{0,number,integer} Affen über {1,number,integer} Bäume um {2,number} Affen pro Baum", 'en_UK' => "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree", 'root' => '{0,whatever} would not work!', 'fr' => "C'est la vie!");
    $str_res = '';
    $m = 4560;
    $t = 123;
    foreach ($locales as $locale => $pattern) {
        $str_res .= "\nLocale is: {$locale}\n";
        $fmt = ut_msgfmt_create($locale, $pattern);
        if (!$fmt) {
            $str_res .= dump(intl_get_error_message()) . "\n";
            continue;
        }
        $str_res .= dump(ut_msgfmt_format($fmt, array($m, $t, $m / $t))) . "\n";
        $str_res .= dump(ut_msgfmt_format_message($locale, $pattern, array($m, $t, $m / $t))) . "\n";
    }
    return $str_res;
}
예제 #5
0
<?php

include_once 'ut_common.inc';
$GLOBALS['oo-mode'] = true;
$res_str = '';
/*
 * Clone
 */
$fmt = ut_msgfmt_create("en_US", "{0,number} monkeys on {1,number} trees");
// Get default patten.
$res_str .= "Formatting result: " . ut_msgfmt_format($fmt, array(123, 456)) . "\n";
$fmt_clone = clone $fmt;
// Set a new pattern.
$pattern = "{0,number} trees hosting {1,number} monkeys";
$res = ut_msgfmt_set_pattern($fmt, $pattern);
$res_str .= "Formatting result: " . ut_msgfmt_format($fmt, array(123, 456)) . "\n";
$res_str .= "Formatting clone result: " . ut_msgfmt_format($fmt_clone, array(123, 456)) . "\n";
echo $res_str;