open flash chart 教程翻译(2)——数据文件

1 数据文件放在哪

除了在URL里添加数据的地址,ofc也有一个名为"data-file"的变量,可以在HTML里的JavaScript里设置:

<html>
<head>
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF(
  "open-flash-chart.swf", "my_chart", "550", "200",
  "9.0.0", "expressInstall.swf",
  {"data-file":"chart-3.php"}
  );
</script>

<p>Hello World</p>
<div id="my_chart"></div>

要实现上例的效果,必须要有swfobject,获取更多关于swfobject的信息,请参考swfobject documentation.

注意

  • URL里面不需要再写"ofc=".
  • 当你要在一个页面里显示多个chart时,这种方法尤为有用.

这一篇就这么多,下一篇讲如何利用现有的库生成所需的数据文件.

原文地址:http://teethgrinder.co.uk/open-flash-chart-2/tutorial-3.php

<div id="my_chart"></div>

open flash chart 教程翻译(3)——生成数据文件(PHP篇)

1 生成JSON文件

如何使用PHP库生成JSON文件:

<?php

include '../php-ofc-library/open-flash-chart.php';

// generate some random data
srand((double)microtime()*1000000);

$max = 20;
$tmp = array();
for( $i=0; $i<9; $i++ )
{
  $tmp[] = rand(0,$max);
}

$title = new title( date("D M d Y") );

$bar = new bar();
$bar->set_values( array(1,2,3,4,5,6,7,8,9) );

$chart = new open_flash_chart();
$chart->set_title( $title );
$chart->add_element( $bar );

echo $chart->toString();

?>

Open Flash Chart 图表教程之一

今天在群里有位朋友发来一个开源的flash图表程序,自己研究了一下感觉不错,特自己翻译官方教程帮助一些想用该图表的朋友. very very easy Let’s go!!
它的工作原理
:
在这个教程里,我们将在你的站点里尝试并且得到以下的类似图表

1:配置Open-Flash-Chart
开始之前,我们必须先下载一个Open Flash Chart 压缩文件. Click Down

解压.zip文件,在version-2文件夹里的把open-flash-chart.swf复制到你的站点根目录

你可以把所有文件移到你的站点上任何目录下,但为了保持本教程的完整和简单,现在不必移动全部文件到站点里.当你学完这个教程并且例子代码都能运行时,可 以把文件移到到你指定的目录下.如果例子运行出错,你应该清楚知道你移动过的文件并且修改相关的文件路径引用

2:代码:
现在让我们开始编写代码!
新建一个HTML文件,我们将运行一个”Hello World”例子.复制下面的代码到文件里,并保存文件名为”chart.html”在站点根目录:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Open Flash Chart</title>
  5. </head>
  6. <body>
  7. <p>Hello World</p>
  8. <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
  9. codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
  10. width="500" height="250" id="graph-2" align="middle">
  11. <param name="allowScriptAccess" value="sameDomain" />
  12. <param name="movie" value="open-flash-chart.swf" />
  13. <param name="quality" value="high" />
  14. <embed src="open-flash-chart.swf" quality="high" bgcolor="#FFFFFF" width="500" height="250" name="open-flash-chart" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
  15. </object>
  16. </body>
  17. </html>

现在打开浏览这个页面
Open Flash Chart会查找图表数据源,但是我们没有创建数据文件,所以它不能找到数据源并且给出一个错误信息.正如你所看到的:

