blob: 804f3d50b20fcec536e2b06bd48440308ca64988 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
<?php
class Language {
private $code = '';
private $text = [];
public function __construct($code) {
$this->code = $code;
}
#===============================================================================
# Return the language code
#===============================================================================
public function getCode() {
return $this->code;
}
#===============================================================================
# Load another language file
#===============================================================================
public function load($filename) {
if(file_exists($filename) and is_readable($filename)) {
require $filename;
$this->text = array_merge($this->text, $LANGUAGE ?? []);
}
}
#===============================================================================
# Set language string
#===============================================================================
public function set($name, $value) {
return $this->text[$name] = $value;
}
#===============================================================================
# Return language string with included arguments
#===============================================================================
public function text($name, $arguments = null): string {
if(!isset($this->text[$name])) {
return "{{$name}}";
}
return vsprintf($this->text[$name], (array) $arguments);
}
}
|