Packages » Package i18n » Class I18NMessageDictionary

Class I18NMessageDictionary

Declaration:
<? interface I18NMessageDictionary ?>

Description:
This is the interface to message dictionaries. A message dictionary is an abstraction of a message translation facility. This interface declares just a single method, I18NMessageDictionary::translateMessage that will fetch localized message by its ID and target language/dialect code. Note that the dialect code is required; if the message for this dialect is not found, this will look up the Official dialect for the message translation. This package ships with the I18NMessageFile class that is an implementation of this interface and allows you to keep the translation infomation in ini-like files. Example
Given the following message file:
 [en_Official]
 hello='Hello!'
 bye='Bye!'
 something='Oops!'
  [en_American]
 hello='Hi!'
 bye='So long!' 
 
and the code:
<?

 $mf 
= new I18NMessageFile('/path/to/file');
 
$s $mf->translateMessage('hello''en''Official');
 
// $s will contain 'Hello!'
 
$s $mf->translateMessage('hello''en''American');
 
// $s will contain 'Hi!'
 
$s $mf->translateMessage('something''en''American');
 
// $s will contain 'Oops!' as it will search the Official dialect
 
$s $mf->translateMessage('someotherthing''en''American'true);
 
// will throw an exception
 
?>


Authors:
  • Dennis Popel

Methods:
  • translateMessage()
    Return translated message with the given ID, into the given language dialect. If the specified dialect or translation could not be found, this will try to translate into the Official dialect of the language.