msgfmt_format_subpatterns.phpt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --TEST--
  2. msgfmt_format() with subpatterns
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded('intl'))
  6. die('skip intl extension not enabled');
  7. if (version_compare(INTL_ICU_VERSION, '4.8') < 0)
  8. die('skip for ICU 4.8+');
  9. --FILE--
  10. <?php
  11. /*
  12. * Format a number using misc locales/patterns.
  13. */
  14. function ut_main()
  15. {
  16. $pattern=<<<_MSG_
  17. {0, select,
  18. female {{1, plural, offset:1
  19. =0 {{2} does not give a party.}
  20. =1 {{2} invites {3} to her party.}
  21. =2 {{2} invites {3} and one other person to her party.}
  22. other {{2} invites {3} as one of the # people invited to her party.}}}
  23. male {{1, plural, offset:1
  24. =0 {{2} does not give a party.}
  25. =1 {{2} invites {3} to his party.}
  26. =2 {{2} invites {3} and one other person to his party.}
  27. other {{2} invites {3} as one of the # other people invited to his party.}}}
  28. other {{1, plural, offset:1
  29. =0 {{2} does not give a party.}
  30. =1 {{2} invites {3} to their party.}
  31. =2 {{2} invites {3} and one other person to their party.}
  32. other {{2} invites {3} as one of the # other people invited to their party.}}}}
  33. _MSG_;
  34. $args = array(
  35. array('female', 0, 'Alice', 'Bob'),
  36. array('male', 1, 'Alice', 'Bob'),
  37. array('none', 2, 'Alice', 'Bob'),
  38. array('female', 27, 'Alice', 'Bob'),
  39. );
  40. $str_res = '';
  41. $fmt = ut_msgfmt_create( 'en_US', $pattern );
  42. if(!$fmt) {
  43. $str_res .= dump(intl_get_error_message())."\n";
  44. return $str_res;
  45. }
  46. foreach ($args as $arg) {
  47. $str_res .= dump( ut_msgfmt_format($fmt, $arg) ). "\n";
  48. $str_res .= dump( ut_msgfmt_format_message('en_US', $pattern, $arg) ) . "\n";
  49. }
  50. return $str_res;
  51. }
  52. include_once( 'ut_common.inc' );
  53. // Run the test
  54. ut_run();
  55. ?>
  56. --EXPECT--
  57. 'Alice does not give a party.'
  58. 'Alice does not give a party.'
  59. 'Alice invites Bob to his party.'
  60. 'Alice invites Bob to his party.'
  61. 'Alice invites Bob and one other person to their party.'
  62. 'Alice invites Bob and one other person to their party.'
  63. 'Alice invites Bob as one of the 26 people invited to her party.'
  64. 'Alice invites Bob as one of the 26 people invited to her party.'