1. Internationalisation with PHP This presentation is about the “Intl” extension for PHP. By Daniel Rhodes of Warp Asylum http://www.warpasylum.co.uk
2. What is the “Intl” extension? <ul><li>A wrapper for ICU – International Components for Unicode (http://site.icu-project.org)
3. Let's us... </li></ul><ul><ul><li>Compare and sort strings
4. Format numbers, times and dates
5. Format text </li></ul></ul><ul><li>... as appropriate for a given locale!
6. See PHP docs at http://www.php.net/manual/en/book.intl.php </li></ul>
7. Example locale differences <ul>Here are some example locale differences that we might like to tackle: <li>Japan's official calendar counts years by using emperor's era name followed by year number of that emperor's reign. 2011 is “Heisei 23” for example.
8. Korean language system of counting in tens of thousands. 10,000 is “one man” for example.
9. German alphabet with its umlauted vowels (ä, ö and ü) and eszett (ß) </li></ul>
10. How to get the extension <ul><li>A wrapper for ICU so you'll need that first!
11. Bundled extension as of PHP 5.3.0 (compile freaks will want --enable-intl)
12. PHP 5.2.0 onwards can get the extension from PECL
42. ICU locales support UCA keywords (eg. numbers=roman) </li></ul>
43. Challenge for you! <ul>We've seen that Collator can quite easily give us the phonebook and dictionary sort orders for German. But can you use Collator to get the Austrian phonebook sort order? Try experimenting with: <li>The collation string passed to Collator::__construct()
44. Collator::setAttribute() </li></ul>
45. Case study – Japanese era <ul><li>Gory details at http://en.wikipedia.org/wiki/Japanese_era
46. Basically the current emperor's reign is named “Heisei” and 2011 is Heisei 23 as it's the 23 rd year of the current emperor's reign
47. Month and day same as Gregorian
48. Used for more official paperwork and formal situations (Gregorian year used day-to-day)
49. Let's see how Intl can present this format for a Japanese locale... </li></ul>
50. Case study – Japanese era
51. Case study – Japanese era <ul><li>Works out of the box!
52. Because calendar=japanese supported by UCA
53. Give IntlDateFormatter::__construct() [email_address] =uca_calendar_type and IntlDateFormatter::TRADITIONAL to get non-Gregorian calendars </li></ul>
54. Challenge for you! <ul>Ignoring the fact that they refer to months of the Chinese lunar calendar, can you get IntlDateFormatter to output dates for ja_JP using the traditional month names (see http://en.wikipedia.org/wiki/Japanese_calendar)? Try experimenting with: <li>IntlDateFormatter::getPattern()
55. IntlDateFormatter::setPattern() </li></ul>
56. Case study – Korean numbers <ul><li>Let's try to spell out numbers in Korean
57. Korean equivalent of the newspaper style “four million, two hundred thousand and forty-seven”
58. So need Korean words / characters for numbers
59. BUT Korean counts in ten thousands
60. One, ten, hundred, thousand, man (ten thousand), eok (100 million ie. Ten thousand man), jo (one trillion ie. Ten thousand eok)
61. See http://en.wikipedia.org/wiki/Korean_numerals </li></ul>
62. Case study – Korean numbers
63. Case study – Korean numbers <ul><li>Korean locale is supported but with no number spellout rules
64. We have to create, and then set, our own spellout rules
65. Luckily we can base our rules on the already present Japanese spellout rules!
66. Japanese also counts in ten thousands and uses non-Arabic numerals </li></ul>
67. Case study – Korean numbers <ul><li>Our rules: </li></ul>
68. Case study – Korean numbers
69. Challenge for you! <ul>Can you extend the Korean spellout rules to support the following?: <li>Hangul as used in the North
71. Financial / anti-forgery Hanja
72. (See http://en.wikipedia.org/wiki/Korean_numerals) </li></ul>
73. Summary <ul><li>Not every bit of every locale works out of the box
74. But we can usually set our own rules
75. Don't need to install locales on our OS
76. More flexible and fine-grained than system locales (ie. setlocale() and money_format() etc)
77. NumberFormatter class also supports durations
78. Resource bundles for locale-specific messages, patterns etc supported with ResourceBundle class </li></ul>
79. Links <ul><li>Should be able to get a PHP source code pack from wherever you got this presentation