Zeile 8 | Zeile 8 |
---|
* */
|
* */
|
| #[AllowDynamicProperties]
|
class MyLanguage {
| class MyLanguage {
|
Zeile 19 | Zeile 20 |
---|
public $path;
/**
|
public $path;
/**
|
* The language we are using.
| * The language we are using and the area (if admin). * * For example 'english' or 'english/admin'.
|
* * @var string */ public $language;
/**
|
* * @var string */ public $language;
/**
|
* The fallback language we are using.
| * The fallback language we are using and the area (if admin). * * For example 'english' or 'english/admin'. * * @var string */ public $fallback = 'english';
/** * The fallback language we are using.
|
* * @var string
|
* * @var string
|
*/ public $fallback = 'english';
| */ public $fallbackLanguage = 'english';
|
/** * Information about the current language. *
| /** * Information about the current language. *
|
Zeile 41 | Zeile 53 |
---|
/** * Set the path for the language folder.
|
/** * Set the path for the language folder.
|
* * @param string The path to the language folder.
| * * @param string $path The path to the language folder.
|
*/ function set_path($path) {
| */ function set_path($path) {
|
Zeile 52 | Zeile 64 |
---|
/** * Check if a specific language exists. *
|
/** * Check if a specific language exists. *
|
* @param string The language to check for.
| * @param string $language The language to check for.
|
* @return boolean True when exists, false when does not exist. */ function language_exists($language) { $language = preg_replace("#[^a-z0-9\-_]#i", "", $language); if(file_exists($this->path."/".$language.".php"))
|
* @return boolean True when exists, false when does not exist. */ function language_exists($language) { $language = preg_replace("#[^a-z0-9\-_]#i", "", $language); if(file_exists($this->path."/".$language.".php"))
|
{
| {
|
return true; } else
| return true; } else
|
Zeile 71 | Zeile 83 |
---|
/** * Set the language for an area. *
|
/** * Set the language for an area. *
|
* @param string The language to use. * @param string The area to set the language for.
| * @param string $language The language to use. * @param string $area The area to set the language for.
|
*/
|
*/
|
function set_language($language="english", $area="user")
| function set_language($language="", $area="user")
|
{ global $mybb;
$language = preg_replace("#[^a-z0-9\-_]#i", "", $language);
|
{ global $mybb;
$language = preg_replace("#[^a-z0-9\-_]#i", "", $language);
|
// Default language is English.
| // Use the board's default language
|
if($language == "") {
|
if($language == "") {
|
$language = "english";
| $language = $mybb->settings['bblanguage'];
|
}
// Check if the language exists.
| }
// Check if the language exists.
|
Zeile 95 | Zeile 107 |
---|
$this->language = $language; require $this->path."/".$language.".php"; $this->settings = $langinfo;
|
$this->language = $language; require $this->path."/".$language.".php"; $this->settings = $langinfo;
|
|
|
// Load the admin language files as well, if needed. if($area == "admin") {
| // Load the admin language files as well, if needed. if($area == "admin") {
|
Zeile 111 | Zeile 123 |
---|
{ $language = "english"; }
|
{ $language = "english"; }
|
}
| }
|
else { $language = $mybb->settings['cplanguage']; } } $this->language = $language."/{$area}";
|
else { $language = $mybb->settings['cplanguage']; } } $this->language = $language."/{$area}";
|
$this->fallback = $this->fallback."/{$area}"; }
| $this->fallback = $this->fallbackLanguage."/{$area}"; }
|
}
/** * Load the language variables for a section. *
|
}
/** * Load the language variables for a section. *
|
* @param string The section name. * @param boolean Is this a datahandler? * @param boolean supress the error if the file doesn't exist?
| * @param string $section The section name. * @param boolean $forceuserarea Should use the user area even if in admin? For example for datahandlers * @param boolean $supress_error supress the error if the file doesn't exist?
|
*/
|
*/
|
function load($section, $isdatahandler=false, $supress_error=false)
| function load($section, $forceuserarea=false, $supress_error=false)
|
{
|
{
|
// Assign language variables. // Datahandlers are never in admin lang directory. if($isdatahandler === true) { $lfile = $this->path."/".str_replace('/admin', '', $this->language)."/".$section.".lang.php"; } else
| $language = $this->language; $fallback = $this->fallback;
if($forceuserarea === true)
|
{
|
{
|
$lfile = $this->path."/".$this->language."/".$section.".lang.php"; }
| $language = str_replace('/admin', '', $language); $fallback = str_replace('/admin', '', $fallback); }
$lfile = $this->path."/".$language."/".$section.".lang.php"; $ffile = $this->path."/".$fallback."/".$section.".lang.php";
|
if(file_exists($lfile)) {
|
if(file_exists($lfile)) {
|
require_once $lfile; } elseif(file_exists($this->path."/".$this->fallback."/".$section.".lang.php")) { require_once $this->path."/".$this->fallback."/".$section.".lang.php";
| require $lfile; } elseif(file_exists($ffile)) { require $ffile;
|
} else { if($supress_error != true) { die("$lfile does not exist");
|
} else { if($supress_error != true) { die("$lfile does not exist");
|
} }
| } }
|
// We must unite and protect our language variables!
|
// We must unite and protect our language variables!
|
$lang_keys_ignore = array('language', 'path', 'settings');
| $lang_keys_ignore = array('language', 'fallback', 'fallbackLanguage', 'path', 'settings');
|
if(isset($l) && is_array($l)) {
| if(isset($l) && is_array($l)) {
|
Zeile 173 | Zeile 186 |
---|
} }
|
} }
|
| /** * @param string $string * * @return string */
|
function sprintf($string) { $arg_list = func_get_args();
| function sprintf($string) { $arg_list = func_get_args();
|
Zeile 189 | Zeile 207 |
---|
/** * Get the language variables for a section. *
|
/** * Get the language variables for a section. *
|
* @param boolean Admin variables when true, user when false.
| * @param boolean $admin Admin variables when true, user when false.
|
* @return array The language variables. */
|
* @return array The language variables. */
|
function get_languages($admin=0)
| function get_languages($admin=false)
|
{ $dir = @opendir($this->path); while($lang = readdir($dir))
| { $dir = @opendir($this->path); while($lang = readdir($dir))
|
Zeile 215 | Zeile 233 |
---|
/** * Parse contents for language variables. *
|
/** * Parse contents for language variables. *
|
* @param string The contents to parse.
| * @param string $contents The contents to parse.
|
* @return string The parsed contents. */ function parse($contents)
| * @return string The parsed contents. */ function parse($contents)
|
Zeile 227 | Zeile 245 |
---|
/** * Replace content with language variable. *
|
/** * Replace content with language variable. *
|
* @param array Matches.
| * @param array $matches Matches.
|
* @return string Language variable. */ function parse_replace($matches) {
|
* @return string Language variable. */ function parse_replace($matches) {
|
return $this->$matches[1];
| return $this->{$matches[1]};
|
} }
| } }
|