Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.langproc.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
17{
21 private $current;
22
26 private $raw;
27
33 public function __construct()
34 {
35 $this->load();
36 }
37
44 public function load()
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 }
56
62 public function getCurrent()
63 {
64 return $this->current;
65 }
66
74 public function getList()
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 }
93
103 public function getValue($key)
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 }
121}
$result
global $bearsamppRoot
global $bearsamppCore
static endWith($string, $search)
global $bearsamppConfig
Definition homepage.php:27