Pluf_Translation Class Reference

List of all members.

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


Detailed Description

Translation utility.

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.


Member Function Documentation

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'

Parameters:
array Available languages in the system
string String of comma separated accepted languages ('')
Returns:
string Language 2 or 5 letter iso code, default is 'en'

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

Author:
Matthias Bauer http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License 2.1 http://opensource.org/licenses/apache2.0.php Apache License 2.0

static Pluf_Translation::getCachedFile ( file  )  [static]

Load optimized version of a language file if available.

Returns:
mixed false or array with value

static Pluf_Translation::cacheFile ( file,
hash 
) [static]

Cache an optimized version of a language file.

Parameters:
string File
array Parsed hash


Member Data Documentation

Pluf_Translation::$plural_forms [static]

Initial value:

 array(
                         'fr' => 'plural_2gt1',
                         'en' => 'plural_2not1', // This is the default.
                         'de' => 'plural_2not1',
                                        )


The documentation for this class was generated from the following file:

Generated on Wed Feb 3 15:44:52 2010 for Pluf by  doxygen