Source for file Common.php
Documentation is available at Common.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Wolfram Kriesing <wolfram@kriesing.de> |
// | Naoki Shima <naoki@avantexchange.com> |
// +----------------------------------------------------------------------+
// $Id: Common.php 110339 2003-01-04 11:55:29Z mj $
* this class provides language functionality, such as
* determining the language of a given string, etc.
* iso639-1 compliant, 2 letter code is used
* iso639-1 http://www.loc.gov/standards/iso639-2/langcodes.html
* @author Wolfram Kriesing <wolfram@kriesing.de>
* Holds messageID to corresponding message mapping
# FIXXME pass a resource to the constructor which can be used to determine the
# language of a string, it should be possible to use XML, DB, or whatever
# this can then be used as a replacement for the array as used now
// {{ I18N_Messages_Common()
* for pre-ZE2 compatibility
// {{ determineLanuguage()
* trys to get the language of a given string
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @param string $string the string which is used to try and determine its language
* @return string iso-string for the language
// include a file here, so one can provide its own file,
// and to reduce compile time for php, since it will only be included when needed
// the file that gets included might become very big
include('I18N/Messages/determineLanguage.inc.php');
include($source); // include the file given as parameter, it only needs to provide an array, as in the above included file
// replace all non word-characters by a space, i hope that is ok for all languages
$splitString = explode(' ',$string); // get each single word in a field
foreach( $splitString as $key=> $aString ) // remove spaces around the word and make it lower case
// simply intersect each language array with the array that we created by splitting the string
// and the result that's size is the biggest is our language
foreach( $languages as $lang=> $aLanguage )
list ($lang,) = each($results);
* Look for and return the message corresponds to the messageID passed.
* Returns messageID when the corresponding message is not found
* @author: Naoki Shima <naoki@avantexchange.com>
function get($messageID = "")
return ($messageID !== "" && is_array($this->_message) && in_array($messageID, array_keys($this->_message))) ? $this->_message[$messageID] : $messageID;
* Alias for get(). Function name might not be appropriate because it conflicts PEAR coding standard
* that this is meant to be public function
* @param : string messageID
* @return: string corresponding message
* @author: Naoki Shima <naoki@avantexchange.com>
function _ ($messageID = "")
return $this->get($messageID);
* Set message ID to corresponding string
* @author: Naoki Shima <naoki@avantexchange.com>
function set($messageID = "",$str = "")
if($str === "" && is_array($messageID)) {
// user is passing an array
$this->_message = $messageID;
$this->_message[$messageID] = $str;
* @param : string Charset
* @author: Naoki Shima <naoki@avantexchange.com>
function setCharset($charset = I18N_MESSAGES_DEFAULT_CHARSET )
$this->_charset = $charset;
* Returns charset of message. Returns null if it's not set.
* @author: Naoki Shima <naoki@avantexchange.com>
return ($this->_charset ? $this->_charset: false );
* If domain is not passed and there's already a value set to domain,
* then this method returns current domain.
* @return: string Current domain
return ($this->_domain ? $this->_domain : '');
$this->_domain = $domain;
* If language is not passed and there's already a value set to domain,
* then this method returns current domain.
* @return: string Current language
* @author: Naoki Shima <naoki@avantexchange.com>
return ($this->_lang ? $this->_lang : '');
Documentation generated on Mon, 11 Mar 2019 15:36:10 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|