PHP CodeStandard update
- all if/while/for/etc blocks have brackets on same line - functions have brackets on new line - no blocks without brackets - all code starts on col 0 and there are no tab intends anymore off: came case for classes and class methods ignore: _ prefix functions (we can't change that anymore)
This commit is contained in:
+100
-99
@@ -1,117 +1,118 @@
|
||||
<?
|
||||
/*********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2004/11/18
|
||||
* VERSION: 0.1.1
|
||||
* RELEASED LICENSE: GNU GPL 3
|
||||
* SHORT DESCRIPTION:
|
||||
* init class for gettext. Original was just a function & var setting include for wordpress.
|
||||
* I changed that to a class to be more portable with my style of coding
|
||||
*
|
||||
* PUBLIC VARIABLES
|
||||
*
|
||||
* PRIVATE VARIABLES
|
||||
*
|
||||
* PUBLIC METHODS
|
||||
* __: returns string (translated or original if not found)
|
||||
* _e: echos out string (translated or original if not found)
|
||||
* __ngettext: should return plural. never tested this.
|
||||
*
|
||||
* PRIVATE METHODS
|
||||
*
|
||||
* HISTORY:
|
||||
* 2005/10/17 (cs) made an on the fly switch method (reload of lang)
|
||||
*********************************************************************/
|
||||
/*********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2004/11/18
|
||||
* VERSION: 0.1.1
|
||||
* RELEASED LICENSE: GNU GPL 3
|
||||
* SHORT DESCRIPTION:
|
||||
* init class for gettext. Original was just a function & var setting include for wordpress.
|
||||
* I changed that to a class to be more portable with my style of coding
|
||||
*
|
||||
* PUBLIC VARIABLES
|
||||
*
|
||||
* PRIVATE VARIABLES
|
||||
*
|
||||
* PUBLIC METHODS
|
||||
* __: returns string (translated or original if not found)
|
||||
* _e: echos out string (translated or original if not found)
|
||||
* __ngettext: should return plural. never tested this.
|
||||
*
|
||||
* PRIVATE METHODS
|
||||
*
|
||||
* HISTORY:
|
||||
* 2005/10/17 (cs) made an on the fly switch method (reload of lang)
|
||||
*********************************************************************/
|
||||
|
||||
// try to include file from LIBS path, or from normal path
|
||||
_spl_autoload('Class.Basic.inc');
|
||||
// try to include file from LIBS path, or from normal path
|
||||
_spl_autoload('Class.Basic.inc');
|
||||
|
||||
class l10n extends basic
|
||||
class l10n extends basic
|
||||
{
|
||||
private $lang = '';
|
||||
private $mofile = '';
|
||||
private $input;
|
||||
private $l10n;
|
||||
|
||||
public function __construct($lang = '', $path = DEFAULT_TEMPLATE)
|
||||
{
|
||||
private $lang = '';
|
||||
private $mofile = '';
|
||||
private $input;
|
||||
private $l10n;
|
||||
|
||||
public function __construct($lang = '', $path = DEFAULT_TEMPLATE)
|
||||
{
|
||||
foreach (array('streams.php', 'gettext.php') as $include_file)
|
||||
_spl_autoload($include_file);
|
||||
|
||||
if (!$lang)
|
||||
$this->lang = 'en';
|
||||
else
|
||||
$this->lang = $lang;
|
||||
|
||||
if (is_dir(LAYOUT.$path.LANG))
|
||||
$path = LAYOUT.$path.LANG;
|
||||
elseif (!is_dir($path))
|
||||
$path = '';
|
||||
|
||||
$this->mofile = $path.$this->lang.".mo";
|
||||
|
||||
// check if get a readable mofile
|
||||
if (is_readable($this->mofile))
|
||||
$this->input = new FileReader($this->mofile);
|
||||
else
|
||||
$this->input = false;
|
||||
|
||||
$this->l10n = new gettext_reader($this->input);
|
||||
foreach (array('streams.php', 'gettext.php') as $include_file) {
|
||||
_spl_autoload($include_file);
|
||||
}
|
||||
|
||||
// reloads the mofile, if the location of the lang file changes
|
||||
public function l10nReloadMOfile($lang, $path = DEFAULT_TEMPLATE)
|
||||
{
|
||||
$old_mofile = $this->mofile;
|
||||
$old_lang = $this->lang;
|
||||
|
||||
if (!$lang) {
|
||||
$this->lang = 'en';
|
||||
} else {
|
||||
$this->lang = $lang;
|
||||
|
||||
if (is_dir(LAYOUT.$path.LANG))
|
||||
$path = LAYOUT.$path.LANG;
|
||||
elseif (!is_dir($path))
|
||||
$path = '';
|
||||
|
||||
$this->mofile = $path.$this->lang.".mo";
|
||||
|
||||
// check if get a readable mofile
|
||||
if (is_readable($this->mofile))
|
||||
{
|
||||
$this->input = new FileReader($this->mofile);
|
||||
$this->l10n = new gettext_reader($this->input);
|
||||
}
|
||||
else
|
||||
{
|
||||
// else fall back to the old ones
|
||||
$this->mofile = $old_mofile;
|
||||
$this->lang = $old_lang;
|
||||
}
|
||||
}
|
||||
|
||||
public function __($text)
|
||||
{
|
||||
return $this->l10n->translate($text);
|
||||
if (is_dir(LAYOUT.$path.LANG)) {
|
||||
$path = LAYOUT.$path.LANG;
|
||||
} elseif (!is_dir($path)) {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
public function _e($text)
|
||||
{
|
||||
echo $this->l10n->translate($text);
|
||||
$this->mofile = $path.$this->lang.".mo";
|
||||
|
||||
// check if get a readable mofile
|
||||
if (is_readable($this->mofile)) {
|
||||
$this->input = new FileReader($this->mofile);
|
||||
} else {
|
||||
$this->input = false;
|
||||
}
|
||||
|
||||
// Return the plural form.
|
||||
public function __ngettext($single, $plural, $number)
|
||||
{
|
||||
return $this->l10n->ngettext($single, $plural, $number);
|
||||
$this->l10n = new gettext_reader($this->input);
|
||||
}
|
||||
|
||||
// reloads the mofile, if the location of the lang file changes
|
||||
public function l10nReloadMOfile($lang, $path = DEFAULT_TEMPLATE)
|
||||
{
|
||||
$old_mofile = $this->mofile;
|
||||
$old_lang = $this->lang;
|
||||
|
||||
$this->lang = $lang;
|
||||
|
||||
if (is_dir(LAYOUT.$path.LANG)) {
|
||||
$path = LAYOUT.$path.LANG;
|
||||
} elseif (!is_dir($path)) {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
public function __get_lang()
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
$this->mofile = $path.$this->lang.".mo";
|
||||
|
||||
public function __get_mofile()
|
||||
{
|
||||
return $this->mofile;
|
||||
// check if get a readable mofile
|
||||
if (is_readable($this->mofile)) {
|
||||
$this->input = new FileReader($this->mofile);
|
||||
$this->l10n = new gettext_reader($this->input);
|
||||
} else {
|
||||
// else fall back to the old ones
|
||||
$this->mofile = $old_mofile;
|
||||
$this->lang = $old_lang;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
public function __($text)
|
||||
{
|
||||
return $this->l10n->translate($text);
|
||||
}
|
||||
|
||||
public function _e($text)
|
||||
{
|
||||
echo $this->l10n->translate($text);
|
||||
}
|
||||
|
||||
// Return the plural form.
|
||||
public function __ngettext($single, $plural, $number)
|
||||
{
|
||||
return $this->l10n->ngettext($single, $plural, $number);
|
||||
}
|
||||
|
||||
public function __get_lang()
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
public function __get_mofile()
|
||||
{
|
||||
return $this->mofile;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user