这是一个简单的方法来翻译你的网站使用PHP。这个想法是为你想要提供的每一种语言准备好几个文件。这些文件中的每一个都有ISO代码和txt扩展名。在这个演示中,我只使用德语作为网站默认语言的替代语言——英语。这些文件的内容是用他们的翻译形式写的单词和句子:
word=translation
所提供的PHP类将解析这个文件,创建一个映射两个单词和它的翻译对的数组。您只需要在php代码中插入以下内容:
$translate = new Translator($outputlanguage);
//$outputlanguage: ISO code (example: de,en,...) --> these are the names of each file
$translate->__('word to translate');
举个例子:
<?php $translate->__('Registration'); ?>
在您的txt文件中,我们将拥有:
Registration=Registrierung