Test Failed
Push — master ( 2c8b6d...9d1fea )
by Alxarafe
45:51
created
dolibarr/dev/examples/code/create_invoice.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -83,19 +83,19 @@  discard block
 block discarded – undo
83 83
 $idobject=$obj->create($user);
84 84
 if ($idobject > 0)
85 85
 {
86
-	// Change status to validated
87
-	$result=$obj->validate($user);
88
-	if ($result > 0) print "OK Object created with id ".$idobject."\n";
89
-	else
90
-	{
91
-		$error++;
92
-		dol_print_error($db,$obj->error);
93
-	}
86
+    // Change status to validated
87
+    $result=$obj->validate($user);
88
+    if ($result > 0) print "OK Object created with id ".$idobject."\n";
89
+    else
90
+    {
91
+        $error++;
92
+        dol_print_error($db,$obj->error);
93
+    }
94 94
 }
95 95
 else
96 96
 {
97
-	$error++;
98
-	dol_print_error($db,$obj->error);
97
+    $error++;
98
+    dol_print_error($db,$obj->error);
99 99
 }
100 100
 
101 101
 
@@ -103,13 +103,13 @@  discard block
 block discarded – undo
103 103
 
104 104
 if (! $error)
105 105
 {
106
-	$db->commit();
107
-	print '--- end ok'."\n";
106
+    $db->commit();
107
+    print '--- end ok'."\n";
108 108
 }
109 109
 else
110 110
 {
111
-	print '--- end error code='.$error."\n";
112
-	$db->rollback();
111
+    print '--- end error code='.$error."\n";
112
+    $db->rollback();
113 113
 }
114 114
 
115 115
 $db->close();
Please login to merge, or discard this patch.
dolibarr/dev/examples/code/create_user.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -71,23 +71,23 @@  discard block
 block discarded – undo
71 71
 $idobject=$obj->create($user);
72 72
 if ($idobject > 0)
73 73
 {
74
-	// Change status to validated
75
-	$result=$obj->setStatut(1);
76
-	if ($result > 0) print "OK Object created with id ".$idobject."\n";
77
-	else
78
-	{
79
-		$error++;
80
-		dol_print_error($db,$obj->error);
81
-	}
74
+    // Change status to validated
75
+    $result=$obj->setStatut(1);
76
+    if ($result > 0) print "OK Object created with id ".$idobject."\n";
77
+    else
78
+    {
79
+        $error++;
80
+        dol_print_error($db,$obj->error);
81
+    }
82 82
 }
83 83
 else if ($obj->error == 'ErrorLoginAlreadyExists')
84 84
 {
85
-     print "User with login ".$obj->login." already exists\n";
85
+        print "User with login ".$obj->login." already exists\n";
86 86
 }
87 87
 else
88 88
 {
89
-	$error++;
90
-	dol_print_error($db,$obj->error);
89
+    $error++;
90
+    dol_print_error($db,$obj->error);
91 91
 }
92 92
 
93 93
 
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 
96 96
 if (! $error)
97 97
 {
98
-	$db->commit();
99
-	print '--- end ok'."\n";
98
+    $db->commit();
99
+    print '--- end ok'."\n";
100 100
 }
101 101
 else
102 102
 {
103
-	print '--- end error code='.$error."\n";
104
-	$db->rollback();
103
+    print '--- end error code='.$error."\n";
104
+    $db->rollback();
105 105
 }
106 106
 
107 107
 $db->close();
Please login to merge, or discard this patch.
dolibarr/dev/examples/code/create_order.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -81,19 +81,19 @@  discard block
 block discarded – undo
81 81
 $idobject=$com->create($user);
82 82
 if ($idobject > 0)
83 83
 {
84
-	// Change status to validated
85
-	$result=$com->valid($user);
86
-	if ($result > 0) print "OK Object created with id ".$idobject."\n";
87
-	else
88
-	{
89
-		$error++;
90
-		dol_print_error($db,$com->error);
91
-	}
84
+    // Change status to validated
85
+    $result=$com->valid($user);
86
+    if ($result > 0) print "OK Object created with id ".$idobject."\n";
87
+    else
88
+    {
89
+        $error++;
90
+        dol_print_error($db,$com->error);
91
+    }
92 92
 }
93 93
 else
94 94
 {
95
-	$error++;
96
-	dol_print_error($db,$com->error);
95
+    $error++;
96
+    dol_print_error($db,$com->error);
97 97
 }
98 98
 
99 99
 
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
 
102 102
 if (! $error)
103 103
 {
104
-	$db->commit();
105
-	print '--- end ok'."\n";
104
+    $db->commit();
105
+    print '--- end ok'."\n";
106 106
 }
107 107
 else
108 108
 {
109
-	print '--- end error code='.$error."\n";
110
-	$db->rollback();
109
+    print '--- end error code='.$error."\n";
110
+    $db->rollback();
111 111
 }
112 112
 
113 113
 $db->close();
Please login to merge, or discard this patch.
dolibarr/dev/examples/code/create_product.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -81,25 +81,25 @@
 block discarded – undo
81 81
 $idobject = $myproduct->create($user);
82 82
 if ($idobject > 0)
83 83
 {
84
-	print "OK Object created with id ".$idobject."\n";
84
+    print "OK Object created with id ".$idobject."\n";
85 85
 }
86 86
 else
87 87
 {
88
-	$error++;
89
-	dol_print_error($db,$myproduct->error);
88
+    $error++;
89
+    dol_print_error($db,$myproduct->error);
90 90
 }
91 91
 
92 92
 // -------------------- END OF YOUR CODE --------------------
93 93
 
94 94
 if (! $error)
95 95
 {
96
-	$db->commit();
97
-	print '--- end ok'."\n";
96
+    $db->commit();
97
+    print '--- end ok'."\n";
98 98
 }
99 99
 else
100 100
 {
101
-	print '--- end error code='.$error."\n";
102
-	$db->rollback();
101
+    print '--- end error code='.$error."\n";
102
+    $db->rollback();
103 103
 }
104 104
 
105 105
 $db->close();
Please login to merge, or discard this patch.
dolibarr/dev/translation/autotranslator.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -69,23 +69,23 @@
 block discarded – undo
69 69
 $file='';
70 70
 if (isset($argv[4]))
71 71
 {
72
-	$file=$argv[4];
73
-	print 'Argument 4='.$argv[4]."\n";
72
+    $file=$argv[4];
73
+    print 'Argument 4='.$argv[4]."\n";
74 74
 }
75 75
 print 'Files will be generated/updated in directory '.$dir."\n";
76 76
 
77 77
 if ($argv[2] != 'all')
78 78
 {
79
-	if (! is_dir($dir.'/'.$argv[2]))
80
-	{
81
-		print 'Create directory '.$dir.'/'.$argv[2]."\n";
82
-		$result=mkdir($dir.'/'.$argv[2]);
83
-		if (! $result)
84
-		{
85
-			$db->close();
86
-			return -1;
87
-		}
88
-	}
79
+    if (! is_dir($dir.'/'.$argv[2]))
80
+    {
81
+        print 'Create directory '.$dir.'/'.$argv[2]."\n";
82
+        $result=mkdir($dir.'/'.$argv[2]);
83
+        if (! $result)
84
+        {
85
+            $db->close();
86
+            return -1;
87
+        }
88
+    }
89 89
 }
90 90
 
91 91
 require_once DOL_DOCUMENT_ROOT."/../dev/translation/autotranslator.class.php";
Please login to merge, or discard this patch.
dolibarr/dev/translation/strip_language_file.php 1 patch
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 
51 51
 // Test if batch mode
52 52
 if (substr($sapi_type, 0, 3) == 'cgi') {
53
-	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
54
-	exit;
53
+    echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
54
+    exit;
55 55
 }
56 56
 
57 57
 $rc = 0;
@@ -65,11 +65,11 @@  discard block
 block discarded – undo
65 65
 
66 66
 if (empty($lPrimary) || empty($lSecondary) || empty($filesToProcess))
67 67
 {
68
-	$rc = 1;
69
-	$msg = '***** Script to clean language files *****'."\n";
70
-	$msg.= 'Usage: ./dev/translation/strip_language_file.php xx_XX xx_YY [file.lang|all]'."\n";
71
-	print $msg . "(rc=$rc).\n";
72
-	exit($rc);
68
+    $rc = 1;
69
+    $msg = '***** Script to clean language files *****'."\n";
70
+    $msg.= 'Usage: ./dev/translation/strip_language_file.php xx_XX xx_YY [file.lang|all]'."\n";
71
+    print $msg . "(rc=$rc).\n";
72
+    exit($rc);
73 73
 }
74 74
 
75 75
 $aPrimary = array();
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
 // Define array $filesToProcess
80 80
 if ($filesToProcess == 'all')
81 81
 {
82
-	$dir = new DirectoryIterator('htdocs/langs/'.$lPrimary);
83
-	while($dir->valid()) {
84
-		if(!$dir->isDot() && $dir->isFile() && ! preg_match('/^\./',$dir->getFilename())) {
85
-			$files[] =  $dir->getFilename();
86
-		}
87
-		$dir->next();
88
-	}
89
-	$filesToProcess=$files;
82
+    $dir = new DirectoryIterator('htdocs/langs/'.$lPrimary);
83
+    while($dir->valid()) {
84
+        if(!$dir->isDot() && $dir->isFile() && ! preg_match('/^\./',$dir->getFilename())) {
85
+            $files[] =  $dir->getFilename();
86
+        }
87
+        $dir->next();
88
+    }
89
+    $filesToProcess=$files;
90 90
 }
91 91
 else $filesToProcess=explode(',',$filesToProcess);
92 92
 
@@ -96,257 +96,257 @@  discard block
 block discarded – undo
96 96
 // Loop on each file
97 97
 foreach($filesToProcess as $fileToProcess)
