-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlocale.php
More file actions
92 lines (76 loc) · 1.75 KB
/
locale.php
File metadata and controls
92 lines (76 loc) · 1.75 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Plugin RefNotes: Localization
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Mykola Ostrovskyy <dwpforge@gmail.com>
*/
/**
* Plugins that rely on refnotes_localization should use this trait.
*/
trait refnotes_localization_plugin {
/**
*
*/
public function getRawLang() {
return $this->lang;
}
}
class refnotes_localization {
private static $instance = NULL;
private $plugin;
/**
*
*/
public static function initialize($plugin) {
if (self::$instance == NULL) {
self::$instance = new refnotes_localization($plugin);
}
}
/**
*
*/
public static function getInstance() {
if (self::$instance == NULL) {
throw new Exception('Shared refnotes_localization instance is not properly initialized.');
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct($plugin) {
$this->plugin = $plugin;
}
/**
*
*/
public function getLang($id) {
return $this->plugin->getLang($id);
}
/**
*
*/
public function getFileName($id) {
return $this->plugin->localFN($id);
}
/**
*
*/
public function getByPrefix($prefix, $strip = true) {
$this->plugin->setupLocale();
if ($strip) {
$pattern = '/^' . $prefix . '_(.+)$/';
}
else {
$pattern = '/^(' . $prefix . '_.+)$/';
}
$result = array();
foreach ($this->plugin->getRawLang() as $key => $value) {
if (preg_match($pattern, $key, $match) == 1) {
$result[$match[1]] = $value;
}
}
return $result;
}
}