Static Public Member Functions | |
| static | loadSetLocale ($lang) |
| static | getLocale () |
| static | getPluralForm ($locale) |
| static | getAcceptedLanguage ($available, $accepted='') |
| static | sprintf ($string, $words=array()) |
| static | plural_2gt1 ($n) |
| static | plural_2not1 ($n) |
| static | readPoFile ($file) |
| static | getCachedFile ($file) |
| static | cacheFile ($file, $hash) |
Static Public Attributes | |
| static | $plural_forms |
This class provides utilities to load and cache translation strings. The functions using the values are directly available when loading Pluf. They are __ and _n for simple translations and for plural dependent translations respectively.
Based on benchmarking by http://mel.melaxis.com/devblog/2006/04/10/benchmarking-php- \ localization-is-gettext-fast-enough/ the string id system is really fast, so here the system is using a .ini file approach with a string id cache.
Why reimplementing a gettext system when one is already available? It is because the PHP gettext extension requires the corresponding locale to be installed system wide to load the corresponding translations. If your host has no locales outside English installed, you can only provide English to your users. Which is not really nice.
| static Pluf_Translation::loadSetLocale | ( | $ | lang | ) | [static] |
| static Pluf_Translation::getLocale | ( | ) | [static] |
| static Pluf_Translation::getPluralForm | ( | $ | locale | ) | [static] |
Get the plural form for a given locale.
| static Pluf_Translation::getAcceptedLanguage | ( | $ | available, | |
| $ | accepted = '' | |||
| ) | [static] |
Return the "best" accepted language from the list of available languages.
Use $_SERVER['HTTP_ACCEPT_LANGUAGE'] if the accepted language list is empty. The list must be something like: 'da, en-gb;q=0.8, en;q=0.7'
| array | Available languages in the system | |
| string | String of comma separated accepted languages ('') |
| static Pluf_Translation::sprintf | ( | $ | string, | |
| $ | words = array() | |||
| ) | [static] |
Given a key indexed array, do replacement using the %key%% in the string.
| static Pluf_Translation::plural_2gt1 | ( | $ | n | ) | [static] |
French, Brazilian Portuguese
| static Pluf_Translation::plural_2not1 | ( | $ | n | ) | [static] |
| static Pluf_Translation::readPoFile | ( | $ | file | ) | [static] |
Read a .po file.
Based on the work by Matthias Bauer with some little cosmetic fixes.
http://wordpress-soc-2007.googlecode.com/svn/trunk/moeffju/php-msgfmt/msgfmt-functions.php 2007 Matthias Bauer
| static Pluf_Translation::getCachedFile | ( | $ | file | ) | [static] |
Load optimized version of a language file if available.
| static Pluf_Translation::cacheFile | ( | $ | file, | |
| $ | hash | |||
| ) | [static] |
Cache an optimized version of a language file.
| string | File | |
| array | Parsed hash |
Pluf_Translation::$plural_forms [static] |
Initial value:
array(
'fr' => 'plural_2gt1',
'en' => 'plural_2not1', // This is the default.
'de' => 'plural_2not1',
)