98 98
 {
99
-	$lPrimaryFile = 'htdocs/langs/'.$lPrimary.'/'.$fileToProcess;
100
-	$lSecondaryFile = 'htdocs/langs/'.$lSecondary.'/'.$fileToProcess;
101
-	$lEnglishFile = 'htdocs/langs/'.$lEnglish.'/'.$fileToProcess;
102
-	$output = $lSecondaryFile . '.delta';
103
-
104
-	print "---- Process language file ".$lSecondaryFile."\n";
105
-
106
-	if ( ! is_readable($lPrimaryFile) ) {
107
-		$rc = 2;
108
-		$msg = "Cannot read primary language file $lPrimaryFile.";
109
-		print $msg . " (rc=$rc).\n";
110
-		exit($rc);
111
-	}
112
-
113
-	if ( ! is_readable($lSecondaryFile) ) {
114
-		$rc = 3;
115
-		$msg = "Cannot read secondary language file $lSecondaryFile. We discard this file.";
116
-		print $msg . "\n";
117
-		continue;
118
-	}
119
-
120
-	if ( ! is_readable($lEnglishFile) ) {
121
-		$rc = 3;
122
-		$msg = "Cannot read english language file $lEnglishFile. We discard this file.";
123
-		print $msg . "\n";
124
-		continue;
125
-	}
126
-
127
-	// Start reading and parsing Secondary
128
-
129
-	if ( $handle = fopen($lSecondaryFile, 'r') )
130
-	{
131
-		print "Read Secondary File $lSecondaryFile:\n";
132
-		$cnt = 0;
133
-		while (($line = fgets($handle)) !== false)
134
-		{
135
-			$cnt++;
136
-
137
-			// strip comments
138
-			if ( preg_match("/^\w*#/", $line) ) {
139
-				continue;
140
-			}
141
-			// strip empty lines
142
-			if ( preg_match("/^\w*$/", $line) ) {
143
-				continue;
144
-			}
145
-
146
-			$a = mb_split('=', trim($line), 2);
147
-			if ( count($a) != 2 ) {
148
-				print "ERROR in file $lSecondaryFile, line $cnt: " . trim($line) . "\n";
149
-				continue;
150
-			}
151
-
152
-			list($key, $value) = $a;
153
-
154
-			// key is redundant
155
-			if ( array_key_exists($key, $aSecondary) ) {
156
-				print "Key $key is redundant in file $lSecondaryFile (line: $cnt).\n";
157
-				continue;
158
-			}
159
-
160
-			// String has no value
161
-			if ( $value == '' ) {
162
-				print "Key $key has no value in file $lSecondaryFile (line: $cnt).\n";
163
-				continue;
164
-			}
165
-
166
-			$aSecondary[$key] = trim($value);
167
-		}
168
-		if ( ! feof($handle) )
169
-		{
170
-			$rc = 5;
171
-			$msg = "Unexpected fgets() fail";
172
-			print $msg . " (rc=$rc).\n";
173
-			exit($rc);
174
-		}
175
-		fclose($handle);
176
-	}
177
-	else {
178
-		$rc = 6;
179
-		$msg = "Cannot open file $lSecondaryFile";
180
-		print $msg . " (rc=$rc).\n";
181
-		exit($rc);
182
-	}
183
-
184
-
185
-	// Start reading and parsing English
186
-
187
-	if ( $handle = fopen($lEnglishFile, 'r') )
188
-	{
189
-		print "Read English File $lEnglishFile:\n";
190
-		$cnt = 0;
191
-		while (($line = fgets($handle)) !== false)
192
-		{
193
-			$cnt++;
194
-
195
-			// strip comments
196
-			if ( preg_match("/^\w*#/", $line) ) {
197
-				continue;
198
-			}
199
-			// strip empty lines
200
-			if ( preg_match("/^\w*$/", $line) ) {
201
-				continue;
202
-			}
203
-
204
-			$a = mb_split('=', trim($line), 2);
205
-			if ( count($a) != 2 ) {
206
-				print "ERROR in file $lEnglishFile, line $cnt: " . trim($line) . "\n";
207
-				continue;
208
-			}
209
-
210
-			list($key, $value) = $a;
211
-
212
-			// key is redundant
213
-			if ( array_key_exists($key, $aEnglish) ) {
214
-				print "Key $key is redundant in file $lEnglishFile (line: $cnt).\n";
215
-				continue;
216
-			}
217
-
218
-			// String has no value
219
-			if ( $value == '' ) {
220
-				print "Key $key has no value in file $lEnglishFile (line: $cnt).\n";
221
-				continue;
222
-			}
223
-
224
-			$aEnglish[$key] = trim($value);
225
-		}
226
-		if ( ! feof($handle) )
227
-		{
228
-			$rc = 5;
229
-			$msg = "Unexpected fgets() fail";
230
-			print $msg . " (rc=$rc).\n";
231
-			exit($rc);
232
-		}
233
-		fclose($handle);
234
-	}
235
-	else {
236
-		$rc = 6;
237
-		$msg = "Cannot open file $lEnglishFile";
238
-		print $msg . " (rc=$rc).\n";
239
-		exit($rc);
240
-	}
241
-
242
-
243
-
244
-	// Start reading and parsing Primary. See rules in header!
245
-
246
-	$arrayofkeytoalwayskeep=array('DIRECTION','FONTFORPDF','FONTSIZEFORPDF','SeparatorDecimal','SeparatorThousand');
247
-
248
-
249
-	if ( $handle = fopen($lPrimaryFile, 'r') )
250
-	{
251
-		if ( ! $oh = fopen($output, 'w') )
252
-		{
253
-			print "ERROR in writing to file $output\n";
254
-			exit;
255
-		}
256
-
257
-		print "Read Primary File $lPrimaryFile and write ".$output.":\n";
258
-
259
-		fwrite($oh, "# Dolibarr language file - Source file is en_US - ".(preg_replace('/\.lang$/','',$fileToProcess))."\n");
260
-
261
-		$cnt = 0;
262
-		while (($line = fgets($handle)) !== false)
263
-		{
264
-			$cnt++;
265
-
266
-			// strip comments
267
-			if ( preg_match("/^\w*#/", $line) ) {
268
-				continue;
269
-			}
270
-			// strip empty lines
271
-			if ( preg_match("/^\w*$/", $line) ) {
272
-				continue;
273
-			}
274
-
275
-			$a = mb_split('=', trim($line), 2);
276
-			if ( count($a) != 2 ) {
277
-				print "ERROR in file $lPrimaryFile, line $cnt: " . trim($line) . "\n";
278
-				continue;
279
-			}
280
-
281
-			list($key, $value) = $a;
282
-
283
-			// key is redundant
284
-			if ( array_key_exists($key, $aPrimary) ) {
285
-				print "Key $key is redundant in file $lPrimaryFile (line: $cnt) - Already found into ".$fileFirstFound[$key]." (line: ".$lineFirstFound[$key].").\n";
286
-				continue;
287
-			}
288
-			else
289
-			{
290
-				$fileFirstFound[$key] = $fileToProcess;
291
-				$lineFirstFound[$key] = $cnt;
292
-			}
293
-
294
-			// String has no value
295
-			if ( $value == '' ) {
296
-				print "Key $key has no value in file $lPrimaryFile (line: $cnt).\n";
297
-				continue;
298
-			}
299
-
300
-			$aPrimary[$key] = trim($value);
301
-			$fileFirstFound[$key] = $fileToProcess;
302
-			$lineFirstFound[$key] = $cnt;
303
-
304
-			// ----- Process output now -----
305
-
306
-			//print "Found primary key = ".$key."\n";
307
-
308
-			// Key not in other file
309
-			if (in_array($key, $arrayofkeytoalwayskeep) || preg_match('/^FormatDate/',$key) || preg_match('/^FormatHour/',$key))
310
-			{
311
-				//print "Key $key is a key we always want to see into secondary file (line: $cnt).\n";
312
-			}
313
-			else if ( ! array_key_exists($key, $aSecondary))
314
-			{
315
-				//print "Key $key does NOT exist in secondary language (line: $cnt).\n";
316
-				continue;
317
-			}
318
-
319
-			// String exists in both files and value into alternative language differs from main language but also from english files
320
-			if (
321
-				(! empty($aSecondary[$key]) && $aSecondary[$key] != $aPrimary[$key]
322
-			    && ! empty($aEnglish[$key]) && $aSecondary[$key] != $aEnglish[$key])
323
-				|| in_array($key, $arrayofkeytoalwayskeep) || preg_match('/^FormatDate/',$key) || preg_match('/^FormatHour/',$key)
324
-				)
325
-			{
326
-				//print "Key $key differs (aSecondary=".$aSecondary[$key].", aPrimary=".$aPrimary[$key].", aEnglish=".$aEnglish[$key].") so we add it into new secondary language (line: $cnt).\n";
327
-				fwrite($oh, $key."=".(empty($aSecondary[$key])?$aPrimary[$key]:$aSecondary[$key])."\n");
328
-			}
329
-		}
330
-		if ( ! feof($handle) ) {
331
-			$rc = 7;
332
-			$msg = "Unexpected fgets() fail";
333
-			print $msg . " (rc=$rc).\n";
334
-			exit($rc);
335
-		}
336
-		fclose($oh);
337
-		fclose($handle);
338
-	}
339
-	else {
340
-		$rc = 8;
341
-		$msg = "Cannot open file $lPrimaryFile";
342
-		print $msg . " (rc=$rc).\n";
343
-		exit($rc);
344
-	}
345
-
346
-	print "Output can be found at $output.\n";
347
-
348
-	print "To rename all .delta files, you can do:\n";
349
-	print '> for fic in `ls htdocs/langs/'.$lSecondary.'/*.delta`; do f=`echo $fic | sed -e \'s/\.delta//\'`; echo $f; mv $f.delta $f; done'."\n";
99
+    $lPrimaryFile = 'htdocs/langs/'.$lPrimary.'/'.$fileToProcess;
100
+    $lSecondaryFile = 'htdocs/langs/'.$lSecondary.'/'.$fileToProcess;
101
+    $lEnglishFile = 'htdocs/langs/'.$lEnglish.'/'.$fileToProcess;
102
+    $output = $lSecondaryFile . '.delta';
103
+
104
+    print "---- Process language file ".$lSecondaryFile."\n";
105
+
106
+    if ( ! is_readable($lPrimaryFile) ) {
107
+        $rc = 2;
108
+        $msg = "Cannot read primary language file $lPrimaryFile.";
109
+        print $msg . " (rc=$rc).\n";
110
+        exit($rc);
111
+    }
112
+
113
+    if ( ! is_readable($lSecondaryFile) ) {
114
+        $rc = 3;
115
+        $msg = "Cannot read secondary language file $lSecondaryFile. We discard this file.";
116
+        print $msg . "\n";
117
+        continue;
118
+    }
119
+
120
+    if ( ! is_readable($lEnglishFile) ) {
121
+        $rc = 3;
122
+        $msg = "Cannot read english language file $lEnglishFile. We discard this file.";
123
+        print $msg . "\n";
124
+        continue;
125
+    }
126
+
127
+    // Start reading and parsing Secondary
128
+
129
+    if ( $handle = fopen($lSecondaryFile, 'r') )
130
+    {
131
+        print "Read Secondary File $lSecondaryFile:\n";
132
+        $cnt = 0;
133
+        while (($line = fgets($handle)) !== false)
134
+        {
135
+            $cnt++;
136
+
137
+            // strip comments
138
+            if ( preg_match("/^\w*#/", $line) ) {
139
+                continue;
140
+            }
141
+            // strip empty lines
142
+            if ( preg_match("/^\w*$/", $line) ) {
143
+                continue;
144
+            }
145
+
146
+            $a = mb_split('=', trim($line), 2);
147
+            if ( count($a) != 2 ) {
148
+                print "ERROR in file $lSecondaryFile, line $cnt: " . trim($line) . "\n";
149
+                continue;
150
+            }
151
+
152
+            list($key, $value) = $a;
153
+
154
+            // key is redundant
155
+            if ( array_key_exists($key, $aSecondary) ) {
156
+                print "Key $key is redundant in file $lSecondaryFile (line: $cnt).\n";
157
+                continue;
158
+            }
159
+
160
+            // String has no value
161
+            if ( $value == '' ) {
162
+                print "Key $key has no value in file $lSecondaryFile (line: $cnt).\n";
163
+                continue;
164
+            }
165
+
166
+            $aSecondary[$key] = trim($value);
167
+        }
168
+        if ( ! feof($handle) )
169
+        {
170
+            $rc = 5;
171
+            $msg = "Unexpected fgets() fail";
172
+            print $msg . " (rc=$rc).\n";
173
+            exit($rc);
174
+        }
175
+        fclose($handle);
176
+    }
177
+    else {
178
+        $rc = 6;
179
+        $msg = "Cannot open file $lSecondaryFile";
180
+        print $msg . " (rc=$rc).\n";
181
+        exit($rc);
182
+    }
183
+
184
+
185
+    // Start reading and parsing English
186
+
187
+    if ( $handle = fopen($lEnglishFile, 'r') )
188
+    {
189
+        print "Read English File $lEnglishFile:\n";
190
+        $cnt = 0;
191
+        while (($line = fgets($handle)) !== false)
192
+        {
193
+            $cnt++;
194
+
195
+            // strip comments
196
+            if ( preg_match("/^\w*#/", $line) ) {
197
+                continue;
198
+            }
199
+            // strip empty lines
200
+            if ( preg_match("/^\w*$/", $line) ) {
201
+                continue;
202
+            }
203
+
204
+            $a = mb_split('=', trim($line), 2);
205
+            if ( count($a) != 2 ) {
206
+                print "ERROR in file $lEnglishFile, line $cnt: " . trim($line) . "\n";
207
+                continue;
208
+            }
209
+
210
+            list($key, $value) = $a;
211
+
212
+            // key is redundant
213
+            if ( array_key_exists($key, $aEnglish) ) {
214
+                print "Key $key is redundant in file $lEnglishFile (line: $cnt).\n";
215
+                continue;
216
+            }
217
+
218
+            // String has no value
219
+            if ( $value == '' ) {
220
+                print "Key $key has no value in file $lEnglishFile (line: $cnt).\n";
221
+                continue;
222
+            }
223
+
224
+            $aEnglish[$key] = trim($value);
225
+        }
226
+        if ( ! feof($handle) )
227
+        {
228
+            $rc = 5;
229
+            $msg = "Unexpected fgets() fail";
230
+            print $msg . " (rc=$rc).\n";
231
+            exit($rc);
232
+        }
233
+        fclose($handle);
234
+    }
235
+    else {
236
+        $rc = 6;
237
+        $msg = "Cannot open file $lEnglishFile";
238
+        print $msg . " (rc=$rc).\n";
239
+        exit($rc);
240
+    }
241
+
242
+
243
+
244
+    // Start reading and parsing Primary. See rules in header!
245
+
246
+    $arrayofkeytoalwayskeep=array('DIRECTION','FONTFORPDF','FONTSIZEFORPDF','SeparatorDecimal','SeparatorThousand');
247
+
248
+
249
+    if ( $handle = fopen($lPrimaryFile, 'r') )
250
+    {
251
+        if ( ! $oh = fopen($output, 'w') )
252
+        {
253
+            print "ERROR in writing to file $output\n";
254
+            exit;
255
+        }
256
+
257
+        print "Read Primary File $lPrimaryFile and write ".$output.":\n";
258
+
259
+        fwrite($oh, "# Dolibarr language file - Source file is en_US - ".(preg_replace('/\.lang$/','',$fileToProcess))."\n");
260
+
261
+        $cnt = 0;
262
+        while (($line = fgets($handle)) !== false)
263
+        {
264
+            $cnt++;
265
+
266
+            // strip comments
267
+            if ( preg_match("/^\w*#/", $line) ) {
268
+                continue;
269
+            }
270
+            // strip empty lines
271
+            if ( preg_match("/^\w*$/", $line) ) {
272
+                continue;
273
+            }
274
+
275
+            $a = mb_split('=', trim($line), 2);
276
+            if ( count($a) != 2 ) {
277
+                print "ERROR in file $lPrimaryFile, line $cnt: " . trim($line) . "\n";
278
+                continue;
279
+            }
280
+
281
+            list($key, $value) = $a;
282
+
283
+            // key is redundant
284
+            if ( array_key_exists($key, $aPrimary) ) {
285
+                print "Key $key is redundant in file $lPrimaryFile (line: $cnt) - Already found into ".$fileFirstFound[$key]." (line: ".$lineFirstFound[$key].").\n";
286
+                continue;
287
+            }
288
+            else
289
+            {
290
+                $fileFirstFound[$key] = $fileToProcess;
291
+                $lineFirstFound[$key] = $cnt;
292
+            }
293
+
294
+            // String has no value
295
+            if ( $value == '' ) {
296
+                print "Key $key has no value in file $lPrimaryFile (line: $cnt).\n";
297
+                continue;
298
+            }
299
+
300
+            $aPrimary[$key] = trim($value);
301
+            $fileFirstFound[$key] = $fileToProcess;
302
+            $lineFirstFound[$key] = $cnt;
303
+
304
+            // ----- Process output now -----
305
+
306
+            //print "Found primary key = ".$key."\n";
307
+
308
+            // Key not in other file
309
+            if (in_array($key, $arrayofkeytoalwayskeep) || preg_match('/^FormatDate/',$key) || preg_match('/^FormatHour/',$key))
310
+            {
311
+                //print "Key $key is a key we always want to see into secondary file (line: $cnt).\n";
312
+            }
313
+            else if ( ! array_key_exists($key, $aSecondary))
314
+            {
315
+                //print "Key $key does NOT exist in secondary language (line: $cnt).\n";
316
+                continue;
317
+            }
318
+
319
+            // String exists in both files and value into alternative language differs from main language but also from english files
320
+            if (
321
+                (! empty($aSecondary[$key]) && $aSecondary[$key] != $aPrimary[$key]
322
+                && ! empty($aEnglish[$key]) && $aSecondary[$key] != $aEnglish[$key])
323
+                || in_array($key, $arrayofkeytoalwayskeep) || preg_match('/^FormatDate/',$key) || preg_match('/^FormatHour/',$key)
324
+                )
325
+            {
326
+                //print "Key $key differs (aSecondary=".$aSecondary[$key].", aPrimary=".$aPrimary[$key].", aEnglish=".$aEnglish[$key].") so we add it into new secondary language (line: $cnt).\n";
327
+                fwrite($oh, $key."=".(empty($aSecondary[$key])?$aPrimary[$key]:$aSecondary[$key])."\n");
328
+            }
329
+        }
330
+        if ( ! feof($handle) ) {
331
+            $rc = 7;
332
+            $msg = "Unexpected fgets() fail";
333
+            print $msg . " (rc=$rc).\n";
334
+            exit($rc);
335
+        }
336
+        fclose($oh);
337
+        fclose($handle);
338
+    }
339
+    else {
340
+        $rc = 8;
341
+        $msg = "Cannot open file $lPrimaryFile";
342
+        print $msg . " (rc=$rc).\n";
343
+        exit($rc);
344
+    }
345
+
346
+    print "Output can be found at $output.\n";
347
+
348
+    print "To rename all .delta files, you can do:\n";
349
+    print '> for fic in `ls htdocs/langs/'.$lSecondary.'/*.delta`; do f=`echo $fic | sed -e \'s/\.delta//\'`; echo $f; mv $f.delta $f; done'."\n";
350 350
 }
