如何用php设置3种语言? [英] How to set 3 languages with php?
本文介绍了如何用php设置3种语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在现有页面中插入第三种语言,但已经用法语和英语写过了. 我是php的初学者.
I try to insert a third language in an existing page wich is already in french and english. I'm kind of beginner with php.
代码如下:
<?php
$lang = (isset($_GET['lang']) && $_GET['lang'] == 'en') ? 'en' : 'fr' ;
$langParam = ($lang == 'en') ? '&lang=en' : '';
$typeTerms = array(
'fr' => array(
'WINES' => 'vins',
'BEERS' => 'Bières',
'MALTCOOLER' => 'boisson à base de malt',
'CIDER' => 'cidres',
'ALCOHOLFREE' => 'produits sans alcool<br/>et à faible teneur en alcool',
'OTHERS' => 'autres'
),
'en' => array(
'WINES' => 'Wines',
'BEERS' => 'Beers',
'MALTCOOLER' => 'Malt Based Cooler',
'CIDER' => 'Cider',
'ALCOHOLFREE' => 'Alcohol-free and low-alcoholic products',
'OTHERS' => 'Others'
)
);
?>
我想插入此数组并使它工作!
And I want to insert this array, and make it work!
'zh' => array(
'WINES' => '葡萄酒',
'BEERS' => '啤酒',
'MALTCOOLER' => '麦芽果酒',
'CIDER' => '苹果酒',
'ALCOHOLFREE' => '无酒精及低度酒精饮料',
'OTHERS' => '其它'
)
谢谢!
推荐答案
只是
$lang = isset($_GET['lang'])?$_GET['lang']:"en";
if(!in_array($lang,array("en","fr","zh"))) $lang = "en";
要添加一个新的
$typeTerms['zh'] = array(
'WINES' => '葡萄酒',
'BEERS' => '啤酒',
'MALTCOOLER' => '麦芽果酒',
'CIDER' => '苹果酒',
'ALCOHOLFREE' => '无酒精及低度酒精饮料',
'OTHERS' => '其它'
);
这篇关于如何用php设置3种语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文