forked from opensourcepos/opensourcepos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguagecheck.php
192 lines (155 loc) · 4.7 KB
/
Languagecheck.php
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
// ---------------------------------------------------------------------
class Languagecheck extends CI_Controller {
/*
* use this language as comparison reference.
* this should be the one that is complete.
*/
private $reference = 'english';
private $lang_path = 'language';
// -----------------------------------------------------------------
/*
* controller constructor
*/
function Languagecheck()
{
parent::Controller();
}
// -----------------------------------------------------------------
/*
* use remap to capture all calls to this controller
*/
function _remap()
{
// load the required helpers
$this->load->helper('directory');
// for simplicity, we don't use views
$this->output('h1', 'Open Source Point of Sale - Language file checking and validation');
// determine the language file path
if ( ! is_dir($this->lang_path) )
{
$this->lang_path = APPPATH . $this->lang_path;
if ( ! is_dir($this->lang_path) )
{
$this->output('h2', 'Defined language path "'.$this->lang_path.'" not found!', TRUE);
exit;
}
}
// fetch the languages directory map
$languages = directory_map( $this->lang_path, TRUE );
// is our reference language present?
if ( ! in_array($this->reference, $languages ) )
{
$this->output('h2', 'Reference language "'.$this->reference.'" not found!', TRUE);
exit;
}
// load the list of language files for the reference language
$references = directory_map( $this->lang_path . '/' . $this->reference, TRUE );
// now process the list
foreach( $references as $reference )
{
// skip non-language files in the language directory
if ( strpos($reference, '_lang.php') === FALSE )
{
continue;
}
// process it
$this->output('h2', 'Processing '.$this->reference . ' » ' .$reference);
// load the language file
include $this->lang_path . '/' . $this->reference . '/' . $reference;
// did the file contain any language strings?
if ( empty($lang) )
{
// language file was empty or not properly defined
$this->output('h3', 'Language file doesn\'t contain any language strings. Skipping file!', TRUE);
continue;
}
// store the loaded language strings
$lang_ref = $lang;
unset($lang);
// now loop through the available languages
foreach ( $languages as $language )
{
// skip the reference language
if ( $language == $this->reference )
{
continue;
}
// language file to check
$file = $this->lang_path . '/' . $language . '/' . $reference;
// check if the language file exists for this language
if ( ! file_exists( $file ) )
{
// file not found
$this->output('h3', 'Language file doesn\'t exist for the language '.$language.'!', TRUE);
}
else
{
// load the file to compare
include $file;
// did the file contain any language strings?
if ( empty($lang) )
{
// language file was empty or not properly defined
$this->output('h3', 'Language file for the language '.$language.' doesn\'t contain any language strings!', TRUE);
}
else
{
// start comparing
$this->output('h3', 'Comparing with the '.$language.' version:');
// assume all goes well
$failures = 0;
// start comparing language keys
foreach( $lang_ref as $key => $value )
{
if ( ! isset($lang[$key]) )
{
// report the missing key
$this->output('', 'Missing language string "'.$key.'"', TRUE);
// increment the failure counter
$failures++;
}
}
if ( ! $failures )
{
$this->output('', 'The two language files have matching strings.');
}
}
// make sure the lang array is deleted before the next check
if ( isset($lang) )
{
unset($lang);
}
}
}
}
$this->output('h2', 'Language file checking and validation completed');
}
// -----------------------------------------------------------------
private function output($type = '', $line = '', $highlight = FALSE)
{
switch ($type)
{
case 'h1':
$html = "<h1>{line}</h1>\n<hr />\n";
break;
case 'h2':
$html = "<h2>{line}</h2>\n";
break;
case 'h3':
$html = "<h3> {line}</h3>\n";
break;
default:
$html = " » {line}<br />";
break;
}
if ( $highlight )
{
$line = '<span style="color:red;font-weight:bold;">' . $line . '</span>';
}
echo str_replace('{line}', $line, $html);
}
// -----------------------------------------------------------------
}
/* End of file languagecheck.php */
/* Location: ./application/controllers/languagecheck.php */