351 351
 
352 352
 
Please login to merge, or discard this patch.
dolibarr/dev/translation/sanity_check_en_langfiles.php 1 patch
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 $files = scandir($workdir);
108 108
 if (empty($files))
109 109
 {
110
-	echo "Can't scan workdir = ".$workdir;
111
-	exit;
110
+    echo "Can't scan workdir = ".$workdir;
111
+    exit;
112 112
 }
113 113
 
114 114
 $dups=array();
@@ -122,38 +122,38 @@  discard block
 block discarded – undo
122 122
 $langstrings_3d = array();
123 123
 $langstrings_full = array();
124 124
 foreach ($files AS $file) {
125
-	$path_file = pathinfo($file);
126
-	// we're only interested in .lang files
127
-	if ($path_file['extension']=='lang') {
128
-		$content = file($workdir.$file);
129
-		foreach ($content AS $line => $row) {
130
-			// don't want comment lines
131
-			if (substr($row,0,1) !== '#') {
132
-				// don't want lines without the separator (why should those even be here, anyway...)
133
-				if (strpos($row,'=')!==false) {
134
-					$row_array = explode('=',$row);		// $row_array[0] = key
135
-					$langstrings_3d[$path_file['basename']][$line+1]=$row_array[0];
136
-					$langstrings_3dtrans[$path_file['basename']][$line+1]=$row_array[1];
137
-					$langstrings_full[]=$row_array[0];
138
-					$langstrings_dist[$row_array[0]]=$row;
139
-				}
140
-			}
141
-		}
142
-	}
125
+    $path_file = pathinfo($file);
126
+    // we're only interested in .lang files
127
+    if ($path_file['extension']=='lang') {
128
+        $content = file($workdir.$file);
129
+        foreach ($content AS $line => $row) {
130
+            // don't want comment lines
131
+            if (substr($row,0,1) !== '#') {
132
+                // don't want lines without the separator (why should those even be here, anyway...)
133
+                if (strpos($row,'=')!==false) {
134
+                    $row_array = explode('=',$row);		// $row_array[0] = key
135
+                    $langstrings_3d[$path_file['basename']][$line+1]=$row_array[0];
136
+                    $langstrings_3dtrans[$path_file['basename']][$line+1]=$row_array[1];
137
+                    $langstrings_full[]=$row_array[0];
138
+                    $langstrings_dist[$row_array[0]]=$row;
139
+                }
140
+            }
141
+        }
142
+    }
143 143
 }
144 144
 
145 145
 foreach ($langstrings_3d AS $filename => $file)
146 146
 {
147
-	foreach ($file AS $linenum => $value)
148
-	{
149
-		$keys = array_keys($langstrings_full, $value);
150
-		if (count($keys)>1)
151
-		{
152
-				foreach ($keys AS $key) {
153
-					$dups[$value][$filename][$linenum] = trim($langstrings_3dtrans[$filename][$linenum]);
154
-				}
155
-		}
156
-	}
147
+    foreach ($file AS $linenum => $value)
148
+    {
149
+        $keys = array_keys($langstrings_full, $value);
150
+        if (count($keys)>1)
151
+        {
152
+                foreach ($keys AS $key) {
153
+                    $dups[$value][$filename][$linenum] = trim($langstrings_3dtrans[$filename][$linenum]);
154
+                }
155
+        }
156
+    }
157 157
 }
