XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
gettext_reader Class Reference

Public Member Functions

 find_string ($string, $start=-1, $end=-1)
 
 get_original_string ($num)
 
 get_plural_forms ()
 
 get_translation_string ($num)
 
 gettext_reader ($Reader, $enable_cache=true)
 
 load_tables ()
 
 ngettext ($single, $plural, $number)
 
 read ($bytes)
 
 readint ()
 
 readintarray ($count)
 
 sanitize_plural_expression ($expr)
 
 select_string ($n)
 
 translate ($string)
 

Public Attributes

 $BYTEORDER = 0
 
 $cache_translations = NULL
 
 $enable_cache = false
 
 $error = 0
 
 $originals = NULL
 
 $pluralheader = NULL
 
 $short_circuit = false
 
 $STREAM = NULL
 
 $table_originals = NULL
 
 $table_translations = NULL
 
 $total = 0
 
 $translations = NULL
 

Detailed Description

Provides a simple gettext replacement that works independently from the system's gettext abilities. It can read MO files and use them for translating strings. The files are passed to gettext_reader as a Stream (see streams.php)

This version has the ability to cache all strings and translations to speed up the string lookup. While the cache is enabled by default, it can be switched off with the second parameter in the constructor (e.g. whenusing very large MO files that you don't want to keep in memory)

Definition at line 36 of file gettext.php.

Member Function Documentation

gettext_reader::find_string (   $string,
  $start = -1,
  $end = -1 
)

Binary search for string

private

Parameters
stringstring
intstart (internally used in recursive function)
intend (internally used in recursive function)
Returns
int string number (offset in originals table)

Definition at line 208 of file gettext.php.

References $start, $total, and get_original_string().

Referenced by ngettext(), and translate().

Here is the call graph for this function:

Here is the caller graph for this function:

gettext_reader::get_original_string (   $num)

Returns a string from the "originals" table

private

Parameters
intnum Offset number of original string
Returns
string Requested string if found, otherwise ''

Definition at line 172 of file gettext.php.

References $data.

Referenced by find_string().

Here is the caller graph for this function:

gettext_reader::get_plural_forms ( )

Get possible plural forms from MO header

private

Returns
string plural form header

Definition at line 309 of file gettext.php.

References $pluralheader, get_translation_string(), load_tables(), and sanitize_plural_expression().

Referenced by select_string().

Here is the call graph for this function:

Here is the caller graph for this function:

gettext_reader::get_translation_string (   $num)

Returns a string from the "translations" table

private

Parameters
intnum Offset number of original string
Returns
string Requested string if found, otherwise ''

Definition at line 189 of file gettext.php.

References $data.

Referenced by get_plural_forms(), ngettext(), and translate().

Here is the caller graph for this function:

gettext_reader::gettext_reader (   $Reader,
  $enable_cache = true 
)

Constructor

Parameters
objectReader the StreamReader object
booleanenable_cache Enable or disable caching of strings (default on)

Definition at line 101 of file gettext.php.

References $enable_cache, elseif(), error(), read(), and readint().

Here is the call graph for this function:

gettext_reader::load_tables ( )

Loads the translation tables from the MO file into the cache If caching is enabled, also loads all strings into a cache to speed up translation lookups

private

Definition at line 140 of file gettext.php.

References $i, $total, and readintarray().

Referenced by get_plural_forms(), and translate().

Here is the call graph for this function:

Here is the caller graph for this function:

gettext_reader::ngettext (   $single,
  $plural,
  $number 
)

Plural version of gettext

public

Parameters
stringsingle
stringplural
stringnumber
Returns
translated plural form

Definition at line 361 of file gettext.php.

References $result, find_string(), get_translation_string(), and select_string().

Here is the call graph for this function:

gettext_reader::read (   $bytes)

Definition at line 75 of file gettext.php.

Referenced by gettext_reader().

Here is the caller graph for this function:

gettext_reader::readint ( )

Reads a 32bit Integer from the Stream

private

Returns
Integer from the Stream

Definition at line 63 of file gettext.php.

Referenced by gettext_reader().

Here is the caller graph for this function:

gettext_reader::readintarray (   $count)

Reads an array of Integers from the Stream

Parameters
intcount How many elements should be read
Returns
Array of Integers

Definition at line 85 of file gettext.php.

Referenced by load_tables().

Here is the caller graph for this function:

gettext_reader::sanitize_plural_expression (   $expr)

Sanitize plural form expression for use in PHP eval call.

private

Returns
string sanitized plural form expression

Definition at line 274 of file gettext.php.

References $i, and $p.

Referenced by get_plural_forms().

Here is the caller graph for this function:

gettext_reader::select_string (   $n)

Detects which plural form to take

private

Parameters
ncount
Returns
int array index of the right plural form

Definition at line 338 of file gettext.php.

References $total, and get_plural_forms().

Referenced by ngettext().

Here is the call graph for this function:

Here is the caller graph for this function:

gettext_reader::translate (   $string)

Translates a string

public

Parameters
stringstring to be translated
Returns
string translated string (or original, if not found)

Definition at line 247 of file gettext.php.

References find_string(), get_translation_string(), and load_tables().

Here is the call graph for this function:

Member Data Documentation

gettext_reader::$BYTEORDER = 0

Definition at line 41 of file gettext.php.

gettext_reader::$cache_translations = NULL

Definition at line 51 of file gettext.php.

gettext_reader::$enable_cache = false

Definition at line 44 of file gettext.php.

Referenced by gettext_reader().

gettext_reader::$error = 0

Definition at line 38 of file gettext.php.

gettext_reader::$originals = NULL

Definition at line 45 of file gettext.php.

gettext_reader::$pluralheader = NULL

Definition at line 47 of file gettext.php.

Referenced by get_plural_forms().

gettext_reader::$short_circuit = false

Definition at line 43 of file gettext.php.

gettext_reader::$STREAM = NULL

Definition at line 42 of file gettext.php.

gettext_reader::$table_originals = NULL

Definition at line 49 of file gettext.php.

gettext_reader::$table_translations = NULL

Definition at line 50 of file gettext.php.

gettext_reader::$total = 0

Definition at line 48 of file gettext.php.

Referenced by find_string(), load_tables(), and select_string().

gettext_reader::$translations = NULL

Definition at line 46 of file gettext.php.


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