我想知道如何在 PHP 脚本中实现多种语言。我真的找不到任何方便的方法来说明如何做这样的事情以使翻译变得容易。我举个例子:
//Output looks like this:
//Where are You, Mike? It is me, Rebeca! I am waiting here for 5 hours!
//But in file it is some abomination like:
echo 'Where are You, '.$name.'? It is me, '.$name2.'! I am waiting here for '.$time.' hours!';
//Just imagine that meantime there might be different functions, included files
//and other code required to create more sentences like the above to create long text...
如果文件输出这样的文本被许多不同的变量和代码打碎,那么语言文件应该是什么样子的?
我想到将用户语言保存在 $_SESSION['lang'] 中,并在每个文件中包含具有正确语言的文件。但是在我尝试这样做之后,它确实看起来像这样:
//main file
echo $txt[1].$name.$txt[2].$name2.$txt[3].$time.$txt[3];
//lang file
$txt[1] = 'Where are You, ';
$txt[2] = '? It is me, ';
$txt[3] = '! I am waiting here for ';
$txt[3] = ' hours!';
它看起来很可笑,不可读,并且有很多潜在的错误。试想一下,如果您是只能访问 lang 文件的翻译人员——不可能翻译这样的文本,对吧?这应该/可以如何以不同的方式完成?
慕丝7291255