This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
forked from BeehiveForum/BeehiveForum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bh_convert_language.php
116 lines (78 loc) · 3.37 KB
/
bh_convert_language.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
<?php
/*======================================================================
Copyright Project BeehiveForum 2002
This file is part of BeehiveForum.
BeehiveForum 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 2 of the License, or
(at your option) any later version.
BeehiveForum 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 Beehive; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
======================================================================*/
// Constant to define where the include files are
define("BH_INCLUDE_PATH", "./forum/include/");
include_once(BH_INCLUDE_PATH. "format.inc.php");
// Prevent time out
set_time_limit(0);
// Output the content as text.
header('Content-Type: text/plain');
$exclude_files_array = array();
$exclude_dirs_array = array('forum/chat', 'forum/include/languages', 'forum/include/swift');
function get_language_file($filename)
{
$lang = array();
include("./forum/include/languages/$filename");
return $lang;
}
function get_file_list(&$file_list_array, $path, $extension)
{
$extension_preg = preg_quote($extension, '/');
if (!is_array($file_list_array)) $file_list_array = array();
if (($dir_handle = opendir($path))) {
while (($file_name = readdir($dir_handle)) !== false) {
if ($file_name != "." && $file_name != "..") {
if (@is_dir("$path/$file_name") && !in_array("$path/$file_name", $GLOBALS['exclude_dirs_array'])) {
get_file_list($file_list_array, "$path/$file_name", $extension);
}else if ((preg_match("/$extension_preg$/iu", $file_name) > 0) && !in_array("$path/$file_name", $GLOBALS['exclude_files_array'])) {
$file_list_array[] = "$path/$file_name";
}
}
}
}
return sizeof($file_list_array) > 0;
}
set_time_limit(0);
header('Content-Type: text/plain');
$lang = get_language_file("en.inc.php");
if (get_file_list($file_list_array, 'forum', '.php')) {
echo "Please wait, checking files...\n\n";
foreach ($file_list_array as $file_path_name) {
if (!($file_contents = @file_get_contents($file_path_name))) {
continue;
}
preg_match_all('/\$lang\[([^\]]+)\]/', $file_contents, $matches_array);
$matches_array = array_map(function($match) {
return trim($match, "'");
}, $matches_array[1]);
foreach ($matches_array as $match) {
$file_contents = preg_replace(
sprintf('/{\$lang\[\'%s\'\]}/', preg_quote($match, '/')),
sprintf('", gettext("%s"), "', $lang[$match]),
$file_contents
);
$file_contents = preg_replace(
sprintf('/\$lang\[\'%s\'\]/', preg_quote($match, '/')),
sprintf('gettext("%s")', $lang[$match]),
$file_contents
);
}
file_put_contents($file_path_name, $file_contents);
}
}
?>