158 158
 
159 159
 if ($web) print "<h2>";
@@ -175,49 +175,49 @@  discard block
 block discarded – undo
175 175
 $count = 0;
176 176
 foreach ($dups as $string => $pages)
177 177
 {
178
-	$count++;
179
-	$s='';
180
-
181
-	// Keyword $string
182
-	if ($web) $s.="<tr>";
183
-	if ($web) $s.="<td align=\"center\">";
184
-	if ($web) $s.=$count;
185
-	if ($web) $s.="</td>";
186
-	if ($web) $s.="<td>";
187
-	$s.=$string;
188
-	if ($web) $s.="</td>";
189
-	if ($web) $s.="<td>";
190
-	if (! $web) $s.= ' : ';
191
-
192
-	// Loop on each files keyword was found
178
+    $count++;
179
+    $s='';
180
+
181
+    // Keyword $string
182
+    if ($web) $s.="<tr>";
183
+    if ($web) $s.="<td align=\"center\">";
184
+    if ($web) $s.=$count;
185
+    if ($web) $s.="</td>";
186
+    if ($web) $s.="<td>";
187
+    $s.=$string;
188
+    if ($web) $s.="</td>";
189
+    if ($web) $s.="<td>";
190
+    if (! $web) $s.= ' : ';
191
+
192
+    // Loop on each files keyword was found
193 193
     $duplicateinsamefile=0;
194
-	$inmain=0;
194
+    $inmain=0;
195 195
     $inadmin=0;
196
-	foreach ($pages AS $file => $lines)
197
-	{
196
+    foreach ($pages AS $file => $lines)
197
+    {
198 198
         if ($file == 'main.lang') { $inmain=1; $inadmin=0; }
199 199
         if ($file == 'admin.lang' && ! $inmain) { $inadmin=1; }
200 200
 
201
-	    $s.=$file." ";
201
+        $s.=$file." ";
202 202
 
203
-	    // Loop on each line keword was found into file.
204
-	    $listoffilesforthisentry=array();
205
-	    foreach ($lines as $line => $translatedvalue)
206
-		{
203
+        // Loop on each line keword was found into file.
204
+        $listoffilesforthisentry=array();
205
+        foreach ($lines as $line => $translatedvalue)
206
+        {
207 207
             if (! empty($listoffilesforthisentry[$file])) $duplicateinsamefile=1;
208 208
             $listoffilesforthisentry[$file]=1;
209 209
 
210
-			$s.= "(".$line." - ".htmlentities($translatedvalue).") ";
211
-		}
212
-		if ($web) $s.="<br>";
213
-	}
214
-	if ($web) $s.="</td></tr>";
215
-	$s.="\n";
216
-
217
-	if ($duplicateinsamefile) $sduplicateinsamefile .= $s;
218
-	else if ($inmain) $sinmainandother .= $s;
219
-	else if ($inadmin) $sininstallandadmin .= $s;
220
-	else $sother .= $s;
210
+            $s.= "(".$line." - ".htmlentities($translatedvalue).") ";
211
+        }
212
+        if ($web) $s.="<br>";
213
+    }
214
+    if ($web) $s.="</td></tr>";
215
+    $s.="\n";
216
+
217
+    if ($duplicateinsamefile) $sduplicateinsamefile .= $s;
218
+    else if ($inmain) $sinmainandother .= $s;
219
+    else if ($inadmin) $sininstallandadmin .= $s;
220
+    else $sother .= $s;
221 221
 }
222 222
 
223 223
 if (! $web) print "\n***** Entries duplicated in same file\n";
@@ -254,122 +254,122 @@  discard block
 block discarded – undo
254 254
     print "***** Strings in en_US that are never used:\n";
255 255
 
256 256
     $unused=array();
