Files
development/www/lib/CoreLibs/Language/L10n.inc
Clemens Schwaighofer 593e8fa7b0 Relocate folders
the old "www/layout/<admin/frontend>/<template name>/..." layout is
deprecated.

new layout:

www/layout/<admin|frontend>/<cache/css/images/javascript>/
The layout/<admin/frontend> is symlinked to www/<admin|frontend>/layout

templates and lang are moved to includes
www/includes/template/<admin/frontend>
www/includes/lang/<admin/frontend>

and no longer symlinked to any public facing folders

The language po files have already been moved to
4dev/lang/<admin|frontend>/
2019-05-28 10:56:53 +09:00

136 lines
3.0 KiB
PHP

<?php
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2004/11/18
* VERSION: 1.0.0
* 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)
*********************************************************************/
namespace CoreLibs\Language;
use \CoreLibs\Language\Core\FileReader;
use \CoreLibs\Language\Core\GetTextReader;
class L10n extends \CoreLibs\Basic
{
private $lang = '';
private $mofile = '';
private $input;
private $l10n;
public function __construct($lang = '', $path = DEFAULT_TEMPLATE)
{
if (!$lang) {
$this->lang = 'en';
} else {
$this->lang = $lang;
}
if (USE_DEPRECATED_TEMPLATE_FOLDERS === true) {
if (is_dir(LAYOUT.$path.LANG)) {
$path = LAYOUT.$path.LANG;
} elseif (!is_dir($path)) {
$path = '';
}
} else {
// override path check
if (!is_dir($path)) {
$path = INCLUDES.LANG.CONTENT_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 GetTextReader($this->input);
}
// reloads the mofile, if the location of the lang file changes
public function l10nReloadMOfile($lang, $path = DEFAULT_TEMPLATE)
{
$success = false;
$old_mofile = $this->mofile;
$old_lang = $this->lang;
$this->lang = $lang;
if (USE_DEPRECATED_TEMPLATE_FOLDERS === true) {
if (is_dir(LAYOUT.$path.LANG)) {
$path = LAYOUT.$path.LANG;
} elseif (!is_dir($path)) {
$path = '';
}
} else {
// override path check
if (!is_dir($path)) {
$path = INCLUDES.LANG.CONTENT_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 GetTextReader($this->input);
// we successfully loaded
$success = true;
} else {
// else fall back to the old ones
$this->mofile = $old_mofile;
$this->lang = $old_lang;
}
return $success;
}
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 __getLang()
{
return $this->lang;
}
public function __getMoFile()
{
return $this->mofile;
}
}
// __END__