<object>和<embed>标签来告诉浏览器来显示一个Flash影片.只要Open Flash Chart 影片名在这两个标签里,浏览器就能下载并且显示它.
(声明:之所以我们使用这两个标签是因为只适用于IE浏览器而其他浏览器使用其他标签)
3:数据源
下一步我们需要提供一些数据.Open Flash Chart读取的是JSON数据,如果你从未听过JSON,不必担心它很简单易学.JSON是一种数据格式的命名,这里有一个简单的JSON图表数据:

  1. {
  2. "title":{
  3. "text": "Yedeer sale lines",
  4. "style": "{font-size: 20px; color:#0000ff; font-family: Verdana; text-align: center;}"
  5. },
  6. "y_legend":{
  7. "text": "Yedeer Chart",
  8. "style": "{color: #736AFF; font-size: 12px;}"
  9. },
  10. "elements":[
  11. {
  12. "type": "bar_glass",
  13. "alpha": 0.8,
  14. "colour": "#9933CC",
  15. "text": "Page views",
  16. "font-size": 10,
  17. "values" :   [9,6,7,9,5,7,6,9,7]
  18. },
  19. {
  20. "type": "bar_glass",
  21. "alpha": 0.8,
  22. "colour": "#CC9933",
  23. "text": "Page views 2",
  24. "font-size": 10,
  25. "values" :   [6,7,9,5,7,6,9,7,3]
  26. }
  27. ],
  28. "x_axis":{
  29. "stroke":1,
  30. "tick_height":10,
  31. "colour":"#d000d0",
  32. "grid_colour":"#00ff00",
  33. "labels": ["January","February","March","April","May","June","July","August","Spetember"]
  34. },
  35. "y_axis":{
  36. "stroke": 4,
  37. "tick_length": 3,
  38. "colour": "#d000d0",
  39. "grid_colour": "#00ff00",
  40. "offset": 0,
  41. "max": 15
  42. }
  43. }

JSON数据不应该手工输入(稍后我们让后台程序来完成JSON数据生成),这很容易输错.
下一步,我们将上面的JSON数据复制到文件里并保存到根目录命名为”data.json”
Open Flash Chart 能以URL的get形式获取数据源,它的变量是”ofc”值为JSON数据源的名字.现在你的数据文件保存在根目录名为data.json
在浏览你的网页,仍然会提示出错.你只要在网页后添加参数?ofc=data.json
你将看到:

