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

Post on 01-Jan-2016

217 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

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

PmWiki is designed for needs of web and content administrators

Easy to install and upgrade

Simple configuration

Skin capabilities

Markup customization

PmWiki has an active user base.

400+ mailing list subscribers

Hundreds of sites globally

200+ “add-on” recipes

14 languages

Internationalization is often abbreviated “i18n”

Internationalization18 characters

We want to provide language-specific programmatic prompts

We want to provide language-specific programmatic prompts

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

Translations for phrases are held in a global lookup table

$XL = array( ‘Edit’ => ‘Editer’, ‘View’ => ‘Vue’, ‘Save’ => ‘Enregistrer’,

…);

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.

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);

PmWiki allows the translation table to be loaded from wiki pages

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

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”

Summary of i18n in PmWiki

Simple translation table for phrase => translation

Phrase keys as printable values

Select proper encoding type and locale

top related