aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace/Language.php
blob: fdaf104e8a5c61fe1ab1db078d1c764cd6c6fcc7 (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
45
46
47
48
49
50
51
52
<?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], $arguments);
	}

	#===============================================================================
	# DEPRECATED: This method will be removed in the future!
	#===============================================================================
	public function template($name, $params = FALSE): string {
		return $this->text($name, $params);
	}
}
?>