Your SlideShare is downloading. ×
0
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Internationalisation with PHP and Intl
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Internationalisation with PHP and Intl

10,298

Published on

Internationalisation with PHP and the Intl extension. Featuring source code and three real world case studies.

Internationalisation with PHP and the Intl extension. Featuring source code and three real world case studies.

Published in: Technology
7 Comments
3 Likes
Statistics
Notes
  • Just to let you all know that this slideshow is quite old now so please check http://www.php.net/manual/en/book.intl.php for the current state of play with PHP's Intl. (It looks like it's a bit more complete now than when it was at the time of making the slideshow).
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @ShellyWarren1 Glad you like it! I actually learned this stuff - the hard way - not long before writing the slides so it was all 'fresh'. Annoyingly I've never had the chance to use this in production PHP - so you could say the slides are unpolluted by real world concerns! http://www.php.net/manual/en/book.intl.php and http://site.icu-project.org are great practical and theoretical resources (respectively).
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @kehalim Great question! I've had a look (http://www.php.net/manual/en/class.locale.php) and I don't see and way to list supported locales. I think the idea is it's *supposed* to support EVERY language and locale. But as you can see from the slides some bits of some locales are missing. Perhaps whole locales are missing? If so, there is then the issue of is it missing in ICU itself or just in PHP's Intl library? (Rambling answer sorry!)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Thank You!! The best and quickest explanation, I have spent 2 days reading various posts to teach myself this stuff and boy do I wish I found this sooner!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Nice slide. any way to retrieve all supported regions/languages with php intl?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
10,298
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
32
Comments
7
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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&apos;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&apos;s official calendar counts years by using emperor&apos;s era name followed by year number of that emperor&apos;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&apos;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
  • 13. ( http://www.php.net/manual/en/install.pecl.php ) </li></ul>
  • 14. Check extension presence <ul><li>phpinfo() will look something like: </li></ul>
  • 15. First play and test
  • 16. Functionality overview <ul><li>Sort and compare strings (Collator class)
  • 17. Format currency amounts and other numbers (NumberFormatter class)
  • 18. Locale getting, setting and information (Locale class)
  • 19. Format natural language sentences (MessageFormatter class)
  • 20. Format dates (IntlDateFormatter class)
  • 21. And much more! (Transliterator class not yet implemented) </li></ul>
  • 22. Case study – sorting German <ul><li>More than one native way to sort!
  • 23. Dictionary , phonebook and Austrian sort orders
  • 24. See http://de.wikipedia.org/wiki/Alphabetische_Sortierung
  • 25. Basically English A to Z order but with... </li><ul><li>Where do the umlauted vowels go?
  • 26. Where does eszett go? </li></ul><li>...to answer </li></ul>
  • 27. Case study – sorting German <ul>Let&apos;s try plain vanilla PHP first: </ul>
  • 28. Case study – sorting German <ul><li>With sort() we seem to coincidentally (?!) be getting the Austrian phonebook sort order
  • 29. What about the other two sort orders?
  • 30. Well, sort() supports system locales...
  • 31. ...so let&apos;s try that! </li></ul>
  • 32. Case study – sorting German
  • 33. Case study – sorting German <ul><li>System locale of de_DE.utf8, if present! , gives us dictionary sort order
  • 34. Setlocale() [and fgetcsv(), nl_langinfo(), localeconv() etc] needs system locale installed on OS
  • 35. But system locale can be spelled differently, or be absent! , on different OS
  • 36. And we still haven&apos;t got phonebook sort order!
  • 37. A job for Intl... </li></ul>
  • 38. Case study – sorting German
  • 39. Case study – sorting German <ul>ICU locales and system locales are different and independent: <li>ICU locales don&apos;t need to be installed on the OS
  • 40. ICU locales do not specify encoding (as ICU is for Unicode)
  • 41. ICU locales specify variant locales differently
  • 42. ICU locales support UCA keywords (eg. numbers=roman) </li></ul>
  • 43. Challenge for you! <ul>We&apos;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&apos;s reign is named “Heisei” and 2011 is Heisei 23 as it&apos;s the 23 rd year of the current emperor&apos;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&apos;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&apos;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
  • 70. Hanja
  • 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&apos;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
  • 80. http://site.icu-project.org
  • 81. http://www.php.net/manual/en/intro.intl.php
  • 82. http://de.wikipedia.org/wiki/Alphabetische_Sortierung
  • 83. http://en.wikipedia.org/wiki/Japanese_era
  • 84. http://en.wikipedia.org/wiki/Korean_numerals </li></ul>

×