I want to put inside an already existing ARRAY the information of a text file.TXT with PHP
The idea and do the translation of a system in PHP, where each key of the ARRAY is a translation.
Manually I have already managed to pull out all the keys and translate them, separating each translated key into a line, putting them all in a text file.txt, now I want to put these already translated lines inside the ARRAY as value, automatically pulling from the text file.txt
Ex:
<?php
$lang["CHAVE"] ="VALOR";
?>
Part of the code is this:
<?php
$lang["Signup"] ="";
$lang["Sign In"] ="";
$lang['Login Successful'] ='';
?>
Has to stay like this:
<?php
$lang["Signup"] ="Inscrição";
$lang["Sign In"] ="Entrar";
$lang['Login Successful'] ="Login com êxito";
?:>
This file has more than 2600 lines, all in this pattern, so I want to automate this work, it has more files like this to do.
I noticed that there are still many scripts in PHP that use this form of translation, it would be interesting to put together a script to do this automated work.
Text file.txt
Inscrição
Entrar
Login com êxito
1 answers
Although I understand it to be a lousy logic to propose the question, I think this solves the Question:
$lang = ['Signup', 'Sign in', 'Login successfull'];
foreach ($lang as $key => $value) {
$txt = trim(fgets($file_handle))
$lang[$key] = $txt;
}
Note that I omitted the opening / closing code of the text file (which can be done by fopen()
and fclose()
.
I also assumed that the text file has no blank lines at the beginning and middle of translations.