wiclear-2007-07-19/inc/classes/lang.class.php
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of WiClear.
# Copyright (c) 2004-2007 David Jobet. All rights
# reserved.
#
# WiClear is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# WiClear is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DotClear; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
# ***** END LICENSE BLOCK *****
/**
* \brief represents a translation lang allowed in this wiki
*
* an allowed translation lang must not be confused with a UI translation lang.
* a site may allow 2 langs (say fr and en) but provides UI translation files in more languages.
*/
class lang
{
var $id; //!< database id
var $code; //!< lang code
var $description; //!< free text description
var $flag; //!< flag file name (fr_lang.png for example)
function lang($id, $code, $description, $flag)
{
$this->id = $id;
$this->code = $code;
$this->description = $description;
$this->flag = $flag;
}
/**
* \brief returns a lang database id from a list of lang object and a lang code
*
* this method is static
*
* \param langList array<lang>
* \param code lang code
* \return database id
*/
function getIdFromCode($langList, $code)
{
foreach ($langList as $lang)
{
if ($lang->code == $code)
{
return $lang->id;
}
}
return 0;
}
/**
* \brief returns a list of available langs from i18n directory
*
* this method is static
*
* \param $langBaseDir path to i18n lang files
* \return array<lang code>
*/
function getUILangs($langBaseDir)
{
$langs = array();
$langs[] = 'en';
$h = opendir($langBaseDir);
while (($file = readdir($h)) !== false)
{
if (is_file($langBaseDir.$file))
{
$lang = basename($file, '.lang');
if ($lang != $file)
{
$langs[] = $lang;
}
}
}
closedir($h);
return $langs;
}
}
?>