Language translation functions.

The idea is very much stolen from the GNU translate C library.

We load a translation file and store it in the global array $translations. If a cache dir is enabled (in $settings[]), then we serialize $translations and store it as a file in the cache dir. The next call will unserialize the cached file rather than re-parse the file.

Although there is a PHP gettext () function, I prefer to use this home-grown translate function since it is simpler to work with.

  • author: Craig Knudsen <>
  • version: $Id$
  • copyright: Craig Knudsen, <>,
  • license: GNU GPL
define_languages (line 384)

Generate translated array of language names

The first is the name presented to users while the second is the filename (without the ".txt") that must exist in the translations subdirectory. Only called from admin.php and pref.php.

void define_languages ()
etooltip (line 372)

Translates and removes HTML from text, and prints it.

This is useful for tooltips, which barf on HTML.

Note: () returns the result rather than print the value.

void etooltip (string $str, [ $decode = ''])
  • string $str: Text to translate and print
  • $decode
etranslate (line 342)

Translates text and prints it.

This is just an abbreviation for:

  1. echo translate $str )

void etranslate (string $str, [string $decode = ''])
  • string $str: Text to translate and print
  • string $decode: Do we want to envoke html_entity_decode
languageToAbbrev (line 453)

Converts language names to their abbreviation.

  • return: The abbreviation ("fr" for "French")
string languageToAbbrev (string $name)
  • string $name: Name of the language (such as "French")
load_translation_text (line 157)

Loads all the language translation into an array for quick lookup.

Note: There is no need to call this manually. It will be invoked by () the first time it is called.

void load_translation_text ()
read_trans_file (line 62)

Read in a language file and cache it if we can.

void read_trans_file (string $in_file, [string $out_file = ''], [bool $strip = true])
  • string $in_file: The name of the language file to read.
  • string $out_file: Name of the cache file.
  • bool $strip: Do we want to call stripslashes? It may cause problems with Japanese translations.
reset_language (line 135)

Unloads $translations so we can translate a different language.

void reset_language (string $new_language)
  • string $new_language: New language file to load (just the base filename, no directory or file suffix. Example: "French")
tooltip (line 356)

Translates and removes HTML from text, and returns it.

This is useful for tooltips, which barf on HTML.

Note: () prints the result rather than return the value.

  • return: The translated text with all HTML removed
  • usedby: etooltip()
string tooltip (string $str, [ $decode = ''])
  • string $str: Text to translate
  • $decode
translate (line 316)

Translates a string from the default English usage to another language.

The first time that this is called, the translation file will be loaded (with ()).

  • return: The translated text, if available. If no translation is avalailable, then the original untranslated text is returned.
  • usedby: define_languages()
  • usedby: etranslate()
string translate (string $str, [string $decode = ''])
  • string $str: Text to translate
  • string $decode: Do we want to envoke html_entity_decode? We currently only use this with javascript alerts.
translation_exists (line 296)
void translation_exists ( $str)
  • $str
unhtmlentities (line 36)

Performs html_entity_decode style conversion for php < 4.3 Borrowed from

void unhtmlentities (string $string)
  • string $string: Text to convert

Documentation generated on Thu, 10 Jun 2010 17:08:37 -0400 by phpDocumentor 1.4.3