Translate array values write to file php
I have a google language translate PHP class you can see here
My array file like this:
$lang['FORUM_LOCK'] = 'Lock';
$lang['FORUM_EDIT'] = 'Edit';
$lang['FORUM开发者_如何转开发_POST'] ='Post';
...
I want to loop through and translate all array values and write to file. I tried all kinds of methods but cant figure it out :(
Im sure someone has done this before?
You may want to use a foreach
construct to iterate through all values of $lang
.
Something like this :
$lang_fr = array();
foreach($lang as $key => $val) {
$lang_fr = $gt->translate($val , "en", "fr");
}
You can write then it to a PHP file using fwrite()
using the same construct :
fwrite($fp, "\$lang_fr['$key'] ='$val';\n");
Be wary of specials characters though. You may want to use addslashes()
.
Try to extend Google Translate class:
class ExtendedTranslate extends GoogleTranslateWrapper {
public function translateArray($array, $fromLanguage, $toLanguage) {
foreach ($array as &$item) {
$item = $this->translate($item, $fromLanguage, $toLanguage);
}
return array();
}
}
精彩评论