Skip to content

Commit

Permalink
$LANG strings insertion script added
Browse files Browse the repository at this point in the history
Usage: http://si.domain.tld/lang/lang_insert.php?l=tr_TR
to get the lang.php file for Turkish.
Edit output to update Date of update and manually translate
and update the translation status flag at the end of each line
  • Loading branch information
apmuthu committed Oct 18, 2013
1 parent 391c18b commit b0588c6
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions lang/lang_insert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/* **************
// Purpose: To insert untranslated strings into language file
// and arrange the non title_* keys in alphabetical order
// Author : Ap.Muthu
// Release: 2013-10-18
//
// Usage : http://si_domain.com/lang/lang_insert.php?l=vi_VN
// The Source HTML would be the raw text for the lang.php file
*/

$lang_cmp = (isset($_REQUEST['l']) ? trim($_REQUEST['l']) : false);

if ($lang_cmp === false) die('No language given');

// $lang_cmp = "nb_NO";

include "en_GB/lang.php";
$LANG_en = $LANG;

unset($LANG);

$preamble = '';
$nl = chr(10);

include "$lang_cmp/lang.php";

$h = fopen("$lang_cmp/lang.php", "r");
while ($line = fgets($h)) {
if ((substr($line, 0, 6) != '$LANG[') && (substr($line, 0, 2) !='?>')) {
$preamble .= $line;
// } elseif ((substr($line, 0, 6) == '$LANG[') && (substr($line, -5) == '";//0')) {
} elseif ( (!(preg_match('/^\$LANG\[.*;\s*\/\/\s*1/', $line)))
&& (preg_match('/^\$LANG\[.*;\s*\/\/\s*0/', $line)) ) {
// Untranslated strings in lang file
$ukeyarr = explode("'", $line, 3);
$ukey = $ukeyarr[1];
unset($ukeyarr);
unset($LANG[$ukey]);
}
}

foreach ($LANG_en AS $k => $v) {
if (! isset($LANG[$k])) {
// Untranslated String
$LANG[$k][0] = $v;
$LANG[$k][1] = 0;
} else {
// Translated String
$v = $LANG[$k];
unset($LANG[$k]);
$LANG[$k][0] = $v;
$LANG[$k][1] = 1;
}
}

$LANG_gen = Array();
$LANG_title = Array();
foreach ($LANG as $k => $v) {
$basestr = '$LANG[' . "'" . $k ."'" . '] = "' . $v[0] . '";//' . $v[1];
if (substr($k, 0, 5) == 'title') $LANG_title[$k] = $basestr;
else $LANG_gen[$k] = $basestr;
}

ksort($LANG_gen);

echo $preamble;

foreach ($LANG_gen as $v) echo $v . $nl;
echo $nl;
foreach ($LANG_title as $v) echo $v . $nl;

echo $nl;
echo '?>';
echo $nl;

?>

0 comments on commit b0588c6

Please sign in to comment.