4.祝贺
你成功了!
你编辑刚才data.json文件,另存为’data-2.json’,修改里面"values" : [9,6,7,9,5,7,6,9,7]内的数值来改变显示.里面数据改变后浏览一下(http://example.com/chart.html?ofc=data-2.json)注意ofc变量参数为data-2.json.手工更改JSON内容是很容易输错的方法,另一种方法是在教程3里我们将用PHP的类库来生成JSON格式文件
5.后记
注意:
*ofc变量不单只有它一个参数还可以有多个其他变量参数
如: http://example.com/chart.html?x=1&ofc=data.json&y=2 都能正常执行
*你可以把JSON文件保存到站点下任何目录并且要用完整路径指定ofc变量
如: http://example.com/chart.html?ofc=../stuff/../data.json
*路径和文件名必须是URL编码.当你输入URL时,没有按URL编码会出现问题
回顾一下刚才我们所做的:
1. 在站点根目录里创建一个chart.html文件
2. chart.html内的Flash两个标签和复制一个Open Flash Chart 的应用程序(open-flash-chart.swf)到根目录
3. 创建Open Flash Chart 所需的JSON数据文件
4. Open Flash Chart 读取JSON数据文件,显示相应的图表(?ofc=data.json)

你应该做出来了!觉得如何?好的话我就继续为剩余教程继续编译!

Linux 指令篇:工作行程资讯与管理--ps

名称:ps
使用权限:所有使用者
使用方式:ps [options] [--help]
说明:显示瞬间行程 (process) 的动态
参数:
ps 的参数非常多, 在此仅列出几个常用的参数并大略介绍含义
-A 列出所有的行程
-w 显示加宽可以显示较多的资讯
-au 显示较详细的资讯
-aux 显示所有包含其他使用者的行程

au(x) 输出格式 :

USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
USER:   行程拥有者
PID:    pid
%CPU:   占用的 CPU 使用率
%MEM:   占用的记忆体使用率
VSZ:    占用的虚拟记忆体大小
RSS:    占用的记忆体大小
TTY:    终端的次要装置号码 (minor device number of tty)
STAT:   该行程的状态:
D:  不可中断的静止 (通悸□□缜b进行 I/O 动作)
R:  正在执行中
S:  静止状态
T:  暂停执行
Z:  不存在但暂时无法消除
W:  没有足够的记忆体分页可分配
<:  高优先序的行程
N:  低优先序的行程
L:  有记忆体分页分配并锁在记忆体内 (实时系统或捱A I/O)
START:  行程开始时间
TIME:   执行的时间
COMMAND:所执行的指令

范例:

ps
PID TTY          TIME CMD
2791 ttyp0    00:00:00 tcsh
3092 ttyp0    00:00:00 ps
% ps -A
PID TTY          TIME CMD
1 ?        00:00:03 init
2 ?        00:00:00 kflushd
3 ?        00:00:00 kpiod
4 ?        00:00:00 kswapd
5 ?        00:00:00 mdrecoveryd
.......
% ps -aux
USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.7  1096  472 ?        S    Sep10   0:03 init [3]
root         2  0.0  0.0     0    0 ?        SW   Sep10   0:00 [kflushd]
root         3  0.0  0.0     0    0 ?        SW   Sep10   0:00 [kpiod]
root         4  0.0  0.0     0    0 ?        SW   Sep10   0:00 [kswapd]
........
(http://www.fanqiang.com) 进入【UNIX论坛

UNIX操作命令 第六章 Mail命令

6.1 发送或接受电子邮件
命令:mail/Mail/mailx
格式:mail username (发送)
mail [option] (接受)
功能:向网上用户发送或接受电子邮件。
选项:-r 邮件按先进先出顺序排序。缺省时为后进先出顺序排序
-q 中断mail后不改变信箱内容
-p 显示mail每份邮件,不显示提示信息
-f 从邮件格式文件中读邮件
注释:mail命令:
? 显示mail帮助命令
h 邮件标题列表
p 显示当前邮件
n 显示下一邮件
r [uers] 给发信人或用户回信
s [file] 将邮件保存到文件中,保存标题信息
w [file] 将邮件写到文件中,不保存标题信息
d [n] 删除当前邮件或第n封邮件
q 将未删除的邮件存入mbox文件,并退出mail
x 所有邮件不作修改,退出mail
例如:% mail -s "Subjet ..." username < messages

6.2 显示邮件队列
命令:mailq
格式:mailq
功能:查看正在发送或接收邮件的排队情况。
选项:
注释:此命令一般在系统或网络不同时使用。
例如:% mailq

6.3 邮件操作命令
命令:pine
格式:pine
功能:对自己邮件操作的程序。
选项:
注释:此操作是在菜单提示下进行。
例如:% pine

ports装php5-extensions出错 "t1lib_target Error 1"

T1_AA_TYPE16=short -DT1_AA_TYPE32=int t1x11.c  -fPIC -DPIC -o .libs/t1x11.o
t1x11.c:41:22: X11/Xlib.h: No such file or directory
t1x11.c:42:23: X11/Xutil.h: No such file or directory
In file included from t1x11.c:60:
t1x11.h:32: error: syntax error before '*' token
t1x11.h:36: error: syntax error before "d"
t1x11.h:39: error: syntax error before "d"
t1x11.h:43: error: syntax error before "d"
t1x11.h:47: error: syntax error before "d"
t1x11.h:50: error: syntax error before "d"
t1x11.h:54: error: syntax error before "d"
t1x11.h:61: error: syntax error before "drawable"
t1x11.c:78: error: syntax error before '*' token
t1x11.c:78: warning: data definition has no type or storage class
t1x11.c:79: error: syntax error before '*' token
t1x11.c:79: warning: data definition has no type or storage class
t1x11.c:80: error: syntax error before "T1_colormap"
t1x11.c:80: warning: data definition has no type or storage class
t1x11.c:94: error: syntax error before "aacolors"
t1x11.c:94: warning: data definition has no type or storage class
t1x11.c:108: error: syntax error before '*' token
t1x11.c: In function `T1_SetX11Params':
t1x11.c:114: error: `display' undeclared (first use in this function)
t1x11.c:114: error: (Each undeclared identifier is reported only once
t1x11.c:114: error: for each function it appears in.)
t1x11.c:115: error: `visual' undeclared (first use in this function)
t1x11.c:116: error: `depth' undeclared (first use in this function)
t1x11.c:117: error: `colormap' undeclared (first use in this function)
t1x11.c: At top level:
t1x11.c:142: error: syntax error before "d"
t1x11.c: In function `T1_SetCharX':
t1x11.c:150: error: syntax error before "clipmask"
t1x11.c:163: error: `mode' undeclared (first use in this function)
t1x11.c:166: error: `FontID' undeclared (first use in this function)
t1x11.c:166: error: `charcode' undeclared (first use in this function)
t1x11.c:166: error: `size' undeclared (first use in this function)
t1x11.c:166: error: `transform' undeclared (first use in this function)
t1x11.c:183: error: `clipmask' undeclared (first use in this function)
t1x11.c:184: error: `d' undeclared (first use in this function)
t1x11.c:192: error: `x_dest' undeclared (first use in this function)
t1x11.c:193: error: `y_dest' undeclared (first use in this function)
t1x11.c:197: error: `gc' undeclared (first use in this function)
t1x11.c:207: error: `None' undeclared (first use in this function)
t1x11.c: At top level:
t1x11.c:228: error: syntax error before "d"
t1x11.c: In function `T1_SetStringX':
t1x11.c:237: error: syntax error before "clipmask"
t1x11.c:250: error: `mode' undeclared (first use in this function)
t1x11.c:253: error: `FontID' undeclared (first use in this function)
t1x11.c:253: error: `string' undeclared (first use in this function)
t1x11.c:253: error: `len' undeclared (first use in this function)
t1x11.c:254: error: `spaceoff' undeclared (first use in this function)
t1x11.c:254: error: `modflag' undeclared (first use in this function)
t1x11.c:254: error: `size' undeclared (first use in this function)
t1x11.c:255: error: `transform' undeclared (first use in this function)
t1x11.c:271: error: `clipmask' undeclared (first use in this function)
t1x11.c:272: error: `d' undeclared (first use in this function)
t1x11.c:280: error: `x_dest' undeclared (first use in this function)
t1x11.c:281: error: `y_dest' undeclared (first use in this function)
t1x11.c:285: error: `gc' undeclared (first use in this function)
t1x11.c:295: error: `None' undeclared (first use in this function)
t1x11.c: At top level:
t1x11.c:316: error: syntax error before "d"
t1x11.c: In function `T1_SetRectX':
t1x11.c:325: error: syntax error before "clipmask"
t1x11.c:338: error: `mode' undeclared (first use in this function)
t1x11.c:341: error: `FontID' undeclared (first use in this function)
t1x11.c:341: error: `size' undeclared (first use in this function)
t1x11.c:341: error: `rwidth' undeclared (first use in this function)
t1x11.c:341: error: `rheight' undeclared (first use in this function)
t1x11.c:341: error: `transform' undeclared (first use in this function)
t1x11.c:358: error: `clipmask' undeclared (first use in this function)
t1x11.c:359: error: `d' undeclared (first use in this function)
t1x11.c:367: error: `x_dest' undeclared (first use in this function)
t1x11.c:368: error: `y_dest' undeclared (first use in this function)
t1x11.c:372: error: `gc' undeclared (first use in this function)
t1x11.c:382: error: `None' undeclared (first use in this function)
t1x11.c: At top level:
t1x11.c:404: error: syntax error before "d"
t1x11.c: In function `T1_AASetCharX':
t1x11.c:411: error: `XImage' undeclared (first use in this function)
t1x11.c:411: error: `ximage' undeclared (first use in this function)
t1x11.c:417: error: syntax error before "xgcvalues"
t1x11.c:420: error: syntax error before "clipmask"
t1x11.c:437: error: `mode' undeclared (first use in this function)
t1x11.c:443: error: `gc' undeclared (first use in this function)
t1x11.c:443: error: `GCForeground' undeclared (first use in this function)
t1x11.c:443: error: `GCBackground' undeclared (first use in this function)
t1x11.c:443: error: `xgcvalues' undeclared (first use in this function)
t1x11.c:453: error: `size' undeclared (first use in this function)
t1x11.c:505: error: `FontID' undeclared (first use in this function)
t1x11.c:505: error: `charcode' undeclared (first use in this function)
t1x11.c:506: error: `transform' undeclared (first use in this function)
t1x11.c:525: error: `x_dest' undeclared (first use in this function)
t1x11.c:526: error: `y_dest' undeclared (first use in this function)
t1x11.c:564: error: `clipmask' undeclared (first use in this function)
t1x11.c:565: error: `d' undeclared (first use in this function)
t1x11.c:578: error: `ZPixmap' undeclared (first use in this function)
t1x11.c:602: error: `None' undeclared (first use in this function)
t1x11.c: At top level:
t1x11.c:623: error: syntax error before "d"
t1x11.c: In function `T1_AASetStringX':
t1x11.c:631: error: `XImage' undeclared (first use in this function)
t1x11.c:631: error: `ximage' undeclared (first use in this function)
t1x11.c:638: error: syntax error before "xgcvalues"
t1x11.c:642: error: syntax error before "clipmask"
t1x11.c:658: error: `mode' undeclared (first use in this function)
t1x11.c:663: error: `gc' undeclared (first use in this function)
t1x11.c:663: error: `GCForeground' undeclared (first use in this function)
t1x11.c:663: error: `GCBackground' undeclared (first use in this function)
t1x11.c:663: error: `xgcvalues' undeclared (first use in this function)
t1x11.c:674: error: `size' undeclared (first use in this function)
t1x11.c:727: error: `FontID' undeclared (first use in this function)
t1x11.c:727: error: `string' undeclared (first use in this function)
t1x11.c:727: error: `len' undeclared (first use in this function)
t1x11.c:728: error: `spaceoff' undeclared (first use in this function)
t1x11.c:728: error: `modflag' undeclared (first use in this function)
t1x11.c:729: error: `transform' undeclared (first use in this function)
t1x11.c:748: error: `x_dest' undeclared (first use in this function)
t1x11.c:749: error: `y_dest' undeclared (first use in this function)
t1x11.c:787: error: `clipmask' undeclared (first use in this function)
t1x11.c:788: error: `d' undeclared (first use in this function)
t1x11.c:801: error: `ZPixmap' undeclared (first use in this function)
t1x11.c:825: error: `None' undeclared (first use in this function)
t1x11.c: At top level:
t1x11.c:846: error: syntax error before "d"
t1x11.c: In function `T1_AASetRectX':
t1x11.c:854: error: `XImage' undeclared (first use in this function)
t1x11.c:854: error: `ximage' undeclared (first use in this function)
t1x11.c:860: error: syntax error before "xgcvalues"
t1x11.c:863: error: syntax error before "clipmask"
t1x11.c:880: error: `mode' undeclared (first use in this function)
t1x11.c:886: error: `gc' undeclared (first use in this function)
t1x11.c:886: error: `GCForeground' undeclared (first use in this function)
t1x11.c:886: error: `GCBackground' undeclared (first use in this function)
t1x11.c:886: error: `xgcvalues' undeclared (first use in this function)
t1x11.c:896: error: `size' undeclared (first use in this function)
t1x11.c:948: error: `FontID' undeclared (first use in this function)
t1x11.c:948: error: `rwidth' undeclared (first use in this function)
t1x11.c:948: error: `rheight' undeclared (first use in this function)
t1x11.c:948: error: `transform' undeclared (first use in this function)
t1x11.c:967: error: `x_dest' undeclared (first use in this function)
t1x11.c:968: error: `y_dest' undeclared (first use in this function)
t1x11.c:1006: error: `clipmask' undeclared (first use in this function)
t1x11.c:1007: error: `d' undeclared (first use in this function)
t1x11.c:1020: error: `ZPixmap' undeclared (first use in this function)
t1x11.c:1044: error: `None' undeclared (first use in this function)
t1x11.c: In function `T1_ComputeAAColorsX':
t1x11.c:1076: error: request for member `pixel' in something not a structure or union
t1x11.c:1077: error: request for member `pixel' in something not a structure or union
t1x11.c:1085: error: request for member `red' in something not a structure or union
t1x11.c:1085: error: request for member `red' in something not a structure or union
t1x11.c:1086: error: request for member `green' in something not a structure or union
t1x11.c:1086: error: request for member `green' in something not a structure or union
t1x11.c:1087: error: request for member `blue' in something not a structure or union
t1x11.c:1087: error: request for member `blue' in something not a structure or union
t1x11.c:1088: error: request for member `pixel' in something not a structure or union
t1x11.c:1089: error: request for member `pixel' in something not a structure or union
t1x11.c:1092: error: request for member `red' in something not a structure or union
t1x11.c:1092: error: request for member `red' in something not a structure or union
t1x11.c:1093: error: request for member `green' in something not a structure or union
t1x11.c:1093: error: request for member `green' in something not a structure or union
t1x11.c:1094: error: request for member `blue' in something not a structure or union
t1x11.c:1094: error: request for member `blue' in something not a structure or union
t1x11.c:1095: error: request for member `flags' in something not a structure or union
t1x11.c:1095: error: `DoRed' undeclared (first use in this function)
t1x11.c:1095: error: `DoGreen' undeclared (first use in this function)
t1x11.c:1095: error: `DoBlue' undeclared (first use in this function)
t1x11.c:1096: error: request for member `pad' in something not a structure or union
t1x11.c:1096: error: request for member `pad' in something not a structure or union
t1x11.c:1099: error: request for member `pixel' in something not a structure or union
t1x11.c: At top level:
t1x11.c:1122: error: syntax error before '*' token
t1x11.c: In function `T1_XImageFromGlyph':
t1x11.c:1124: error: `XImage' undeclared (first use in this function)
t1x11.c:1124: error: `ximage' undeclared (first use in this function)
t1x11.c:1136: error: `XYBitmap' undeclared (first use in this function)
t1x11.c:1149: error: `ZPixmap' undeclared (first use in this function)
gmake[2]: *** [t1x11.lo] Error 1
gmake[2]: Leaving directory `/usr/ports/devel/t1lib/work/t1lib-5.1.2/lib/t1lib'
gmake[1]: *** [t1lib_target] Error 1
gmake[1]: Leaving directory `/usr/ports/devel/t1lib/work/t1lib-5.1.2/lib'
gmake: *** [XXXX] Error 1
*** Error code 2

Stop in /usr/ports/devel/t1lib.
*** Error code 1

Stop in /usr/ports/graphics/php5-gd.
*** Error code 1

Stop in /usr/ports/print/pecl-pdflib.
*** Error code 1

Stop in /usr/ports/lang/php5-extensions.
*** Error code 1

Stop in /usr/ports/lang/php5-extensions.

没有安装X11的.

解决办法:

QUOTE:
原帖由 hehetest 于 2008-2-28 13:49 发表
T1_AA_TYPE16=short -DT1_AA_TYPE32=int t1x11.c  -fPIC -DPIC -o .libs/t1x11.o
t1x11.c:41:22: X11/Xlib.h: No such file or directory
t1x11.c:42:23: X11/Xutil.h: No such file or directory

In file i ...

make WITHOUT_X11=yes install clean

gettext简介

由fanyamin翻译摘录自php.net及

http://www.onlamp.com/pub/a/php/2002/06/13/php.html
gettext函数实现了本地化语言支持的应用程序接口,可用于PHP应用程序的国际化,详细的说明文档请参见

http://www.gnu.org/software/gettext/manual/index.html
需求:
要使用这些函数,必需从

http://www.gnu.org/software/gettext/gettext.html 下载安装GNU gettext软件包
要在你的PHP安装中加入GNU gettext支持,必需增加--with-gettext[=DIR]选择,其中 DIR 是 gettext 的安装目录,默认为/usr/local.
注意对于win32用户,必需拷贝gnu_gettext.dll到windows下的SYSTEM32目录,从PHP 4.2.3开始更名为libintl-1.dll,而且同时要安装iconv.dll
函数列表
bind_textdomain_codeset -- Specify the character encoding in which the messages from the DOMAIN message catalog will be returned
bindtextdomain -- Sets the path for a domain
dcgettext -- Overrides the domain for a single lookup
dcngettext -- Plural version of dcgettext
dgettext -- Override the current domain
dngettext -- Plural version of dgettext
gettext -- Lookup a message in the current domain
ngettext -- Plural version of gettext
textdomain -- Sets the default domain
为简单起见,Gettext PHP extension允许通过使用gettext()函数在你的PHP代码中动态地翻译源字串为适宜的目的字串,
如果那个字串仍没有被翻译,则保留源字串。
例如
<?php
// I18N support information here
$language = 'en';
putenv("LANG=$language");
setlocale(LC_ALL, $language);
// Set the text domain as 'messages'
$domain = 'messages';
bindtextdomain($domain, "/www/htdocs/site.com/locale");
textdomain($domain);
echo gettext("A string to be translated would go here");
?>
安装Gettext文件
Gettext需要一个拥有全部翻译字串的locale目录,基本结构如下
/locale
/en
/LC_MESSAGES
messages.po
messages.mo
在locale目录中要为每一个你想要支持的语言创建一个子目录
<?php
// The language code goes here
$language = 'zh_CN';
putenv("LANG=$language");
setlocale(LC_ALL, $language);
// ....
?>
例如:
/locale
/en
/LC_MESSAGES
messages.po
messages.mo
/zh_CN
/LC_MESSAGES
messages.po
messages.mo
zh_CN目录创建以后,在PHP文件中用gettext函数标注需要翻译和文本,然后可以用命令
$xgettext -n *.php
来生成翻译字串文件messages.po,举例如下
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Free Software Foundation, Inc.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2002-04-06 21:44-0500\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"
#: gettext_example.php:12
msgid "A string to be translated would go here"
msgstr ""
这个文件包括所有在gettext()调用的字串,可提供给翻译者翻译成不同的语言
然后,就可把这些pot文件*.po转换成Gettext函数真正能够了解的二进制文件*.mo
以下命令可以创建一个message.mo文件,且须放置在正确的目录下locale/<LANG_CODE>/LC_MESSAGES/
$ msgfmt messages.po
注意如果新增一包含新字串的新文件,如何维护一个包括所有字串翻译的不断更新的message.po文件
这时就可利用gettext的msgmerge 功能
$ ls
example.php
$ xgettext -n *.php
$ ls
example.php messages.po
// ...
// Translates the messages.po file now
// ...
$ msgfmt messages.po
$ ls
example.php messages.po messages.mo
// ...
// Changes the example.php file
// ...
$ mv messages.po old.po
$ xgettext -n *.php
$ ls
example.php messages.po messages.mo old.po
$ msgmerge old.po messages.po --output-file=new.po
$ ls
example.php messages.po messages.mo new.po old.po
// ...
// Translates the new.po file
// ...
$ msgfmt new.po

关于php中gettext的用法?

利用gettext实现多国语系支持!

这里我们主要介绍window平台下使用php的扩展gettext实现程序的国际化。

步骤一:搭建环境
1,首先查看你的php扩展目录下是否有php_gettext.dll这个文件,如果没有,这就需要你下载一个或是从其他地方拷贝一个,然后放到php扩展目录。
2,打开php.ini,查找”;extension=php_gettext.dll“ ,然后去除注释,重启apache。

步骤二:原理讲解
假如你的没有国际化的程序里有这样的代码,echo "你好";,而国际化的程序你要写成 echo gettext("你好");,然后再在配置文件里添加“你好”相对应的英文“Hi”。
这时,中国地区浏览都会在屏幕上输出“你好”,而美国地区浏览都会在屏幕上输出“Hi”。也就是说,最终显示什么是根据你的配置文件而定的,如果找不到配置文件,才会输出程序里面的内容。

步骤三:编码测试
1,我们在d:\www下面新建文件
hi.php,详细代码如下

1 <?php
2
3 $domain = 'test';
4 bindtextdomain($domain, "locale/");//设置某个域的mo文件路径
5 textdomain($domain);//设置gettext()函数从哪个域去找mo文件
6 echo gettext("Hi!");//_()是gettext()函数的简写形式
7
8 ?>

这时你运行改程序,只会输出“Hi”。但我们是中国人,我们不认识“Hi”,
我们只认识“你好”,这时就要配置文件出马。配置文件的生成一般借助一款工具。
下载地址:http://nchc.dl.sourceforge.net/sourceforge/gnuwin32/gettext-0.14.4.exe
安装好以后,为了在任意目录里使用,需要把“安装路径/bin”添加到系统环境变量里。

步骤四:配置文件的生成
1,我们假设你的工具已经安装好,并且可以在任意目录使用。现在就要运行cmd,并把路径切换到d:\www下面,也就是hi.php所在目录。
键入xgettext -d hi hi.php --from-code=gb2312,然后执行,这时你可以看到新生成一个hi.po文件,注意:--from-code=gb2312,其中gb2312还可以是utf-8。
2,打开hi.po文件,显示如下:

# 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-01-19 17:47+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"

#: hi.php:6
msgid "Hi!"
msgstr
""

现在有两个地方需要修改,
1:"Content-Type: text/plain; charset=CHARSET\n"
2:
msgstr ""把1中的CHARSET修改成gb2312,然后把2修改成msgstr "你好"。
3,键入msgfmt -o hi.mo hi.po,执行,这时生成hi.mo文件。
然后在d:\www下新建locale\zh_Cn\LC_MESSAGES目录,把hi.mo拷到这里就行了。
4,现在重启apache,再次运行,屏幕上可以输出“你好”。

其他:
如果使用utft-8编码的话,需要使用 bind_textdomain_codeset($domain,'UTF-8');
相应的要把hi.po里的CHARSET改成utf-8,还需要把hi.po保存成utf-8格式,再次生成hi.mo就行了。

总结:
我们都希望我们写的程序可以被大众甚至国际普遍使用,像大名鼎鼎的wordpress的国际化使用的也是他。gettext还是非常不错的,简单易用

$domain = 'test';
bindtextdomain(
$domain, "locale/");//设置某个域的mo文件路径
textdomain($domain);//设置gettext()函数从哪个域去找mo文件
echo _("Hi,phper!");//_()是gettext()函数的简写形式

?>

史上最牛的人力资源部经理

我的老同学开创了一个软件公司,据说富得流油。今天他到这个城市来后马上打电话给我:“还好吧?我到这里的大学里招毕业生,要呆上五天,咱哥们趁这个机会好好聚一聚,我做东。”

既然他要做东,我理所当然顺水推舟。

来到他下榻的宾馆,看见一个大学生模样的人站在他面前接受面试。我的老同学说:“我这里有个魔方,你能不能把它弄成六面六个颜色?”那个大学生拿着魔方,面有难色。

我的老同学看了看我,对大学生说:“如果你没有考虑好,可以把魔方拿回去考虑,我直到星期五才走。”等那个大学生走了以后,我问老同学:“这是你独创的考题?”

“咳!这个人有后台,我不好意思不要他,所以出个题考他,以便到时候安排个合适的职务。”

我说:“要是我会把魔方拆开,然后一个个安上去。”

他不假思索地回答:“如果他这样做就好了,这就说明他敢作敢为,就可以从事开拓市场方面的工作。”

“那其他做法呢?”

“如果他拿漆把六面刷出来,说明他很有创意,可以从事软件开发部的工作;如果他今天下午就把魔方拿回来,说明他非常聪明,领悟能力强,做我的助理最合适了;如果他星期三之前把魔方拿回来,说明他请教了人,也就是说他很有人缘,可以去客户服务部工作;如果在我走之前拿回来,说明他勤劳肯干,从事低级程序员的工作没问题;如果他最终拿回来说他还是不会,那说明他人很老实,可以从事保管或财物方面的工作;如果他拿不回来,那我就爱莫能助了。”

第二天晚上,我的老同学又请我吃饭。在饭桌上,我又问起魔方的事。这一回,老同学有些得意洋洋:“那个大学生我要定了,他今天早上把魔方还给了我,你猜怎么着?他新买了一个魔方!他还说‘你的魔方我扳来扳去都无法还原,所以,我新买了一个,比你那个更大、更灵活!’”

“这说明什么?”我问。我的老同学压低了声音:“他绝对是做盗版的好材料!”
感谢【网友:昂首向前冲】推荐