forked from Indicia-Team/client_helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlang.php
More file actions
79 lines (74 loc) · 2.75 KB
/
Copy pathlang.php
File metadata and controls
79 lines (74 loc) · 2.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
<?php
/**
* Indicia, the OPAL Online Recording Toolkit.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/gpl.html.
*
* @package Client
* @author Indicia Team
* @license http://www.gnu.org/licenses/gpl.html GPL 3.0
* @link http://code.google.com/p/indicia/
*/
/**
* Link in other required php files.
*/
require_once('lang/default.php');
/**
* Class providing static functions to obtain localised or customised terms for use
* in output generated by the data_entry_helper class.
* By default, retrieves terms from the lang/default.php file, unless a custom terms
* file has been linked to the PHP page which overrides the requested term.
*
* @package Client
*/
class lang {
/**
* Static function to obtain a customised or localised term.
*
* @param string $key Key identifying the term to get.
* @param string Any other parameters are treated as replacements for tags marked {1}, {2} etc in the language string.
* These replacements should be already utf8 encoded.
*/
public static function get($key) {
if (isset($_GET['notranslate']))
return "[$key]";
global $default_terms;
global $custom_terms;
$output = FALSE;
if (isset($custom_terms)) {
if (array_key_exists($key, $custom_terms)) {
$output = $custom_terms[$key];
}
}
if ($output === FALSE && array_key_exists($key, $default_terms)) {
// use default term if no custom terms, or absent from custom term list
$output = $default_terms[$key];
} elseif ($output === FALSE) {
// no translation, so use original requested key
$output = $key;
}
// Now do any replacements using any additional function arguments
$args = func_get_args();
if (count($args) > 1) {
// get rid of the first argument, it is the language string key
array_shift($args);
// build a set of replacements
$argkeys = array();
foreach($args as $arg) {
$argkeys[] = '/\{'.(count($argkeys)+1).'\}/';
}
// replace the replacements with the function argument list
$output = preg_replace($argkeys, $args, $output);
}
return $output;
}
}