Skip to content

Commit 8dd29e2

Browse files
committed
Added a function to merge language files.
1 parent a3ec01f commit 8dd29e2

File tree

5 files changed

+321
-0
lines changed

5 files changed

+321
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2008, Till Brehm, projektfarm Gmbh
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
/*
32+
Form Definition
33+
34+
Tabellendefinition
35+
36+
Datentypen:
37+
- INTEGER (Wandelt Ausdrücke in Int um)
38+
- DOUBLE
39+
- CURRENCY (Formatiert Zahlen nach Währungsnotation)
40+
- VARCHAR (kein weiterer Format Check)
41+
- TEXT (kein weiterer Format Check)
42+
- DATE (Datumsformat, Timestamp Umwandlung)
43+
44+
Formtype:
45+
- TEXT (normales Textfeld)
46+
- TEXTAREA (normales Textfeld)
47+
- PASSWORD (Feldinhalt wird nicht angezeigt)
48+
- SELECT (Gibt Werte als option Feld aus)
49+
- RADIO
50+
- CHECKBOX
51+
- FILE
52+
53+
VALUE:
54+
- Wert oder Array
55+
56+
Hinweis:
57+
Das ID-Feld ist nicht bei den Table Values einzufügen.
58+
59+
60+
*/
61+
62+
$form["title"] = "Software Repository";
63+
$form["description"] = "Software Repositoy which may contain addons or updates";
64+
$form["name"] = "software_repo";
65+
$form["action"] = "software_repo_edit.php";
66+
$form["db_table"] = "software_repo";
67+
$form["db_table_idx"] = "software_repo_id";
68+
$form["db_history"] = "no";
69+
$form["tab_default"] = "software_repo";
70+
$form["list_default"] = "software_repo_list.php";
71+
$form["auth"] = 'yes';
72+
73+
$form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user
74+
$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user
75+
$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete
76+
$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
77+
$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
78+
79+
$form["tabs"]['software_repo'] = array (
80+
'title' => "Repository",
81+
'width' => 80,
82+
'template' => "templates/software_repo_edit.htm",
83+
'fields' => array (
84+
##################################
85+
# Beginn Datenbankfelder
86+
##################################
87+
'repo_name' => array (
88+
'datatype' => 'VARCHAR',
89+
'formtype' => 'TEXT',
90+
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
91+
'errmsg'=> 'repo_name_empty'),
92+
1 => array ( 'type' => 'UNIQUE',
93+
'errmsg'=> 'repo_name_unique'),
94+
),
95+
'default' => '',
96+
'value' => '',
97+
'separator' => '',
98+
'width' => '40',
99+
'maxlength' => '40',
100+
'rows' => '',
101+
'cols' => ''
102+
),
103+
'repo_url' => array (
104+
'datatype' => 'VARCHAR',
105+
'formtype' => 'TEXT',
106+
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
107+
'errmsg'=> 'repo_name_empty'),
108+
1 => array ( 'type' => 'UNIQUE',
109+
'errmsg'=> 'repo_name_unique'),
110+
),
111+
'default' => '',
112+
'value' => '',
113+
'separator' => '',
114+
'width' => '40',
115+
'maxlength' => '40',
116+
'rows' => '',
117+
'cols' => ''
118+
),
119+
'repo_username' => array (
120+
'datatype' => 'VARCHAR',
121+
'formtype' => 'TEXT',
122+
'default' => '',
123+
'value' => '',
124+
'separator' => '',
125+
'width' => '30',
126+
'maxlength' => '30',
127+
'rows' => '',
128+
'cols' => ''
129+
),
130+
'repo_password' => array (
131+
'datatype' => 'VARCHAR',
132+
'formtype' => 'PASSWORD',
133+
'encryption' => 'CLEARTEXT',
134+
'default' => '',
135+
'value' => '',
136+
'separator' => '',
137+
'width' => '30',
138+
'maxlength' => '30',
139+
'rows' => '',
140+
'cols' => ''
141+
),
142+
'active' => array (
143+
'datatype' => 'VARCHAR',
144+
'formtype' => 'CHECKBOX',
145+
'default' => 'y',
146+
'value' => array(0 => 'n',1 => 'y')
147+
),
148+
##################################
149+
# ENDE Datenbankfelder
150+
##################################
151+
)
152+
);
153+
?>
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
/*
3+
Copyright (c) 2008, Till Brehm, projektfarm Gmbh
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification,
7+
are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
* Neither the name of ISPConfig nor the names of its contributors
15+
may be used to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
require_once('../../lib/config.inc.php');
31+
require_once('../../lib/app.inc.php');
32+
33+
//* Check permissions for module
34+
$app->auth->check_module_permissions('admin');
35+
36+
//* This is only allowed for administrators
37+
if(!$app->auth->is_admin()) die('only allowed for administrators.');
38+
39+
$app->uses('tpl');
40+
41+
$app->tpl->newTemplate('form.tpl.htm');
42+
$app->tpl->setInclude('content_tpl', 'templates/language_complete.htm');
43+
44+
//* reading languages
45+
$language_option = '';
46+
$error = '';
47+
$msg = '';
48+
$selected_language = (isset($_REQUEST['lng_select']))?substr($_REQUEST['lng_select'],0,2):'en';
49+
if(!preg_match("/^[a-z]{2}$/i", $selected_language)) die('unallowed characters in selected language name.');
50+
51+
$handle = opendir(ISPC_ROOT_PATH.'/lib/lang/');
52+
while ($file = readdir ($handle)) {
53+
if ($file != '.' && $file != '..') {
54+
$tmp_lng = substr($file,0,-4);
55+
if($tmp_lng !='' && $tmp_lng != 'en') {
56+
$selected = ($tmp_lng == $selected_language)?'SELECTED':'';
57+
$language_option .= "<option value='$tmp_lng' $selected>$tmp_lng</option>";
58+
//if(isset($_POST['lng_new']) && $_POST['lng_new'] == $tmp_lng) $error = 'Language exists already.';
59+
}
60+
}
61+
}
62+
$app->tpl->setVar('language_option',$language_option);
63+
$app->tpl->setVar('error',$error);
64+
65+
// Export the language file
66+
if(isset($_POST['lng_select']) && $error == '') {
67+
68+
// complete the global langauge file
69+
merge_langfile(ISPC_LIB_PATH."/lang/".$selected_language.".lng",ISPC_LIB_PATH."/lang/en.lng");
70+
71+
// Go trough all language files
72+
$bgcolor = '#FFFFFF';
73+
$language_files_list = array();
74+
$handle = @opendir(ISPC_WEB_PATH);
75+
while ($file = @readdir ($handle)) {
76+
if ($file != '.' && $file != '..') {
77+
if(@is_dir(ISPC_WEB_PATH.'/'.$file.'/lib/lang')) {
78+
$handle2 = opendir(ISPC_WEB_PATH.'/'.$file.'/lib/lang');
79+
while ($lang_file = @readdir ($handle2)) {
80+
if ($lang_file != '.' && $lang_file != '..' && substr($lang_file,0,2) == 'en') {
81+
$target_lang_file = $selected_language.substr($lang_file,2);
82+
merge_langfile(ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$target_lang_file,ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$lang_file);
83+
}
84+
}
85+
}
86+
}
87+
}
88+
}
89+
90+
function merge_langfile($langfile,$masterfile) {
91+
global $msg;
92+
93+
if(is_file($langfile)) {
94+
95+
// Load the english language file
96+
include($masterfile);
97+
if(isset($wb) && is_array($wb)) {
98+
$wb_master = $wb;
99+
unset($wb);
100+
} else {
101+
$wb_master = array();
102+
}
103+
104+
// Load the incomplete language file
105+
$wb = array();
106+
include($langfile);
107+
108+
$n = 0;
109+
foreach($wb_master as $key => $val) {
110+
if(!isset($wb[$key])) {
111+
$wb[$key] = $val;
112+
$n++;
113+
}
114+
}
115+
116+
$file_content = "<?php\n";
117+
foreach($wb as $key => $val) {
118+
$val = str_replace("'",'',$val);
119+
$val = str_replace('"','',$val);
120+
$file_content .= '$wb['."'$key'".'] = '."'$val';\n";
121+
}
122+
$file_content .= "?>\n";
123+
124+
$msg .= "Added $n lines to the file $langfile<br />";
125+
file_put_contents($langfile ,$file_content);
126+
} else {
127+
$msg .= "File does not exist yet. Copied file $masterfile to $langfile<br />";
128+
copy($masterfile,$langfile);
129+
}
130+
}
131+
132+
133+
134+
135+
$app->tpl->setVar('msg',$msg);
136+
137+
//* load language file
138+
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_complete.lng';
139+
include($lng_file);
140+
$app->tpl->setVar($wb);
141+
142+
$app->tpl_defaults();
143+
$app->tpl->pparse();
144+
145+
146+
?>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
$wb["list_head_txt"] = 'Merge the selected language file with the english master language file. <br />This adds missing strings from the english master language files to the selected language.';
3+
$wb["language_select_txt"] = 'Select language';
4+
$wb['btn_save_txt'] = 'Merge files now';
5+
$wb['btn_cancel_txt'] = 'Back';
6+
?>

interface/web/admin/lib/module.conf.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@
136136
'target' => 'content',
137137
'link' => 'admin/language_add.php');
138138

139+
$items[] = array( 'title' => 'Merge',
140+
'target' => 'content',
141+
'link' => 'admin/language_complete.php');
142+
139143
$items[] = array( 'title' => 'Export',
140144
'target' => 'content',
141145
'link' => 'admin/language_export.php');
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br />
2+
<p class="frmText11">
3+
<tmpl_var name="language_select_txt">: <select name="lng_select">{tmpl_var name='language_option'}</select>
4+
</p>
5+
<tmpl_if name="msg">
6+
<p class="msg" ><tmpl_var name="msg"></p>
7+
</tmpl_if>
8+
<tmpl_if name="error">
9+
<p class="error" ><tmpl_var name="error"></p>
10+
</tmpl_if>
11+
<input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_complete.php');"><div class="buttonEnding"></div>
12+
<input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php');"><div class="buttonEnding"></div>

0 commit comments

Comments
 (0)