![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
[php]
<?php
function i18n_file_array($fa, $fname = "", $lan = "zh-cn", $postfix = ".ihtml") {
if (!is_array($fa)) {
if (trim($fname) == "") {
return false;
}
else {
$file_array[$fa] = $fname . "_" . $lan . $postfix;
}
}
else {
while (list($key, $value) = each($fa)) {
$file_array[$key] = $value . "_" . $lan . $postfix;
}
}
return $file_array;
}
?>
[/php]
说明:针对用模版开发的PHP i18n应用,通过选择不同的*.ihtml文档实现 i18n 。
该函数与PHPLib的Template模版配合使用,在使用$template->set_file() 方法之前,使用该函数将文件句柄数组转换为对应的i18n HTML文档数组。
使用举例:
[php]
<?php
require_once("phplib/template.inc");
require_once("mylib/i18n.inc"); //包含i18n_file_array函数的文件
$t = new template();
$fa["fh_index"] = "index";
$fa["fh_left"] = "left";
$fa["fh_navigate"] = "navigate";
$fa["fh_main"] = "main";
$fa = i18n_file_array($fa);
$t->set_file($fa);
......
?>
[/php]

