Class LanguageLocalizer

Description

The LanguageLocalizer is a class that handles the organization or strings and other data for multiple languages.

  • version: $Id: LanguageLocalizer.class.php,v 1.22 2007/09/04 20:25:35 adamfranco Exp $
  • license: GNU General Public License (GPL)
  • copyright: Copyright © 2005, Middlebury College

Located in /harmoni/core/languageLocalizer/LanguageLocalizer.class.php (line 14)


	
			
Variable Summary
string $_application
string $_lang
string $_langDir
array $_strings
Method Summary
void LanguageLocalizer (optional 0, optional 1, optional 2)
void addApplication (string $application, string $langDir)
void assignConfiguration (object Properties $configuration)
void assignOsidContext (mixed $context, object OsidContext $context )
string getLanguage ()
array getLanguages ([boolean $includeCountries = TRUE])
object OsidContext getOsidContext ()
void setCodeset (string $codeset)
void setLanguage (string $language)
Variables
string $_application (line 37)
  • var: The "app" we are bound to.
  • access: private
string $_lang (line 19)
  • var: The current language.
  • access: private
string $_langDir (line 25)
  • var: The directory in which all the languages reside.
  • access: private
array $_strings (line 31)
  • var: A hash table of strings for this language.
  • access: private
Methods
Constructor LanguageLocalizer (line 48)

The constructor.

  • todo: -cLanguageLocalizer Implement LanguageLocalizer.constructor - use gettext functionality.
  • access: public
void LanguageLocalizer (optional 0, optional 1, optional 2)
  • optional 0: string $langDir The directory in which language files reside.
  • optional 1: string $application The name of the application to use (for *.mo files)
  • optional 2: string $defaultLanguage The default language to use.
addApplication (line 170)

Add a new application to the LanguageLocalizer.

The first application added will be the default textdomain. To use language files in other textdomains use the PHP textdomain() function as follows:

< ? $defaultTextDomain = textdomain(); textdomain("myAppName");

... print _("My nice string"); print _("Some other stuff."); ...

textdomain($defaultTextDomain); ? >

To create the localized binary hashes, the following steps need to be followed:

  1. use xgettext to create the .po translation files: find /www/afranco/polyphony/ -iname "*.php" -exec xgettext -C -j -o /www/afranco/polyphony/main/languages/en_US/LC_MESSAGES/polyphony.po --keyword=_ {} \;
2. translate the .po files 3. use msgfmt to create the binary hashes msgfmt -vf /www/afranco/polyphony/main/languages/es_ES/LC_MESSAGES/polyphony.po -o /www/afranco/polyphony/main/languages/es_ES/LC_MESSAGES/polyphony.mo

void addApplication (string $application, string $langDir)
  • string $application: The application name to add.
  • string $langDir: The directory where language files for the application are stored.
assignConfiguration (line 84)

Assign the configuration of this Manager. Valid configuration options are as

follows: default_language string (ex: 'en_US') applications array of strings ( application_name => language_file_directory, ..., ..., )

  • access: public
  • throws: object OsidException An exception with one of the following messages defined in org.osid.OsidException: OPERATION_FAILED, PERMISSION_DENIED, CONFIGURATION_ERROR, UNIMPLEMENTED, NULL_ARGUMENT
void assignConfiguration (object Properties $configuration)
  • object Properties $configuration: (original type: java.util.Properties)
assignOsidContext (line 133)

Assign the context of this OsidManager.

  • access: public
  • throws: object OsidException An exception with one of the following messages defined in org.osid.OsidException: NULL_ARGUMENT
void assignOsidContext (mixed $context, object OsidContext $context )
  • object OsidContext $context
getLanguage (line 229)

Return the code of the current language.

string getLanguage ()
getLanguages (line 259)

Return an array of availible languages. The keys are the language codes

and the values are a UTF-8 encoded string representation of the language name (eg. "en_US" => "English - US", "es_ES" => "Espa–ol - Espa–a", "es_MX" => "Espa–ol - Mˇxico")

array getLanguages ([boolean $includeCountries = TRUE])
  • boolean $includeCountries: Include the countries of the language codes. Default is TRUE.
getOsidContext (line 118)

Return context of this OsidManager.

  • access: public
  • throws: object OsidException
object OsidContext getOsidContext ()
setCodeset (line 239)

Sets the codeset to use for charactor encoding. UTF-8 is used by default.

void setCodeset (string $codeset)
  • string $codeset: The codeset to use (eg, "UTF-8", "ISO-8859-8", "SHIFT_JIS", etc).
setLanguage (line 196)

Sets the language to use for getting data to $language.

  • todo: -cLanguageLocalizer Implement LanguageLocalizer.setLanguage - use gettext functionality.
  • access: public
void setLanguage (string $language)
  • string $language: The language code (eg, "en_US") to use.

Documentation generated on Wed, 19 Sep 2007 10:24:47 -0400 by phpDocumentor 1.3.0RC3