257
-	foreach ($langstrings_dist AS $value => $line)
258
-	{
259
-    	$qualifiedforclean=1;
260
-	    // Check if we must keep this key to be into file for removal
261
-	    if (preg_match('/^Module\d+/', $value)) $qualifiedforclean=0;
262
-	    if (preg_match('/^Permission\d+/', $value)) $qualifiedforclean=0;
263
-	    if (preg_match('/^PermissionAdvanced\d+/', $value)) $qualifiedforclean=0;
264
-	    if (preg_match('/^ProfId\d+/', $value)) $qualifiedforclean=0;
265
-	    if (preg_match('/^Delays_/', $value)) $qualifiedforclean=0;
266
-	    if (preg_match('/^BarcodeDesc/', $value)) $qualifiedforclean=0;
267
-	    if (preg_match('/^Extrafield/', $value)) $qualifiedforclean=0;
268
-	    if (preg_match('/^LocalTax/', $value)) $qualifiedforclean=0;
269
-	    if (preg_match('/^Country/', $value)) $qualifiedforclean=0;
270
-	    if (preg_match('/^Civility/', $value)) $qualifiedforclean=0;
271
-	    if (preg_match('/^Currency/', $value)) $qualifiedforclean=0;
272
-	    if (preg_match('/^DemandReasonTypeSRC/', $value)) $qualifiedforclean=0;
273
-	    if (preg_match('/^PaperFormat/', $value)) $qualifiedforclean=0;
274
-	    if (preg_match('/^Duration/', $value)) $qualifiedforclean=0;
275
-	    if (preg_match('/^AmountLT/', $value)) $qualifiedforclean=0;
276
-	    if (preg_match('/^TotalLT/', $value)) $qualifiedforclean=0;
277
-	    if (preg_match('/^Month/', $value)) $qualifiedforclean=0;
278
-	    if (preg_match('/^MonthShort/', $value)) $qualifiedforclean=0;
279
-	    if (preg_match('/^Day\d/', $value)) $qualifiedforclean=0;
280
-	    if (preg_match('/^Short/', $value)) $qualifiedforclean=0;
281
-	    if (preg_match('/^ExportDataset_/', $value)) $qualifiedforclean=0;
282
-	    if (preg_match('/^ImportDataset_/', $value)) $qualifiedforclean=0;
283
-	    if (preg_match('/^ActionAC_/', $value)) $qualifiedforclean=0;
284
-	    if (preg_match('/^TypeLocaltax/', $value)) $qualifiedforclean=0;
285
-	    if (preg_match('/^StatusProspect/', $value)) $qualifiedforclean=0;
286
-	    if (preg_match('/^PL_/', $value)) $qualifiedforclean=0;
287
-	    if (preg_match('/^TE_/', $value)) $qualifiedforclean=0;
288
-	    if (preg_match('/^JuridicalStatus/', $value)) $qualifiedforclean=0;
289
-	    if (preg_match('/^CalcMode/', $value)) $qualifiedforclean=0;
290
-	    if (preg_match('/^newLT/', $value)) $qualifiedforclean=0;
291
-	    if (preg_match('/^LT[0-9]/', $value)) $qualifiedforclean=0;
292
-	    if (preg_match('/^TypeContact_contrat_/', $value)) $qualifiedforclean=0;
293
-	    if (preg_match('/^ErrorPriceExpression/', $value)) $qualifiedforclean=0;
294
-	    if (preg_match('/^Language_/', $value)) $qualifiedforclean=0;
295
-	    if (preg_match('/^DescADHERENT_/', $value)) $qualifiedforclean=0;
296
-	    if (preg_match('/^SubmitTranslation/', $value)) $qualifiedforclean=0;
297
-	    if (preg_match('/^ModuleCompanyCode/', $value)) $qualifiedforclean=0;
298
-	    if (preg_match('/InDolibarr$/', $value)) $qualifiedforclean=0;
299
-	    // admin.lang
300
-	    if (preg_match('/^DAV_ALLOW_PUBLIC_DIR/i', $value)) $qualifiedforclean=0;
301
-	    if (preg_match('/^DAV_ALLOW_ECM_DIR/i', $value)) $qualifiedforclean=0;
302
-	    // boxes.lang
303
-	    if (preg_match('/^BoxTitleLast/', $value)) $qualifiedforclean=0;
304
-	    if (preg_match('/^BoxTitleLatest/', $value)) $qualifiedforclean=0;
305
-	    // install.lang
306
-	    if (preg_match('/^KeepDefaultValues/', $value)) $qualifiedforclean=0;
307
-		// mail.lang
308
-	    if (preg_match('/MailingModuleDesc/i', $value)) $qualifiedforclean=0;
309
-	    // main.lang
310
-	    if (preg_match('/^Duration/', $value)) $qualifiedforclean=0;
311
-	    if (preg_match('/^FormatDate/', $value)) $qualifiedforclean=0;
312
-	    if (preg_match('/^DateFormat/', $value)) $qualifiedforclean=0;
313
-	    if (preg_match('/^.b$/', $value)) $qualifiedforclean=0;
314
-	    if (preg_match('/^.*Bytes$/', $value)) $qualifiedforclean=0;
315
-	    if (preg_match('/^NoteSomeFeaturesAreDisabled/', $value)) $qualifiedforclean=0;
316
-	    if (preg_match('/^(DoTest|Under|Limits|Cards|CurrentValue|DateLimit|DateAndHour|NbOfLines|NbOfObjects|NbOfReferes|TotalTTCShort|VATs)/', $value)) $qualifiedforclean=0;
317
-		// modulebuilder
318
-		if (preg_match('/^ModuleBuilderDesc/', $value)) $qualifiedforclean=0;
319
-	    // orders
320
-	    if (preg_match('/^OrderSource/', $value)) $qualifiedforclean=0;
321
-	    if (preg_match('/^TypeContact_/', $value)) $qualifiedforclean=0;
257
+    foreach ($langstrings_dist AS $value => $line)
258
+    {
259
+        $qualifiedforclean=1;
260
+        // Check if we must keep this key to be into file for removal
261
+        if (preg_match('/^Module\d+/', $value)) $qualifiedforclean=0;
262
+        if (preg_match('/^Permission\d+/', $value)) $qualifiedforclean=0;
263
+        if (preg_match('/^PermissionAdvanced\d+/', $value)) $qualifiedforclean=0;
264
+        if (preg_match('/^ProfId\d+/', $value)) $qualifiedforclean=0;
265
+        if (preg_match('/^Delays_/', $value)) $qualifiedforclean=0;
266
+        if (preg_match('/^BarcodeDesc/', $value)) $qualifiedforclean=0;
267
+        if (preg_match('/^Extrafield/', $value)) $qualifiedforclean=0;
268
+        if (preg_match('/^LocalTax/', $value)) $qualifiedforclean=0;
269
+        if (preg_match('/^Country/', $value)) $qualifiedforclean=0;
270
+        if (preg_match('/^Civility/', $value)) $qualifiedforclean=0;
271
+        if (preg_match('/^Currency/', $value)) $qualifiedforclean=0;
272
+        if (preg_match('/^DemandReasonTypeSRC/', $value)) $qualifiedforclean=0;
273
+        if (preg_match('/^PaperFormat/', $value)) $qualifiedforclean=0;
274
+        if (preg_match('/^Duration/', $value)) $qualifiedforclean=0;
275
+        if (preg_match('/^AmountLT/', $value)) $qualifiedforclean=0;
276
+        if (preg_match('/^TotalLT/', $value)) $qualifiedforclean=0;
277
+        if (preg_match('/^Month/', $value)) $qualifiedforclean=0;
278
+        if (preg_match('/^MonthShort/', $value)) $qualifiedforclean=0;
279
+        if (preg_match('/^Day\d/', $value)) $qualifiedforclean=0;
280
+        if (preg_match('/^Short/', $value)) $qualifiedforclean=0;
281
+        if (preg_match('/^ExportDataset_/', $value)) $qualifiedforclean=0;
282
+        if (preg_match('/^ImportDataset_/', $value)) $qualifiedforclean=0;
283
+        if (preg_match('/^ActionAC_/', $value)) $qualifiedforclean=0;
284
+        if (preg_match('/^TypeLocaltax/', $value)) $qualifiedforclean=0;
285
+        if (preg_match('/^StatusProspect/', $value)) $qualifiedforclean=0;
286
+        if (preg_match('/^PL_/', $value)) $qualifiedforclean=0;
287
+        if (preg_match('/^TE_/', $value)) $qualifiedforclean=0;
288
+        if (preg_match('/^JuridicalStatus/', $value)) $qualifiedforclean=0;
289
+        if (preg_match('/^CalcMode/', $value)) $qualifiedforclean=0;
290
+        if (preg_match('/^newLT/', $value)) $qualifiedforclean=0;
291
+        if (preg_match('/^LT[0-9]/', $value)) $qualifiedforclean=0;
292
+        if (preg_match('/^TypeContact_contrat_/', $value)) $qualifiedforclean=0;
293
+        if (preg_match('/^ErrorPriceExpression/', $value)) $qualifiedforclean=0;
294
+        if (preg_match('/^Language_/', $value)) $qualifiedforclean=0;
295
+        if (preg_match('/^DescADHERENT_/', $value)) $qualifiedforclean=0;
296
+        if (preg_match('/^SubmitTranslation/', $value)) $qualifiedforclean=0;
297
+        if (preg_match('/^ModuleCompanyCode/', $value)) $qualifiedforclean=0;
298
+        if (preg_match('/InDolibarr$/', $value)) $qualifiedforclean=0;
299
+        // admin.lang
300
+        if (preg_match('/^DAV_ALLOW_PUBLIC_DIR/i', $value)) $qualifiedforclean=0;
301
+        if (preg_match('/^DAV_ALLOW_ECM_DIR/i', $value)) $qualifiedforclean=0;
302
+        // boxes.lang
303
+        if (preg_match('/^BoxTitleLast/', $value)) $qualifiedforclean=0;
304
+        if (preg_match('/^BoxTitleLatest/', $value)) $qualifiedforclean=0;
305
+        // install.lang
306
+        if (preg_match('/^KeepDefaultValues/', $value)) $qualifiedforclean=0;
307
+        // mail.lang
308
+        if (preg_match('/MailingModuleDesc/i', $value)) $qualifiedforclean=0;
309
+        // main.lang
310
+        if (preg_match('/^Duration/', $value)) $qualifiedforclean=0;
311
+        if (preg_match('/^FormatDate/', $value)) $qualifiedforclean=0;
312
+        if (preg_match('/^DateFormat/', $value)) $qualifiedforclean=0;
313
+        if (preg_match('/^.b$/', $value)) $qualifiedforclean=0;
314
+        if (preg_match('/^.*Bytes$/', $value)) $qualifiedforclean=0;
315
+        if (preg_match('/^NoteSomeFeaturesAreDisabled/', $value)) $qualifiedforclean=0;
316
+        if (preg_match('/^(DoTest|Under|Limits|Cards|CurrentValue|DateLimit|DateAndHour|NbOfLines|NbOfObjects|NbOfReferes|TotalTTCShort|VATs)/', $value)) $qualifiedforclean=0;
317
+        // modulebuilder
318
+        if (preg_match('/^ModuleBuilderDesc/', $value)) $qualifiedforclean=0;
319
+        // orders
320
+        if (preg_match('/^OrderSource/', $value)) $qualifiedforclean=0;
321
+        if (preg_match('/^TypeContact_/', $value)) $qualifiedforclean=0;
322 322
         // other.lang
323
-	    if (preg_match('/^Notify_/', $value)) $qualifiedforclean=0;
324
-	    if (preg_match('/^PredefinedMail/', $value)) $qualifiedforclean=0;
325
-	    if (preg_match('/^DemoCompany/', $value)) $qualifiedforclean=0;
326
-	    if (preg_match('/^WeightUnit/', $value)) $qualifiedforclean=0;
327
-	    if (preg_match('/^LengthUnit/', $value)) $qualifiedforclean=0;
328
-	    if (preg_match('/^SurfaceUnit/', $value)) $qualifiedforclean=0;
329
-	    if (preg_match('/^VolumeUnit/', $value)) $qualifiedforclean=0;
330
-	    if (preg_match('/^SizeUnit/', $value)) $qualifiedforclean=0;
331
-	    if (preg_match('/^EMailText/', $value)) $qualifiedforclean=0;
332
-	    if (preg_match('/ById$/', $value)) $qualifiedforclean=0;
333
-	    if (preg_match('/ByLogin$/', $value)) $qualifiedforclean=0;
334
-	    // printing
335
-	    if (preg_match('/PrintingDriverDesc$/', $value)) $qualifiedforclean=0;
336
-	    if (preg_match('/PrintTestDesc$/', $value)) $qualifiedforclean=0;
337
-	    // products
338
-	    if (preg_match('/GlobalVariableUpdaterType$/', $value)) $qualifiedforclean=0;
339
-	    if (preg_match('/GlobalVariableUpdaterHelp$/', $value)) $qualifiedforclean=0;
340
-	    if (preg_match('/OppStatus/', $value)) $qualifiedforclean=0;
341
-	    if (preg_match('/AvailabilityType/', $value)) $qualifiedforclean=0;
342
-	    if (preg_match('/CardProduct/', $value)) $qualifiedforclean=0;
343
-
344
-	    if (preg_match('/sms/i', $value)) $qualifiedforclean=0;
345
-	    if (preg_match('/TF_/i', $value)) $qualifiedforclean=0;
346
-	    if (preg_match('/WithBankUsing/i', $value)) $qualifiedforclean=0;
347
-	    if (preg_match('/descWORKFLOW_/i', $value)) $qualifiedforclean=0;
348
-
349
-	    if (! $qualifiedforclean)
350
-	    {
323
+        if (preg_match('/^Notify_/', $value)) $qualifiedforclean=0;
324
+        if (preg_match('/^PredefinedMail/', $value)) $qualifiedforclean=0;
325
+        if (preg_match('/^DemoCompany/', $value)) $qualifiedforclean=0;
326
+        if (preg_match('/^WeightUnit/', $value)) $qualifiedforclean=0;
327
+        if (preg_match('/^LengthUnit/', $value)) $qualifiedforclean=0;
328
+        if (preg_match('/^SurfaceUnit/', $value)) $qualifiedforclean=0;
329
+        if (preg_match('/^VolumeUnit/', $value)) $qualifiedforclean=0;
330
+        if (preg_match('/^SizeUnit/', $value)) $qualifiedforclean=0;
331
+        if (preg_match('/^EMailText/', $value)) $qualifiedforclean=0;
332
+        if (preg_match('/ById$/', $value)) $qualifiedforclean=0;
333
+        if (preg_match('/ByLogin$/', $value)) $qualifiedforclean=0;
334
+        // printing
335
+        if (preg_match('/PrintingDriverDesc$/', $value)) $qualifiedforclean=0;
336
+        if (preg_match('/PrintTestDesc$/', $value)) $qualifiedforclean=0;
337
+        // products
338
+        if (preg_match('/GlobalVariableUpdaterType$/', $value)) $qualifiedforclean=0;
339
+        if (preg_match('/GlobalVariableUpdaterHelp$/', $value)) $qualifiedforclean=0;
340
+        if (preg_match('/OppStatus/', $value)) $qualifiedforclean=0;
341
+        if (preg_match('/AvailabilityType/', $value)) $qualifiedforclean=0;
342
+        if (preg_match('/CardProduct/', $value)) $qualifiedforclean=0;
343
+
344
+        if (preg_match('/sms/i', $value)) $qualifiedforclean=0;
345
+        if (preg_match('/TF_/i', $value)) $qualifiedforclean=0;
346
+        if (preg_match('/WithBankUsing/i', $value)) $qualifiedforclean=0;
347
+        if (preg_match('/descWORKFLOW_/i', $value)) $qualifiedforclean=0;
348
+
349
+        if (! $qualifiedforclean)
350
+        {
351 351
             continue;
352
-	    }
353
-
354
-	    //$search = '\'trans("'.$value.'")\'';
355
-	    $search = '-e "\''.$value.'\'" -e \'"'.$value.'"\' -e "('.$value.')" -e "('.$value.',"';
356
-		$string =  'grep -R -m 1 -F --exclude=includes/* --include=*.php '.$search.' '.$htdocs.'* '.$scripts.'*';
357
-		//print $string."<br>\n";
358
-		exec($string,$output);
359
-		if (empty($output)) {
360
-   			$unused[$value] = $line;
361
-       		echo $line;        // $trad contains the \n
362
-		}
363
-		else
364
-		{
365
-		    unset($output);
366
-		    //print 'X'.$output.'Y';
367
-		}
368
-	}
369
-
370
-	if (empty($unused)) print "No string not used found.\n";
371
-	else
372
-	{
352
+        }
353
+
354
+        //$search = '\'trans("'.$value.'")\'';
355
+        $search = '-e "\''.$value.'\'" -e \'"'.$value.'"\' -e "('.$value.')" -e "('.$value.',"';
356
+        $string =  'grep -R -m 1 -F --exclude=includes/* --include=*.php '.$search.' '.$htdocs.'* '.$scripts.'*';
357
+        //print $string."<br>\n";
358
+        exec($string,$output);
359
+        if (empty($output)) {
360
+                $unused[$value] = $line;
361
+                echo $line;        // $trad contains the \n
362
+        }
363
+        else
364
+        {
365
+            unset($output);
366
+            //print 'X'.$output.'Y';
367
+        }
368
+    }
369
+
370
+    if (empty($unused)) print "No string not used found.\n";
371
+    else
372
+    {
373 373
         $filetosave='/tmp/'.($argv[2]?$argv[2]:"").'notused.lang';
374 374
         print "Strings in en_US that are never used are saved into file ".$filetosave.":\n";
375 375
         file_put_contents($filetosave, implode("",$unused));
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
         if (($argv[2]?$argv[2]:"")) print 'cd htdocs/langs/en_US; mv '.($argv[2]?$argv[2]:"")." ".($argv[2]?$argv[2]:"").".tmp; ";
378 378
         print "diff ".($argv[2]?$argv[2]:"").".tmp ".$filetosave." | grep \< | cut  -b 3- > ".($argv[2]?$argv[2]:"");
379 379
         if (($argv[2]?$argv[2]:"")) print "; rm ".($argv[2]?$argv[2]:"").".tmp;\n";
380
-	}
380
+    }
381 381
 }
