\Pluf_Translation

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.

Summary

Methods
Properties
Constants
loadSetLocale()
getLocale()
getPluralForm()
getAcceptedLanguage()
sprintf()
plural_2gt1()
plural_2not1()
readPoFile()
getCachedFile()
cacheFile()
$plural_forms
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$plural_forms

$plural_forms : 

Type

Methods

loadSetLocale()

loadSetLocale(  $lang) 

Parameters

$lang

getLocale()

getLocale() 

getPluralForm()

getPluralForm(  $locale) 

Get the plural form for a given locale.

Parameters

$locale

getAcceptedLanguage()

getAcceptedLanguage(  $available,   $accepted = '') : string

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

$available
$accepted

Returns

string —

Language 2 or 5 letter iso code, default is 'en'

sprintf()

sprintf(  $string,   $words = array()) 

Given a key indexed array, do replacement using the %%key%% in the string.

Parameters

$string
$words

plural_2gt1()

plural_2gt1(  $n) 

French, Brazilian Portuguese

Parameters

$n

plural_2not1()

plural_2not1(  $n) 

Parameters

$n

readPoFile()

readPoFile(  $file) 

Read a .

po file.

Based on the work by Matthias Bauer with some little cosmetic fixes.

Parameters

$file

getCachedFile()

getCachedFile(  $file) : mixed

Load optimized version of a language file if available.

Parameters

$file

Returns

mixed —

false or array with value

cacheFile()

cacheFile(  $file,   $hash) 

Cache an optimized version of a language file.

Parameters

$file
$hash