internationalization in php: pmwiki’s approach dr. patrick r. michaud september 13, 2005

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

Upload: amelia-taylor

Post on 01-Jan-2016

217 views

Category:

Documents


2 download

TRANSCRIPT

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

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

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

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

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

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

Internationalization is often abbreviated “i18n”

Internationalization18 characters

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

We want to provide language-specific programmatic prompts

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

We want to provide language-specific programmatic prompts

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

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

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

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

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

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

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

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

Summary of i18n in PmWiki

Simple translation table for phrase => translation

Phrase keys as printable values

Select proper encoding type and locale