So, I'm not sure if this has been done before. I have just installed a PHP application on my server and I want to translate the site.
The application uses a language_name.php file for each language. Each language file contains a multi-dimensional array $_LANG
.
$_LANG
keys range from one level, $_LANG['l1'] = "string";
to about 5 levels, $_LANG['l1']['l2']['l3']['l4']['l5'] = "string";
WHAT I WANT TO ATTEMPT
To create nested foreach loops to loop through and echo the $key
- $value
pairs.
After which I will write a translation function to translate the values before the echo..
THE PROBLEM
The original file contains more than 3,750 lines.
My echoed version only contains 3,387.
<?php
$_LANG['lang']['vars']['go'];
$_LANG['at']['the'];
$_LANG['top'];,
foreach ($_LANG as $key => $value) {
if (is_array($value)) {
foreach ($value as $key1 => $value1) {
if (is_array($value1)) {
foreach ($value1 as $key2 => $value2) {
if (is_array($value2)) {
foreach ($value2 as $key3 => $value3) {
if (is_array($value3)) {
foreach ($value3 as $key4 => $value4) {
if (is_array($value4)) {
foreach ($value4 as $key5 => $value5) {
echo '$_LANG[\''.$key.'\'][\''.$key1.'\'][\''.$key2.'\'][\''.$key3.'\'][\''.$key4.'\'][\''.$key5.'\'] = "'.$value5.'";'.'<br>';
}
}
else {
echo '$_LANG[\''.$key.'\'][\''.$key1.'\'][\''.$key2.'\'][\''.$key3.'\'][\''.$key4.'\'] = "'.$value4.'";'.'<br>';
}
}
}
else {
echo '$_LANG[\''.$key.'\'][\''.$key1.'\'][\''.$key2.'\'][\''.$key3.'\'] = "'.$value3.'";'.'<br>';
}
}
}
else {
echo '$_LANG[\''.$key.'\'][\''.$key1.'\'][\''.$key2.'\'] = "'.$value2.'";'.'<br>';
}
}
}
else {
echo '$_LANG[\''.$key.'\'][\''.$key1.'\'] = "'.$value1.'";'.'<br>';
}
}
}
else {
echo '$_LANG[\''.$key.'\'] = "'.$value.'";'.'<br>';
}
}
?>