php gettext
安装gettext:
ubuntu: apt-get install php-gettext, apt-get install gettext
window:开启扩展 修改locale :
$ /usr/share/i18n/locales //查看支持的语言
$ vi /etc/locale.gen //开启语言
$ locale-gen //是新设置的locale 生效
$ locale -a 查看目前支持的语言
example: test.php:
<?php
str='home';
xgettext -a test.php -o test.pot
exportLANG=zh_CN.utf8
msginit -l zh_CN.utf8 -i test.pot
生成了相应的zh_CN.po文件


将这两个文件,移动到对应的文件夹中
var/www/test/locale/LC_MESSAGES
index.php $lang = 'tw';
putenv('LANG=zh_TW');
setlocale(LC_ALL, 'zh_TW'); $lang = isset($_GET['lang']) ? $_GET['lang'] : 'tw'; if ('tw' == $lang) {
putenv('LANG=zh_TW');
setlocale(LC_ALL, 'zh_TW'); // bsd use zh_TW.UTF-8
} else if ('cn' == $lang) {
putenv('LANG=zh_CN');
setlocale(LC_ALL, 'zh_CN'); // bsd use zh_CN.UTF-8
} else if ('en' == $lang) {
putenv('LANG=en_US');
setlocale(LC_ALL, 'en_US');
} define('PACKAGE', 'hello'); // package其实是.mo文件的文件名称,比如是zj.mo那么我们写的时候只需要些(PACKAGE:zj) // gettext setting
bindtextdomain(PACKAGE, 'locale'); // or $your_path/locale, ex: /var/www/test/locale
textdomain(PACKAGE);//sets default domain ××我在这里栽了一个跟头,.mo的文件名称要和项目包的名称一样,这样才可以, // main program
echo gettext("Hello World!");
echo '<br>';
echo _("This is book.");
echo '<br>';
echo _("Hello World!");
1、string gettext ( string $message )
looks up a message in the current domain
2、bool putenv ( string $setting )
Setting certain environment variables may be a potential security breach
3、string setlocale ( int $category , string $locale [, string $... ] )
string setlocale ( int $category , array $locale ) set locale information
php gettext的更多相关文章
- jQuery的getText()方法源码
/** * Utility function for retrieving the text value of an array of DOM nodes * @param {Array|Elemen ...
- php gettext 多语言翻译
1.在window与linux下的多语言切换有些区别,主要putenv的设置区别. 参考链接:http://www.cnblogs.com/sink_cup/archive/2013/11/20/ub ...
- php gettext 注释
//setlocale(LC_ALL, "en_US.UTF-8"); setlocale(LC_ALL, "zh_CN.UTF-8"); bindtextdo ...
- 已解决:Ubuntu php gettext 无效
使用gettext做多文字国际化,按PHP官方文档,在CentOS上OK,在Ubuntu上不行,调试了快1天,试了网上提供的无数方法,终于有一个OK了…… 看到此文的同学别再被坑了…… 感谢:http ...
- Selenium2学习-013-WebUI自动化实战实例-011-WebElement.getText()值为空问题探索及解决
今天有个朋友在群里问 WebElement.getText() 值为空,当你发现取到的值为空的时候,会不会郁闷呢?明明看到的值不为空,脚本看着也没有问题啊,为何取到的值为空呢!!!万千纠结啊,若是长时 ...
- Python本地化例子 - gettext 模块
关键字:Python 3.4,gettext,本地化,Localization OS:Windows 7,Mac 1. 创建一个locsample.py文件,文件内容如下,把所有需要本地化的字符串放到 ...
- ActionSupport.getText()方法 以及 js中:<s:text name="" />
下面略述com.opensymphony.xwork2.ActionSupport.getText()方法 public String getText(String aTextName) 说明:Get ...
- c#开发之多国语言解决方案gnu.gettext + poedit
1.工具简介 1.1.关于i18n i18n其来源是英文单词 internationalization的首末字符i和n,18为中间的字符数是“国际化”的简称. i10n为资源本地化,全称为Locali ...
- 转 delphi SelText,GetText,SetText用法
转自:http://blog.163.com/wll_009/blog/static/1173731172009102452632968/ 这几个都跟选区有关的,就是选中一串字符串,选中的会变蓝色Se ...
- CharSequence的getText()与String的getString()(转)
CharSequence的getText()与String的getString()『Android系列七』 曾经在学习中碰见两种获取常量的方式: CharSequence chrs = getText ...
随机推荐
- ubuntu如何实现双屏显示
转载自https://blog.csdn.net/tianmaxingkong_/article/details/50570538
- Python3字符编码
编码 字符串是一种数据类型,但是,字符串比较特殊的是还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字节 ...
- MySQL5.7的安装(CentOS 7 & Ubuntu 16.04)
CentOS 通过 yum 安装MySQL5.7 Yum Repository 下载地址:https://dev.mysql.com/downloads/repo/yum/ 选择相应的版本进行下载:R ...
- java正则表达式(字符串)
参考:http://blog.csdn.net/kdnuggets/article/details/2526588 补充: ?号的使用: ^/branch/([a-z]+[/]?)$ 可以匹配 /b ...
- Flex 排序 SortField and Sort
部分代码 var arrayOfCat:ArrayCollection=outerDocument.getCagegory(); // 需要排序的数组 //创建SortField对象 var so ...
- 【Redis】Redis-benchmark测试Redis性能
Redis-benchmark是官方自带的Redis性能测试工具,可以有效的测试Redis服务的性能. 使用说明如下: Usage: redis-benchmark [-h <host>] ...
- 【Web】移动端下拉刷新、上拉加载更多插件
移动网站中常常有的功能:列表的下拉刷新.上拉加载更多 本例介绍一种简单使用的移动端下拉刷新.上拉加载更多插件,下载及参考地址:https://github.com/ximan/dropload 插件依 ...
- Reading CLR via c# 4th Edition
In fact, at runtime, the CLR has no idea which programming language the developer used for thesource ...
- c++中的log函数
引入#include<cmath> 以e为底:log(exp(n)) 以10为底:log10(n) 以m为底:log(n)/log(m)
- php中 isset函数有什么功能
isset是判断一个变量是否定义过即使它没有值,返回值也是true比如$name="";或var $name;那么if(isset($name))echo 1;它也会输出1,因为$ ...