382 382
 
383 383
 echo "\n";
Please login to merge, or discard this patch.
dolibarr/dev/translation/autotranslator.class.php 1 patch
Indentation   +299 added lines, -299 removed lines patch added patch discarded remove patch
@@ -27,17 +27,17 @@  discard block
 block discarded – undo
27 27
  */
28 28
 class autoTranslator
29 29
 {
30
-	private $_translatedFiles = array();
31
-	private $_destlang = '';
32
-	private $_refLang = '';
33
-	private $_langDir = '';
34
-	private $_limittofile = '';
35
-	private $_time;
36
-	private $_time_end;
37
-	private $_outputpagecode = 'UTF-8';
38
-	private $_apikey;
39
-	//private $_outputpagecode = 'ISO-8859-1';
40
-	const DIR_SEPARATOR = '/';
30
+    private $_translatedFiles = array();
31
+    private $_destlang = '';
32
+    private $_refLang = '';
33
+    private $_langDir = '';
34
+    private $_limittofile = '';
35
+    private $_time;
36
+    private $_time_end;
37
+    private $_outputpagecode = 'UTF-8';
38
+    private $_apikey;
39
+    //private $_outputpagecode = 'ISO-8859-1';
40
+    const DIR_SEPARATOR = '/';
41 41
 
42 42
 
43 43
     /**
@@ -53,296 +53,296 @@  discard block
 block discarded – undo
53 53
     function __construct($_destlang,$_refLang,$_langDir,$_limittofile,$_apikey)
54 54
     {
55 55
 
56
-		// Set enviorment variables
57
-		$this->_destlang = $_destlang;
58
-		$this->_refLang = $_refLang;
59
-		$this->_langDir = $_langDir.self::DIR_SEPARATOR;
60
-		$this->_time = date('Y-m-d H:i:s');
61
-		$this->_limittofile = $_limittofile;
56
+        // Set enviorment variables
57
+        $this->_destlang = $_destlang;
58
+        $this->_refLang = $_refLang;
59
+        $this->_langDir = $_langDir.self::DIR_SEPARATOR;
60
+        $this->_time = date('Y-m-d H:i:s');
61
+        $this->_limittofile = $_limittofile;
62 62
         $this->_apikey = $_apikey;
63 63
 
64
-		// Translate
65
-		//ini_set('default_charset','UTF-8');
66
-		ini_set('default_charset',$this->_outputpagecode);
67
-		$this->parseRefLangTranslationFiles();
68
-	}
69
-
70
-	/**
71
-	 * 	Parse file
72
-	 *
73
-	 * 	@return	void
74
-	 */
75
-	private function parseRefLangTranslationFiles()
76
-	{
77
-
78
-		$files = $this->getTranslationFilesArray($this->_refLang);
79
-		$counter = 1;
80
-		foreach($files as $file)
81
-		{
82
-			if ($this->_limittofile && $this->_limittofile != $file) continue;
83
-			$counter++;
84
-			$fileContent = null;
85
-			$refPath = $this->_langDir.$this->_refLang.self::DIR_SEPARATOR.$file;
86
-			$fileContent = file($refPath,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
87
-			print "Processing file " . $file . ", with ".count($fileContent)." lines<br>\n";
88
-
89
-			// Define target dirs
90
-			$targetlangs=array($this->_destlang);
91
-			if ($this->_destlang == 'all')
92
-			{
93
-				$targetlangs=array();
94
-
95
-				// If we must process all languages
96
-				$arraytmp=dol_dir_list($this->_langDir,'directories',0);
97
-				foreach($arraytmp as $dirtmp)
98
-				{
99
-					if ($dirtmp['name'] === $this->_refLang) continue;	// We discard source language
100
-					$tmppart=explode('_',$dirtmp['name']);
101
-					if (preg_match('/^en/i',$dirtmp['name']))  continue;	// We discard en_* languages
102
-					if (preg_match('/^fr/i',$dirtmp['name']))  continue;	// We discard fr_* languages
103
-					if (preg_match('/^es/i',$dirtmp['name']))  continue;	// We discard es_* languages
104
-					if (preg_match('/ca_ES/i',$dirtmp['name']))  continue;	// We discard es_CA language
105
-					if (preg_match('/pt_BR/i',$dirtmp['name']))  continue;	// We discard pt_BR language
64
+        // Translate
65
+        //ini_set('default_charset','UTF-8');
66
+        ini_set('default_charset',$this->_outputpagecode);
67
+        $this->parseRefLangTranslationFiles();
68
+    }
69
+
70
+    /**
71
+     * 	Parse file
72
+     *
73
+     * 	@return	void
74
+     */
75
+    private function parseRefLangTranslationFiles()
76
+    {
77
+
78
+        $files = $this->getTranslationFilesArray($this->_refLang);
79
+        $counter = 1;
80
+        foreach($files as $file)
81
+        {
82
+            if ($this->_limittofile && $this->_limittofile != $file) continue;
83
+            $counter++;
84
+            $fileContent = null;
85
+            $refPath = $this->_langDir.$this->_refLang.self::DIR_SEPARATOR.$file;
86
+            $fileContent = file($refPath,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
87
+            print "Processing file " . $file . ", with ".count($fileContent)." lines<br>\n";
88
+
89
+            // Define target dirs
90
+            $targetlangs=array($this->_destlang);
91
+            if ($this->_destlang == 'all')
92
+            {
93
+                $targetlangs=array();
94
+
95
+                // If we must process all languages
96
+                $arraytmp=dol_dir_list($this->_langDir,'directories',0);
97
+                foreach($arraytmp as $dirtmp)
98
+                {
99
+                    if ($dirtmp['name'] === $this->_refLang) continue;	// We discard source language
100
+                    $tmppart=explode('_',$dirtmp['name']);
101
+                    if (preg_match('/^en/i',$dirtmp['name']))  continue;	// We discard en_* languages
102
+                    if (preg_match('/^fr/i',$dirtmp['name']))  continue;	// We discard fr_* languages
103
+                    if (preg_match('/^es/i',$dirtmp['name']))  continue;	// We discard es_* languages
104
+                    if (preg_match('/ca_ES/i',$dirtmp['name']))  continue;	// We discard es_CA language
105
+                    if (preg_match('/pt_BR/i',$dirtmp['name']))  continue;	// We discard pt_BR language
106 106
                     if (preg_match('/nl_BE/i',$dirtmp['name']))  continue;  // We discard nl_BE language
107
-					if (preg_match('/^\./i',$dirtmp['name']))  continue;	// We discard files .*
108
-					if (preg_match('/^CVS/i',$dirtmp['name']))  continue;	// We discard CVS
109
-					$targetlangs[]=$dirtmp['name'];
110
-				}
111
-				//var_dump($targetlangs);
112
-			}
113
-
114
-			// Process translation of source file for each target languages
115
-			foreach($targetlangs as $my_destlang)
116
-			{
117
-				$this->_translatedFiles = array();
118
-
119
-				$destPath = $this->_langDir.$my_destlang.self::DIR_SEPARATOR.$file;
120
-				// Check destination file presence
121
-				if (! file_exists($destPath))
122
-				{
123
-					// No file present, we generate file
124
-					echo "File not found: " . $destPath . ". We generate it.<br>\n";
125
-					$this->createTranslationFile($destPath,$my_destlang);
126
-				}
127
-				else
128
-				{
129
-					echo "Updating file: " . $destPath . "<br>\n";
130
-				}
131
-
132
-				// Translate lines
133
-				$fileContentDest = file($destPath,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
134
-				$newlines=0;
135
-				foreach($fileContent as $line){
136
-					$key = $this->getLineKey($line);
137
-					$value = $this->getLineValue($line);
138
-					if ($key && $value)
139
-					{
140
-						$newlines+=$this->translateFileLine($fileContentDest,$file,$key,$value,$my_destlang);
141
-					}
142
-				}
143
-
144
-				$this->updateTranslationFile($destPath,$file,$my_destlang);
145
-				echo "New translated lines: " . $newlines . "<br>\n";
146
-				//if ($counter ==3) die('fim');
147
-			}
148
-		}
149
-	}
150
-
151
-	/**
152
-	 * Update file with new translations
153
-	 *
154
-	 * @param 	string	$destPath		Target path
155
-	 * @param 	string	$file			File
156
-	 * @param 	string	$my_destlang		Target language code
157
-	 * @return	void
158
-	 */
159
-	private function updateTranslationFile($destPath,$file,$my_destlang)
160
-	{
161
-		$this->_time_end = date('Y-m-d H:i:s');
162
-
163
-		if (isset($this->_translatedFiles[$file]) && count($this->_translatedFiles[$file])>0)
164
-		{
165
-			$fp = fopen($destPath, 'a');
166
-			fwrite($fp, "\n");
167
-			fwrite($fp, "\n");
168
-			fwrite($fp, "// START - Lines generated via autotranslator.php tool (".$this->_time.").\n");
169
-			fwrite($fp, "// Reference language: ".$this->_refLang." -> ".$my_destlang."\n");
170
-			foreach( $this->_translatedFiles[$file] as $line) {
171
-				fwrite($fp, $line . "\n");
172
-			}
173
-			fwrite($fp, "// STOP - Lines generated via autotranslator.php tool (".$this->_time_end.").\n");
174
-			fclose($fp);
175
-		}
176
-		return;
177
-	}
178
-
179
-	/**
180
-	 * Create a new translation file
181
-	 *
182
-	 * @param 	string	$path			Path
183
-	 * @param 	string	$my_destlang		Target language code
184
-	 * @return	void
185
-	 */
186
-	private function createTranslationFile($path,$my_destlang)
187
-	{
188
-		$fp = fopen($path, 'w+');
189
-		fwrite($fp, "/*\n");
190
-		fwrite($fp, " * Language code: {$my_destlang}\n");
191
-		fwrite($fp, " * Automatic generated via autotranslator.php tool\n");
192
-		fwrite($fp, " * Generation date " . $this->_time. "\n");
193
-		fwrite($fp, " */\n");
194
-		fclose($fp);
195
-		return;
196
-	}
197
-
198
-	/**
199
-	 * Put in array _translatedFiles[$file], line of a new tranlated pair
200
-	 *
201
-	 * @param 	string	$content		Existing content of dest file
202
-	 * @param 	string	$file			Target file name translated (xxxx.lang)
203
-	 * @param 	string	$key			Key to translate
204
-	 * @param 	string	$value			Existing value in source file
205
-	 * @param	string	$my_destlang	Language code (ie: fr_FR)
206
-	 * @return	int						0=Nothing translated, 1=Record translated
207
-	 */
208
-	private function translateFileLine($content,$file,$key,$value,$my_destlang)
209
-	{
210
-
211
-		//print "key    =".$key."\n";
212
-		foreach( $content as $line ) {
213
-			$destKey = $this->getLineKey($line);
214
-			$destValue = $this->getLineValue($line);
215
-			// If translated return
216
-			//print "destKey=".$destKey."\n";
217
-			if ( trim($destKey) == trim($key) )
218
-			{	// Found already existing translation (key already exits in dest file)
219
-				return 0;
220
-			}
221
-		}
222
-
223
-		if ($key == 'CHARSET') $val=$this->_outputpagecode;
224
-		else if (preg_match('/^Format/',$key)) $val=$value;
225
-		else if ($value=='-') $val=$value;
226
-		else
227
-		{
228
-			// If not translated then translate
229
-			if ($this->_outputpagecode == 'UTF-8') $val=$this->translateTexts(array($value),substr($this->_refLang,0,2),substr($my_destlang,0,2));
230
-			else $val=utf8_decode($this->translateTexts(array($value),substr($this->_refLang,0,2),substr($my_destlang,0,2)));
231
-		}
232
-
233
-		$val=trim($val);
234
-
235
-		if (empty($val)) return 0;
236
-
237
-		$this->_translatedFiles[$file][] = $key . '=' . $val ;
238
-		return 1;
239
-	}
240
-
241
-	/**
242
-	 * getLineKey
243
-	 *
244
-	 * @param 	string 	$line	Line found into file
245
-	 * @return	string	Key
246
-	 */
247
-	private function getLineKey($line)
248
-	{
249
-		$arraykey = explode('=',$line,2);
250
-		return trim($arraykey[0]);
251
-	}
252
-
253
-	/**
254
-	 * getLineValue
255
-	 *
256
-	 * @param 	string 	$line	Line found into file
257
-	 * @return	string	Value
258
-	 */
259
-	private function getLineValue($line)
260
-	{
261
-		$arraykey = explode('=',$line,2);
262
-		return trim(isset($arraykey[1])?$arraykey[1]:'');
263
-	}
264
-
265
-	/**
266
-	 * getTranslationFilesArray
267
-	 *
268
-	 * @param 	string 	$lang	Language code
269
-	 * @return	array	Array
270
-	 */
271
-	private function getTranslationFilesArray($lang)
272
-	{
273
-		$dir = new DirectoryIterator($this->_langDir.$lang);
274
-		while($dir->valid()) {
275
-			if(!$dir->isDot() && $dir->isFile() && ! preg_match('/^\./',$dir->getFilename())) {
276
-				$files[] =  $dir->getFilename();
277
-			}
278
-			$dir->next();
279
-		}
280
-		return $files;
281
-	}
282
-
283
-	/**
284
-	 * Return translation of a value
285
-	 *
286
-	 * @param 	array	$src_texts		Array with one value
287
-	 * @param 	string	$src_lang		Language code source (us, fr, it, ...)
288
-	 * @param 	string	$dest_lang		Language code target (es, de, ...)
289
-	 * @return 	string					Value translated
290
-	 */
291
-	private function translateTexts($src_texts, $src_lang, $dest_lang)
292
-	{
293
-		// We want to be sure that src_lang and dest_lang are using 2 chars only
294
-		$tmp=explode('_',$src_lang);
295
-		if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) $src_lang=$tmp[0];
296
-		$tmp=explode('_',$dest_lang);
297
-		if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) $dest_lang=$tmp[0];
298
-
299
-		//setting language pair
300
-		$lang_pair = $src_lang.'|'.$dest_lang;
301
-
302
-		$src_text_to_translate=preg_replace('/%s/','SSSSS',implode('',$src_texts));
303
-		$src_text_to_translate=preg_replace('/'.preg_quote('\n\n').'/',' NNNNN ',$src_text_to_translate);
304
-
305
-		// Define GET URL v1
306
-		//$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".urlencode($src_text_to_translate)."&langpair=".urlencode($lang_pair);
307
-		// Example: http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=Setup%20area&langpair=en_US|fr_FR
107
+                    if (preg_match('/^\./i',$dirtmp['name']))  continue;	// We discard files .*
108
+                    if (preg_match('/^CVS/i',$dirtmp['name']))  continue;	// We discard CVS
109
+                    $targetlangs[]=$dirtmp['name'];
110
+                }
111
+                //var_dump($targetlangs);
112
+            }
113
+
114
+            // Process translation of source file for each target languages
115
+            foreach($targetlangs as $my_destlang)
116
+            {
117
+                $this->_translatedFiles = array();
118
+
119
+                $destPath = $this->_langDir.$my_destlang.self::DIR_SEPARATOR.$file;
120
+                // Check destination file presence
121
+                if (! file_exists($destPath))
122
+                {
123
+                    // No file present, we generate file
124
+                    echo "File not found: " . $destPath . ". We generate it.<br>\n";
125
+                    $this->createTranslationFile($destPath,$my_destlang);
126
+                }
127
+                else
128
+                {
129
+                    echo "Updating file: " . $destPath . "<br>\n";
130
+                }
131
+
132
+                // Translate lines
133
+                $fileContentDest = file($destPath,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
134
+                $newlines=0;
135
+                foreach($fileContent as $line){
136
+                    $key = $this->getLineKey($line);
137
+                    $value = $this->getLineValue($line);
138
+                    if ($key && $value)
139
+                    {
140
+                        $newlines+=$this->translateFileLine($fileContentDest,$file,$key,$value,$my_destlang);
141
+                    }
142
+                }
143
+
144
+                $this->updateTranslationFile($destPath,$file,$my_destlang);
145
+                echo "New translated lines: " . $newlines . "<br>\n";
146
+                //if ($counter ==3) die('fim');
147
+            }
148
+        }
149
+    }
150
+
151
+    /**
152
+     * Update file with new translations
153
+     *
154
+     * @param 	string	$destPath		Target path
155
+     * @param 	string	$file			File
156
+     * @param 	string	$my_destlang		Target language code
157
+     * @return	void
158
+     */
159
+    private function updateTranslationFile($destPath,$file,$my_destlang)
160
+    {
161
+        $this->_time_end = date('Y-m-d H:i:s');
162
+
163
+        if (isset($this->_translatedFiles[$file]) && count($this->_translatedFiles[$file])>0)
164
+        {
165
+            $fp = fopen($destPath, 'a');
166
+            fwrite($fp, "\n");
167
+            fwrite($fp, "\n");
168
+            fwrite($fp, "// START - Lines generated via autotranslator.php tool (".$this->_time.").\n");
169
+            fwrite($fp, "// Reference language: ".$this->_refLang." -> ".$my_destlang."\n");
170
+            foreach( $this->_translatedFiles[$file] as $line) {
171
+                fwrite($fp, $line . "\n");
172
+            }
173
+            fwrite($fp, "// STOP - Lines generated via autotranslator.php tool (".$this->_time_end.").\n");
174
+            fclose($fp);
175
+        }
176
+        return;
177
+    }
178
+
179
+    /**
180
+     * Create a new translation file
181
+     *
182
+     * @param 	string	$path			Path
183
+     * @param 	string	$my_destlang		Target language code
184
+     * @return	void
185
+     */
186
+    private function createTranslationFile($path,$my_destlang)
187
+    {
188
+        $fp = fopen($path, 'w+');
189
+        fwrite($fp, "/*\n");
190
+        fwrite($fp, " * Language code: {$my_destlang}\n");
191
+        fwrite($fp, " * Automatic generated via autotranslator.php tool\n");
192
+        fwrite($fp, " * Generation date " . $this->_time. "\n");
193
+        fwrite($fp, " */\n");
194
+        fclose($fp);
195
+        return;
196
+    }
197
+
198
+    /**
199
+     * Put in array _translatedFiles[$file], line of a new tranlated pair
200
+     *
201
+     * @param 	string	$content		Existing content of dest file
202
+     * @param 	string	$file			Target file name translated (xxxx.lang)
203
+     * @param 	string	$key			Key to translate
204
+     * @param 	string	$value			Existing value in source file
205
+     * @param	string	$my_destlang	Language code (ie: fr_FR)
206
+     * @return	int						0=Nothing translated, 1=Record translated
207
+     */
208
+    private function translateFileLine($content,$file,$key,$value,$my_destlang)
209
+    {
210
+
211
+        //print "key    =".$key."\n";
212
+        foreach( $content as $line ) {
213
+            $destKey = $this->getLineKey($line);
214
+            $destValue = $this->getLineValue($line);
215
+            // If translated return
216
+            //print "destKey=".$destKey."\n";
217
+            if ( trim($destKey) == trim($key) )
218
+            {	// Found already existing translation (key already exits in dest file)
219
+                return 0;
220
+            }
221
+        }
222
+
223
+        if ($key == 'CHARSET') $val=$this->_outputpagecode;
224
+        else if (preg_match('/^Format/',$key)) $val=$value;
225
+        else if ($value=='-') $val=$value;
226
+        else
227
+        {
228
+            // If not translated then translate
229
+            if ($this->_outputpagecode == 'UTF-8') $val=$this->translateTexts(array($value),substr($this->_refLang,0,2),substr($my_destlang,0,2));
230
+            else $val=utf8_decode($this->translateTexts(array($value),substr($this->_refLang,0,2),substr($my_destlang,0,2)));
231
+        }
232
+
233
+        $val=trim($val);
234
+
235
+        if (empty($val)) return 0;
236
+
237
+        $this->_translatedFiles[$file][] = $key . '=' . $val ;
238
+        return 1;
239
+    }
240
+
241
+    /**
242
+     * getLineKey
243
+     *
244
+     * @param 	string 	$line	Line found into file
245
+     * @return	string	Key
246
+     */
247
+    private function getLineKey($line)
248
+    {
249
+        $arraykey = explode('=',$line,2);
250
+        return trim($arraykey[0]);
251
+    }
252
+
253
+    /**
254
+     * getLineValue
255
+     *
256
+     * @param 	string 	$line	Line found into file
257
+     * @return	string	Value
258
+     */
259
+    private function getLineValue($line)
260
+    {
261
+        $arraykey = explode('=',$line,2);
262
+        return trim(isset($arraykey[1])?$arraykey[1]:'');
263
+    }
264
+
265
+    /**
266
+     * getTranslationFilesArray
267
+     *
268
+     * @param 	string 	$lang	Language code
269
+     * @return	array	Array
270
+     */
271
+    private function getTranslationFilesArray($lang)
272
+    {
273
+        $dir = new DirectoryIterator($this->_langDir.$lang);
274
+        while($dir->valid()) {
275
+            if(!$dir->isDot() && $dir->isFile() && ! preg_match('/^\./',$dir->getFilename())) {
276
+                $files[] =  $dir->getFilename();
277
+            }
278
+            $dir->next();
279
+        }
280
+        return $files;
281
+    }
282
+
283
+    /**
284
+     * Return translation of a value
285
+     *
286
+     * @param 	array	$src_texts		Array with one value
287
+     * @param 	string	$src_lang		Language code source (us, fr, it, ...)
288
+     * @param 	string	$dest_lang		Language code target (es, de, ...)
289
+     * @return 	string					Value translated
290
+     */
291
+    private function translateTexts($src_texts, $src_lang, $dest_lang)
292
+    {
293
+        // We want to be sure that src_lang and dest_lang are using 2 chars only
294
+        $tmp=explode('_',$src_lang);
295
+        if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) $src_lang=$tmp[0];
296
+        $tmp=explode('_',$dest_lang);
297
+        if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) $dest_lang=$tmp[0];
298
+
299
+        //setting language pair
300
+        $lang_pair = $src_lang.'|'.$dest_lang;
301
+
302
+        $src_text_to_translate=preg_replace('/%s/','SSSSS',implode('',$src_texts));
303
+        $src_text_to_translate=preg_replace('/'.preg_quote('\n\n').'/',' NNNNN ',$src_text_to_translate);
304
+
305
+        // Define GET URL v1
306
+        //$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".urlencode($src_text_to_translate)."&langpair=".urlencode($lang_pair);
307
+        // Example: http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=Setup%20area&langpair=en_US|fr_FR
308 308
         // Define GET URL v2
309
-		$url = "https://www.googleapis.com/language/translate/v2?key=".$this->_apikey."&q=".urlencode($src_text_to_translate)."&source=".urlencode($src_lang)."&target=".urlencode($dest_lang);
310
-		// Example: https://www.googleapis.com/language/translate/v2?key=_apikey&q=Setup%20area&source=en_US&target=fr_FR
311
-
312
-		// Send request
313
-		//print "Url to translate: ".$url."\n";
314
-
315
-		if (! function_exists("curl_init"))
316
-		{
317
-		      print "Error, your PHP does not support curl functions.\n";
318
-		      die();
319
-		}
320
-
321
-		$ch = curl_init();
322
-		curl_setopt($ch, CURLOPT_URL, $url);
323
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
324
-		curl_setopt($ch, CURLOPT_REFERER, "Mozilla");
325
-		$body = curl_exec($ch);
326
-		curl_close($ch);
327
-		//sleep(1);	// This is to avoid to overload server.
328
-
329
-		// now, process the JSON string
330
-		$json = json_decode($body, true);
331
-
332
-		if ((! empty($json['responseStatus']) && $json['responseStatus'] != 200)
333
-		|| count($json['data']['translations']) == 0)
334
-		{
335
-		    print "Error: ".$json['responseStatus']." ".$url."\n";
336
-			return false;
337
-		}
338
-
339
-		$rep=$json['data']['translations'][0]['translatedText'];
340
-		$rep=preg_replace('/SSSSS/i','%s',$rep);
341
-		$rep=preg_replace('/NNNNN/i','\n\n',$rep);
342
-		$rep=preg_replace('/&#39;/i','\'',$rep);
343
-
344
-		//print "OK ".join('',$src_texts).' => '.$rep."\n";
345
-
346
-		return $rep;
347
-	}
309
+        $url = "https://www.googleapis.com/language/translate/v2?key=".$this->_apikey."&q=".urlencode($src_text_to_translate)."&source=".urlencode($src_lang)."&target=".urlencode($dest_lang);
310
+        // Example: https://www.googleapis.com/language/translate/v2?key=_apikey&q=Setup%20area&source=en_US&target=fr_FR
311
+
312
+        // Send request
313
+        //print "Url to translate: ".$url."\n";
314
+
315
+        if (! function_exists("curl_init"))
316
+        {
317
+                print "Error, your PHP does not support curl functions.\n";
318
+                die();
319
+        }
320
+
321
+        $ch = curl_init();
322
+        curl_setopt($ch, CURLOPT_URL, $url);
323
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
324
+        curl_setopt($ch, CURLOPT_REFERER, "Mozilla");
325
+        $body = curl_exec($ch);
326
+        curl_close($ch);
327
+        //sleep(1);	// This is to avoid to overload server.
328
+
329
+        // now, process the JSON string
330
+        $json = json_decode($body, true);
331
+
332
+        if ((! empty($json['responseStatus']) && $json['responseStatus'] != 200)
333
+        || count($json['data']['translations']) == 0)
334
+        {
335
+            print "Error: ".$json['responseStatus']." ".$url."\n";
336
+            return false;
337
+        }
338
+
339
+        $rep=$json['data']['translations'][0]['translatedText'];
340
+        $rep=preg_replace('/SSSSS/i','%s',$rep);
341
+        $rep=preg_replace('/NNNNN/i','\n\n',$rep);
342
+        $rep=preg_replace('/&#39;/i','\'',$rep);
343
+
344
+        //print "OK ".join('',$src_texts).' => '.$rep."\n";
345
+
346
+        return $rep;
347
+    }
348 348
 }
