如何将翻译写入文件

时间:2014-07-14 04:17:59

标签: php content-management-system prestashop

我想让我的网站多语言化。我在prestashop等软件包中看到,翻译保存到这样的文件中:

<?php
$_lang['contact_header_steps']      = "Order whatever you like in 4 easy steps";
$_lang['contact_steps_1']           = "Fill out the form";
$_lang['contact_steps_2']           = "We will send you a payment link";
$_lang['contact_steps_3']           = "Pay online";
$_lang['contact_steps_3a']          = "";
?>

所以这就是我所做的。我使用smarty并在我的模板中使用(例子):{$ LANG.contact_header_steps}

我使用全局检测将选定的语言存储在cookie中,以便我的网站知道要显示的语言。

一切正常,但现在我想构建一个简单的管理系统。

我想从admin(没有DB)写入此文件(如上所述)。我已经在prestashop中看到了这一点,但在查看核心后我才迷失了。

所以当我打开翻译页面时,它必须读取此文件并创建2个输入字段。当我保存它必须保存到此文件

最好的方法是什么?

1 个答案:

答案 0 :(得分:0)

为每种语言提供一个&#39;代码名称&#39;例如:英语:en;法国:fr;等

假设您将语言存储在Cookie $ _COOKIE中[&#39; lang&#39;]

<?php
    $mylang = $_COOKIE['lang'];     //get the cookie

    //define the translation here
    $_lang['en']['contact_header_steps'] = "Order whatever you like in 4 easy steps";
    $_lang['en']['contact_steps_1']      = "Fill out the form";
    $_lang['en']['contact_steps_2']      = "We will send you a payment link";
    $_lang['en']['contact_steps_3']      = "Pay online";
    $_lang['en']['contact_steps_3a']     = "";

    $_lang['fr']['contact_header_steps'] = "OTHER_LANG";
    $_lang['fr']['contact_steps_1']      = "THAT_I";
    $_lang['fr']['contact_steps_2']      = "HAVE_NO";
    $_lang['fr']['contact_steps_3']      = "IDEA_OF";
    $_lang['fr']['contact_steps_3a']     = "HERE";

    echo $_lang[$mylang]['contact_header_steps']; //use it to call the language

?>