Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

GetText Class Reference

List of all members.

Public Member Functions

 setLanguage ($langCode)
 addDomain ($domain, $path=false)
 gettext ($key)
 setVar ($key, $value)
 setVars ($hash)
 reset ()

Static Public Member Functions

_support ($set=false)
 init ($managerType=GETTEXT_NATIVE)

Detailed Description

Generic gettext static class.

This class allows gettext usage with php even if the gettext support is not compiled in php.

The developper can choose between the GETTEXT_NATIVE support and the GETTEXT_PHP support on initialisation. If native is not supported, the system will fall back to PHP support.

On both systems, this package add a variable interpolation system so you can translate entire dynamic sentences in stead of peace of sentences.

Small example without pear error lookup :

<?php require_once "GetText.php";

GetText::init(); GetText::setLanguage('fr_Fr'); // may throw GetText_Error GetText::addDomain('myAppDomain'); // may throw GetText_Error GetText::setVar('login', $login); GetText::setVar('name', $name);

// may throw GetText_Error echo GetText::gettext('Welcome ${name}, you\'re connected with login ${login}');

// should echo something like : // // "Bienvenue Jean-Claude, vous êtes connecté en tant qu'utilisateur jcaccount" // // or if fr_FR translation does not exists // // "Welcome Jean-Claude, you're connected with login jcaccount"

?>

A gettext mini-howto should be provided with this package, if you're new to gettext usage, please read it to learn how to build a gettext translation directory (locale).

Todo:
Tools to manage gettext files in php.

Version:
0.5
Author:
Laurent Bedubourg <laurent.bedubourg@free.fr>

Definition at line 79 of file GetText.php.


Member Function Documentation

& GetText::_support set = false  )  [static]
 

This method returns current gettext support class.

Returns:
GetText_Support 1 private

Definition at line 88 of file GetText.php.

References _support().

Referenced by _support(), addDomain(), gettext(), init(), reset(), setLanguage(), setVar(), and setVars().

GetText::addDomain domain,
path = false
 

Add a translation domain.

The domain name is usually the name of the .po file you wish to use. For example, if you created a file 'locale/ll_CC/LC_MESSAGES/myapp.po', you'll use 'myapp' as the domain name.

Parameters:
string $domain The domain name.
string $path optional The path to the locale directory (ie: /path/to/locale/) which contains ll_CC directories.

Definition at line 159 of file GetText.php.

References _support(), addDomain(), and path.

Referenced by addDomain().

GetText::gettext key  ) 
 

Retrieve the translation for specified key.

Parameters:
string $key String to translate using gettext support.

Definition at line 171 of file GetText.php.

References _support(), and gettext().

Referenced by gettext(), and init().

GetText::init managerType = GETTEXT_NATIVE  )  [static]
 

Initialize gettext package.

This method instantiate the gettext support depending on managerType value.

GETTEXT_NATIVE try to use gettext php support and fail back to PHP support if not installed.

GETTEXT_PHP explicitely request the usage of PHP support.

Parameters:
int $managerType Gettext support type.
public 1

Definition at line 119 of file GetText.php.

References _support(), gettext(), GETTEXT_NATIVE, and init().

Referenced by init().

GetText::reset  ) 
 

Reset interpolation variables.

Definition at line 207 of file GetText.php.

References _support().

GetText::setLanguage langCode  ) 
 

Set the language to use for traduction.

Parameters:
string $langCode The language code usually defined as ll_CC, ll is the two letter language code and CC is the two letter country code.
Exceptions:
GetText_Error if language is not supported by your system.

Definition at line 139 of file GetText.php.

References _support(), and setLanguage().

Referenced by setLanguage().

GetText::setVar key,
value
 

Add a variable to gettext interpolation system.

Parameters:
string $key The variable name.
string $value The variable value.

Definition at line 186 of file GetText.php.

References _support(), and setVar().

Referenced by setVar().

GetText::setVars hash  ) 
 

Add an hashtable of variables.

Parameters:
hashtable $hash PHP associative array of variables.

Definition at line 198 of file GetText.php.

References _support(), and setVars().

Referenced by setVars().


The documentation for this class was generated from the following file:
Generated on Tue Jun 29 23:40:23 2004 for Mediawiki by doxygen 1.3.7