Please login to merge, or discard this patch.
dolibarr/dev/initdemo/sftpget_and_loaddump.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Test if batch mode
27 27
 if (substr($sapi_type, 0, 3) == 'cgi') {
28
-	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
29
-	exit;
28
+    echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
29
+    exit;
30 30
 }
31 31
 
32 32
 // Global variables
@@ -60,17 +60,17 @@  discard block
 block discarded – undo
60 60
 $server='';
61 61
 if (preg_match('/^(.*)@(.*):(.*)$/',$sourceserver,$reg))
62 62
 {
63
-	$login=$reg[1];
64
-	$server=$reg[2];
65
-	$sourcefile=$reg[3];
66
-	$targetfile=basename($sourcefile);
63
+    $login=$reg[1];
64
+    $server=$reg[2];
65
+    $sourcefile=$reg[3];
66
+    $targetfile=basename($sourcefile);
67 67
 }
68 68
 if (empty($sourceserver) || empty($server) || empty($login) || empty($sourcefile) || empty($password) || empty($database) || empty($loginbase) || empty($passwordbase))
69 69
 {
70
-	print "Usage: $script_file login@server:/src/file.(sql|gz|bz2) passssh databaseserver databasename loginbase passbase\n";
71
-	print "Return code: 0 if success, <>0 if error\n";
72
-	print "Warning, this script may take a long time.\n";
73
-	exit(-1);
70
+    print "Usage: $script_file login@server:/src/file.(sql|gz|bz2) passssh databaseserver databasename loginbase passbase\n";
71
+    print "Return code: 0 if success, <>0 if error\n";
72
+    print "Warning, this script may take a long time.\n";
73
+    exit(-1);
74 74
 }
