Presentation is loading. Please wait.

Presentation is loading. Please wait.

Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005.

Similar presentations


Presentation on theme: "Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005."— Presentation transcript:

1 Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005

2 This presentation demonstrates internationalization (i18n) in PmWiki Introduction to PmWiki Implementing I18n in PmWiki Internationalization issues Unicode UTF-8 ISO-8859-1 CJKM

3 PmWiki is a wiki-based system for collaborative maintenance of websites A wiki allows editing via a web browser Uses simple markup (similar to email) Easy to create pages and links between pages

4 PmWiki is designed for needs of web and content administrators Easy to install and upgrade Simple configuration Skin capabilities Markup customization

5 PmWiki has an active user base. 400+ mailing list subscribers Hundreds of sites globally 200+ “add-on” recipes 14 languages

6 Internationalization is often abbreviated “i18n” Internationalization 18 characters

7 We want to provide language-specific programmatic prompts

8

9 In PmWiki, all prompts are passed through a special formatting function $[Edit] - $[History] - $[Print] - $[Recent Changes] - $[Search] $[Page last modified on $LastModified] The $[phrase] sequence is a special marker used by PmWiki to indicate a translatable phrase

10 Translations for phrases are held in a global lookup table $XL = array( ‘Edit’ => ‘Editer’, ‘View’ => ‘Vue’, ‘Save’ => ‘Enregistrer’, …);

11 A special XL() function returns a phrase’s translation, or the phrase function XL($key) { global $XL; if (isset($XL[$key])) return $XL [$key]; return $key; } Phrases without a translation in the table are thus left in English.

12 Strings can be easily converted using a preg_replace() function XL($key) { global $XL; if (isset($XL[$key])) return $XL [$key]; return $key; } $str = preg_replace( '/ \\$\\[ ([^\\]]+) \\] /ex', "XL('$1'))", $str);

13 PmWiki allows the translation table to be loaded from wiki pages

14 Proper internationalization requires selecting an appropriate character set In HTML, specified in the or in tag Common choices: utf-8 (Unicode) iso-8859-1(Latin-1) Best is to standardize on utf-8 if possible PHP can have difficulties with Unicode

15 Locales can be used for language- specific dates and times. $x = strftime(‘%c’, time); “Tue Sep 13 18:21:13 2005” setlocale(‘fr_FR’); $x = strftime(‘%c’, time); “mar 13 sep 2005 18:22:23”

16 Summary of i18n in PmWiki Simple translation table for phrase => translation Phrase keys as printable values Select proper encoding type and locale


Download ppt "Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005."

Similar presentations


Ads by Google