这篇文章主要为大家详细介绍了PHP中使用gettext来支持多语言的方法的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编小韵来看看吧!
我们今天用一个简单的实例说明一下在PHP中的getText的用法(getText是一系列的工具和库函数,帮助程序员和翻译人员开发多语言软件的), 从而实现PHP的i18n.代码如下:
//home.php:
$str = 'home';
print <<<HTML
<a href="#">{$str}</a>
HTML;
代码如下:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-07-23 20:56+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: home.php:2
msgid "home"
msgstr "
代码如下:
# Chinese translations for PACKAGE package
# PACKAGE 软件包的简体中文翻译.
# Copyright (C) 2009 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# <huixinchen@localhost.localdomain>, 2009.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-07-23 20:56+0800\n"
"PO-Revision-Date: 2009-07-23 21:00+0800\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: Chinese\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=GB2312\n"
"Content-Transfer-Encoding: 8bit\n"
#: test.php:2
msgid "home"
msgstr "
代码如下:
# Chinese translations for PACKAGE package
# PACKAGE 软件包的简体中文翻译.
# Copyright (C) 2009 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# <huixinchen@localhost.localdomain>, 2009.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-07-23 20:56+0800\n"
"PO-Revision-Date: 2009-07-23 21:00+0800\n"
"Last-Translator: <huixinchen@localhost.localdomain>\n"
"Language-Team: Chinese\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=GB2312\n"
"Content-Transfer-Encoding: 8bit\n"
#: test.php:2
msgid "home"
msgstr "主页
代码如下:
setlocale(LC_ALL, 'zh_CN');
// Specify location of translation tables
bindtextdomain("home", ".");
// Choose domain
textdomain("home");
// Translation is looking for in ./locale/zh_CN/LC_MESSAGES/home.mo now
$str = gettext('home'); //也可以使用_('home')
print <<<HTML
<a href="#">{$str}</a>
HTML;
本文来自:http://www.q1010.com/173/13025-0.html
注:关于PHP中使用gettext来支持多语言的方法的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。