internationalization in php: pmwiki’s approach dr. patrick r. michaud september 13, 2005
TRANSCRIPT
![Page 1: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/1.jpg)
Internationalization in PHP:PmWiki’s approach
Dr. Patrick R. Michaud
September 13, 2005
![Page 2: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/2.jpg)
This presentation demonstrates internationalization (i18n) in PmWiki
Introduction to PmWiki
Implementing I18nin PmWiki
Internationalizationissues
Unicode UTF-8 ISO-8859-1 CJKM
![Page 3: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/3.jpg)
PmWiki is a wiki-based system for collaborative maintenance of websites
A wiki allows editingvia a web browser
Uses simple markup(similar to email)
Easy to create pagesand links between pages
![Page 4: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/4.jpg)
PmWiki is designed for needs of web and content administrators
Easy to install and upgrade
Simple configuration
Skin capabilities
Markup customization
![Page 5: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/5.jpg)
PmWiki has an active user base.
400+ mailing list subscribers
Hundreds of sites globally
200+ “add-on” recipes
14 languages
![Page 6: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/6.jpg)
Internationalization is often abbreviated “i18n”
Internationalization18 characters
![Page 7: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/7.jpg)
We want to provide language-specific programmatic prompts
![Page 8: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/8.jpg)
We want to provide language-specific programmatic prompts
![Page 9: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/9.jpg)
In PmWiki, all prompts are passed through a special formatting function <div id='wikifoot'> <div class='footnav'> <a href='$PageUrl?action=edit'>$[Edit]</a> - <a href='$PageUrl?action=diff'>$[History]</a> - <a href='$PageUrl?action=print' target='_blank'>$[Print]</a> - <a href='$ScriptUrl/$[$Group/RecentChanges]'>$[Recent
Changes]</a> - <a href='$ScriptUrl/$[$SiteGroup/Search]'>$[Search]</a></div> <div class='lastmod'>$[Page last modified on
$LastModified]</div></div>
The $[phrase] sequence is a special markerused by PmWiki to indicate a translatablephrase
![Page 10: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/10.jpg)
Translations for phrases are held in a global lookup table
$XL = array( ‘Edit’ => ‘Editer’, ‘View’ => ‘Vue’, ‘Save’ => ‘Enregistrer’,
…);
![Page 11: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/11.jpg)
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.
![Page 12: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/12.jpg)
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);
![Page 13: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/13.jpg)
PmWiki allows the translation table to be loaded from wiki pages
![Page 14: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/14.jpg)
Proper internationalization requires selecting an appropriate character set
In HTML, specified in the <!DOCTYPE …> or in <meta …> 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
![Page 15: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/15.jpg)
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”
![Page 16: Internationalization in PHP: PmWiki’s approach Dr. Patrick R. Michaud September 13, 2005](https://reader030.vdocuments.site/reader030/viewer/2022032607/56649ec05503460f94bcacbc/html5/thumbnails/16.jpg)
Summary of i18n in PmWiki
Simple translation table for phrase => translation
Phrase keys as printable values
Select proper encoding type and locale