75 75
 
76 76
 
@@ -84,21 +84,21 @@  discard block
 block discarded – undo
84 84
 
85 85
 // SFTP connect
86 86
 if (! function_exists("ssh2_connect")) {
87
-	dol_print_error('','ssh2_connect function does not exists'); exit(1);
87
+    dol_print_error('','ssh2_connect function does not exists'); exit(1);
88 88
 }
89 89
 
90 90
 $connection = ssh2_connect($server, 22);
91 91
 if ($connection)
92 92
 {
93
-	if (! @ssh2_auth_password($connection, $login, $password))
94
-	{
95
-		dol_syslog("Could not authenticate with username ".$login." . and password ".preg_replace('/./', '*', $password),LOG_ERR);
96
-		exit(-5);
97
-	}
98
-	else
99
-	{
100
-		//$stream = ssh2_exec($connection, '/usr/bin/php -i');
101
-		/*
93
+    if (! @ssh2_auth_password($connection, $login, $password))
94
+    {
95
+        dol_syslog("Could not authenticate with username ".$login." . and password ".preg_replace('/./', '*', $password),LOG_ERR);
96
+        exit(-5);
97
+    }
98
+    else
99
+    {
100
+        //$stream = ssh2_exec($connection, '/usr/bin/php -i');
101
+        /*
102 102
 		print "Generate dump ".$filesys1.'.bz2'."\n";
103 103
 			$stream = ssh2_exec($connection, "mysqldump -u debian-sys-maint -p4k9Blxl2snq4FHXY -h 127.0.0.1 --single-transaction -K --tables -c -e --hex-blob --default-character-set=utf8 saasplex | bzip2 -1 > ".$filesys1.'.bz2');
104 104
 			stream_set_blocking($stream, true);
@@ -106,35 +106,35 @@  discard block
 block discarded – undo
106 106
 			$output = stream_get_contents($stream);
107 107
 		*/
108 108
 
109
-		$sftp = ssh2_sftp($connection);
110
-
111
-		print 'Get file '.$sourcefile.' into '.$targetdir.$targetfile."\n";
112
-		ssh2_scp_recv($connection, $sourcefile, $targetdir.$targetfile);
113
-
114
-		$fullcommand="cat ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
115
-		if (preg_match('/\.bz2$/',$targetfile))
116
-		{
117
-			$fullcommand="bzip2 -c -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
118
-		}
119
-		if (preg_match('/\.gz$/',$targetfile))
120
-		{
121
-			$fullcommand="gzip -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
122
-		}
123
-		print "Load dump with ".$fullcommand."\n";
124
-		$output=array();
125
-		$return_var=0;
126
-		print strftime("%Y%m%d-%H%M%S").' '.$fullcommand."\n";
127
-		exec($fullcommand, $output, $return_var);
128
-		foreach($output as $line) print $line."\n";
129
-
130
-		//ssh2_sftp_unlink($sftp, $fileinstalllock);
131
-		//print $output;
132
-	}
109
+        $sftp = ssh2_sftp($connection);
110
+
111
+        print 'Get file '.$sourcefile.' into '.$targetdir.$targetfile."\n";
112
+        ssh2_scp_recv($connection, $sourcefile, $targetdir.$targetfile);
113
+
114
+        $fullcommand="cat ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
115
+        if (preg_match('/\.bz2$/',$targetfile))
116
+        {
117
+            $fullcommand="bzip2 -c -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
118
+        }
119
+        if (preg_match('/\.gz$/',$targetfile))
120
+        {
121
+            $fullcommand="gzip -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
122
+        }
123
+        print "Load dump with ".$fullcommand."\n";
124
+        $output=array();
125
+        $return_var=0;
126
+        print strftime("%Y%m%d-%H%M%S").' '.$fullcommand."\n";
127
+        exec($fullcommand, $output, $return_var);
128
+        foreach($output as $line) print $line."\n";
129
+
130
+        //ssh2_sftp_unlink($sftp, $fileinstalllock);
131
+        //print $output;
132
+    }
133 133
 }
134 134
 else
135 135
 {
136
-	print 'Failed to connect to ssh2 to '.$server;
137
-	exit(-6);
136
+    print 'Failed to connect to ssh2 to '.$server;
137
+    exit(-6);
138 138
 }
139 139
 
140 140
 
Please login to merge, or discard this patch.