2024.8.23
Loading...
Searching...
No Matches
LangProc Class Reference

Public Member Functions

 __construct ()
 
 getCurrent ()
 
 getList ()
 
 getValue ($key)
 
 load ()
 

Private Attributes

 $current
 
 $raw
 

Detailed Description

Class LangProc

This class handles the language processing for the Bearsampp application. It loads language files, retrieves language settings, and provides language-specific values.

Definition at line 16 of file class.langproc.php.

Constructor & Destructor Documentation

◆ __construct()

LangProc::__construct ( )

LangProc constructor.

Initializes the LangProc object and loads the language settings.

Definition at line 33 of file class.langproc.php.

34 {
35 $this->load();
36 }

References load().

Member Function Documentation

◆ getCurrent()

LangProc::getCurrent ( )

Gets the current language being used.

Returns
string The current language.

Definition at line 62 of file class.langproc.php.

63 {
64 return $this->current;
65 }

References $current.

◆ getList()

LangProc::getList ( )

Retrieves the list of available languages.

This method scans the language directory and returns a list of available language files.

Returns
array The list of available languages.

Definition at line 74 of file class.langproc.php.

75 {
76 global $bearsamppCore;
77 $result = array();
78
79 $handle = @opendir($bearsamppCore->getLangsPath());
80 if (!$handle) {
81 return $result;
82 }
83
84 while (false !== ($file = readdir($handle))) {
85 if ($file != "." && $file != ".." && Util::endWith($file, '.lang')) {
86 $result[] = str_replace('.lang', '', $file);
87 }
88 }
89
90 closedir($handle);
91 return $result;
92 }
$result
global $bearsamppCore
static endWith($string, $search)

References $bearsamppCore, $result, and Util\endWith().

Referenced by load().

+ Here is the caller graph for this function:

◆ getValue()

LangProc::getValue ( $key)

Retrieves the value for a given language key.

This method returns the value associated with the specified key in the current language. If the key is not found, it logs an error and returns the key itself.

Parameters
string$keyThe language key to retrieve the value for.
Returns
string The value associated with the key, or the key itself if not found.

Definition at line 103 of file class.langproc.php.

104 {
105 global $bearsamppRoot;
106
107 if (!isset($this->raw[$key])) {
108 $content = '[' . date('Y-m-d H:i:s', time()) . '] ';
109 $content .= 'ERROR: Lang var missing ' . $key;
110 $content .= ' for ' . $this->current . ' language.' . PHP_EOL;
111 file_put_contents($bearsamppRoot->getErrorLogFilePath(), $content, FILE_APPEND);
112 return $key;
113 }
114
115 // Special chars not handled by Aestan Tray Menu
116 $replace = array("ő", "Ő", "ű", "Ű");
117 $with = array("o", "O", "u", "U");
118
119 return str_replace($replace, $with, $this->raw[$key]);
120 }
global $bearsamppRoot

References $bearsamppRoot.

◆ load()

LangProc::load ( )

Loads the current language settings and data.

This method retrieves the default language from the configuration, checks if it is available, and then loads the corresponding language file.

Definition at line 44 of file class.langproc.php.

45 {
47 $this->raw = null;
48
49 $this->current = $bearsamppConfig->getDefaultLang();
50 if (!empty($this->current) && in_array($this->current, $this->getList())) {
51 $this->current = $bearsamppConfig->getLang();
52 }
53
54 $this->raw = parse_ini_file($bearsamppCore->getLangsPath() . '/' . $this->current . '.lang');
55 }
global $bearsamppConfig
Definition homepage.php:26

References $bearsamppConfig, $bearsamppCore, and getList().

Referenced by __construct().

+ Here is the caller graph for this function:

Field Documentation

◆ $current

LangProc::$current
private

Definition at line 21 of file class.langproc.php.

Referenced by getCurrent().

◆ $raw

LangProc::$raw
private

Definition at line 26 of file class.langproc.php.


The documentation for this class was generated from the following file: