Bearsampp 2026.7.11
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->getLang();
50 $langPath = Path::getLangsPath() . '/' . $this->current . '.lang';
51
52 if (file_exists($langPath)) {
53 $this->raw = parse_ini_file($langPath);
54 } else {
55 $this->current = $bearsamppConfig->getDefaultLang();
56 $this->raw = parse_ini_file(Path::getLangsPath() . '/' . $this->current . '.lang');
57 }
58 }
59
65 public function getCurrent()
66 {
67 return $this->current;
68 }
69
77 public function getList()
78 {
79 global $bearsamppCore;
80 $result = array();
81
82 $handle = @opendir(Path::getLangsPath());
83 if (!$handle) {
84 return $result;
85 }
86
87 while (false !== ($file = readdir($handle))) {
88 if ($file != "." && $file != ".." && UtilString::endWith($file, '.lang')) {
89 $result[] = str_replace('.lang', '', $file);
90 }
91 }
92
93 closedir($handle);
94 return $result;
95 }
96
106 public function getValue($key)
107 {
108 global $bearsamppRoot;
109
110 if (!isset($this->raw[$key])) {
111 $content = '[' . date('Y-m-d H:i:s', time()) . '] ';
112 $content .= 'ERROR: Lang var missing ' . $key;
113 $content .= ' for ' . $this->current . ' language.' . PHP_EOL;
114 file_put_contents(Path::getErrorLogFilePath(), $content, FILE_APPEND);
115 return $key;
116 }
117
118 // Special chars not handled by Aestan Tray Menu
119 $replace = array("ő", "Ő", "ű", "Ű");
120 $with = array("o", "O", "u", "U");
121
122 return str_replace($replace, $with, $this->raw[$key]);
123 }
124}
$result
global $bearsamppRoot
global $bearsamppCore
static getLangsPath($aetrayPath=false)
static getErrorLogFilePath($aetrayPath=false)
static endWith($string, $search)
global $bearsamppConfig
Definition homepage.php:41