-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathi18n.php
executable file
·191 lines (177 loc) · 5.41 KB
/
i18n.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
<?php
/**
* Utility to extract the strings to be translated
*
* @author Alessandro Vernassa <[email protected]>
* @copyright Copyright (c) 1011
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License
*
* USAGE:
*
* utility.php?lang=en (get fn_i18n in system files)
* utility.php?lang=en&mod=login (get fn_i18n in login section)
*
*/
global $_FN;
include 'include/flatnux.php';
header("Content-Type: text/html; charset={$_FN['charset_page']}");
$lang=FN_GetParam("lang",$_GET);
if ($lang=="")
$lang="en";
$s=FN_GetParam("mod",$_GET);
$m=FN_GetParam("m",$_GET);
if ($m!=""&&file_exists("modules/$s/"))
{
$s=$m;
$dirs=FN_ListDir("modules/$s/",true,true);
$_cms_strings=Local_LoadMessages("languages/it/lang.csv");
//dprint_r($_cms_strings);
$strings=Local_LoadMessages("modules/$s/languages/$lang/lang.csv",$_cms_strings);
$dirs[]="modules/$s/";
foreach($dirs as $dir)
{
if (FN_erg("^modules/",$dir))
{
$files=glob("$dir/*.php");
foreach($files as $file)
{
$contents=file_get_contents($file);
$out=false;
preg_match_all('/FN_i18n\(\"(.*?)\"/is',$contents,$out);
if (isset($out[1][0]))
{
foreach($out[1] as $string_not_set)
{
if (!isset($strings[$string_not_set])&&!isset($_cms_strings[$string_not_set]))
{
$strings[$string_not_set]="";
}
}
}
preg_match_all('/FN_Translate\(\"(.*?)\"/is',$contents,$out);
if (isset($out[1][0]))
{
foreach($out[1] as $string_not_set)
{
if (!isset($strings[$string_not_set])&&!isset($_cms_strings[$string_not_set]))
{
$strings[$string_not_set]="";
}
}
}
}
}
}
}
elseif ($s!=""&&file_exists("sections/$s/"))
{
$dirs=FN_ListDir("sections/$s/",true,true);
$_cms_strings=Local_LoadMessages("languages/it/lang.csv");
//dprint_r($_cms_strings);
$strings=Local_LoadMessages("sections/$s/languages/$lang/lang.csv",$_cms_strings);
//dprint_r("file: sections/$s/languages/$lang/lang.csv");
$dirs[]="sections/$s/";
foreach($dirs as $dir)
{
if (FN_erg("^sections/",$dir))
{
$files=glob("$dir/*.php");
foreach($files as $file)
{
$contents=file_get_contents($file);
$out=false;
preg_match_all('/FN_i18n\(\"(.*?)\"/is',$contents,$out);
if (isset($out[1][0]))
{
foreach($out[1] as $string_not_set)
{
if (!isset($strings[$string_not_set])&&!isset($_cms_strings[$string_not_set]))
{
$strings[$string_not_set]="";
}
}
}
preg_match_all('/FN_Translate\(\"(.*?)\"/is',$contents,$out);
//dprint_r("file:$file");
if (isset($out[1][0]))
{
//dprint_r($out[1]);
foreach($out[1] as $string_not_set)
{
if (!isset($strings[$string_not_set])&&!isset($_cms_strings[$string_not_set]))
{
$strings[$string_not_set]="";
}
}
}
}
}
}
}
else
{
$dirs=FN_ListDir(".",true,true);
$strings=Local_LoadMessages("languages/$lang/lang.csv");
foreach($dirs as $dir)
{
if (!FN_erg("^modules/",$dir)&&!FN_erg("^sections/",$dir)&&!FN_erg("^blocks/",$dir)&&!FN_erg("^misc/",$dir))
{
$files=glob("$dir/*.php");
foreach($files as $file)
{
$contents=file_get_contents($file);
$out=false;
preg_match_all('/FN_i18n\(\"(.*?)\"/is',$contents,$out);
if (isset($out[1][0]))
{
foreach($out[1] as $string_not_set)
{
if (!isset($strings[$string_not_set]))
{
$strings[$string_not_set]="";
}
}
}
}
}
}
}
$csv='"id","text"';
foreach($strings as $key=> $value)
{
$key=str_replace('"','""',$key);
$value=str_replace('"','""',$value);
$csv.="\n\"{$key}\",\"{$value}\"";
}
dprint_r($csv);
/**
*
* @param string $filename
* @return string
*/
function Local_LoadMessages($filename,$exclude=array())
{
$sd=FN_GetParam("d",$_GET);
$var="";
if ($sd)
{
$var[$filename]="<h1>$filename</h1>";
}
if (!file_exists($filename))
return $var;
$first=true;
$handle=fopen("$filename","r");
while(($data=fgetcsv($handle,5000,","))!==false)
{
if ($first==true)
{
$first=false;
continue;
}
if (isset($data[1])&&!isset($exclude[$data[0]]))
$var[$data[0]]=$data[1];
}
fclose($handle);
return $var;
}
?>