Skip to content
Newer
Older
100644 127 lines (105 sloc) 3.78 KB
168124b @jiangxin add DOCTYPE, so quanta can detect file type automatically
jiangxin authored Sep 12, 2008
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
4 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
5 -->
6
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
7 <!-- =================================================================== -->
8 <sect1 id="psm.i18n">
9 <title>国际化</title>
10
11 <para>要将软件开源,就需要它能说多种语言。让程序支持多语种,Pylons实现非常简单,
12 用Python的gettext模组实现国际化。</para>
13
14 <!-- ================================================================= -->
15 <sect2 id="psm.i18n.gettext">
16 <title>使用_()改写字符串输出</title>
17
18 <para>函数_()实际上是gettext模组的 ugettext方法别名。将程序中出现的字符串输出改为
19 _()调用。例如,在模板文件中:</para>
20
5ee683c @jiangxin screen -> programlisting
jiangxin authored Sep 12, 2008
21 <programlisting><![CDATA[
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
22 <tr>
23 <th>Account</th>
24 <th>Repository</th>
25 <th>Modules</th>
26 </tr>
5ee683c @jiangxin screen -> programlisting
jiangxin authored Sep 12, 2008
27 ]]></programlisting>
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
28
29 <para>修改为</para>
30
5ee683c @jiangxin screen -> programlisting
jiangxin authored Sep 12, 2008
31 <programlisting><![CDATA[
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
32 <tr>
33 <th>${_("Account")}</th>
34 <th>${_("Repository")}</th>
35 <th>${_("Modules")}</th>
36 </tr>
5ee683c @jiangxin screen -> programlisting
jiangxin authored Sep 12, 2008
37 ]]></programlisting>
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
38
39 <para>控制器代码中:</para>
40
5ee683c @jiangxin screen -> programlisting
jiangxin authored Sep 12, 2008
41 <programlisting><![CDATA[
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
42 def get_auth_path(self, repos=None, type=None, path=None):
43 ..
44 msg += 'id[0]="%s";' % '...'
45 msg += 'name[0]="%s";\n' % "Please choose..."
5ee683c @jiangxin screen -> programlisting
jiangxin authored Sep 12, 2008
46 ]]></programlisting>
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
47
48 <para>修改为:</para>
49
5ee683c @jiangxin screen -> programlisting
jiangxin authored Sep 12, 2008
50 <programlisting><![CDATA[
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
51 def get_auth_path(self, repos=None, type=None, path=None):
52 ..
53 msg += 'id[0]="%s";' % '...'
54 msg += 'name[0]="%s";\n' % _("Please choose...")
5ee683c @jiangxin screen -> programlisting
jiangxin authored Sep 12, 2008
55 ]]></programlisting>
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
56
57 </sect2>
58
59 <!-- ================================================================= -->
60 <sect2 id="psm.i18n.default">
61 <title>根据浏览器喜好自动选择缺省语种</title>
62
5ee683c @jiangxin screen -> programlisting
jiangxin authored Sep 12, 2008
63 <programlisting><![CDATA[
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
64 from pylons.i18n import set_lang, add_fallback
65
66 class BaseController(WSGIController):
67 def __before__(self, action):
68
69 if 'lang' in session:
70 set_lang(session['lang'])
71 for lang in request.languages:
72 if lang in ['zh', 'en']:
73 add_fallback(lang)
5ee683c @jiangxin screen -> programlisting
jiangxin authored Sep 12, 2008
74 ]]></programlisting>
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
75
76 </sect2>
77
78 <!-- ================================================================= -->
79 <sect2 id="psm.i18n.translate">
80 <title>本地化翻译</title>
81
82 <table id="psm.i18n.translate.tbl-1">
83 <title>本地化翻译相关命令</title>
84 <tgroup cols="2">
85 <thead>
86 <row>
87 <entry>任务</entry>
88 <entry>命令</entry>
89 </row>
90 </thead>
91 <tbody>
92 <row>
93 <entry>提取待翻译字符串,保存为模板文件(*.pot)</entry>
94 <entry>$ python setup.py extract_messages</entry>
95 </row>
96 <row>
97 <entry>根据模板文件,创建本地语种文件(*.po)</entry>
861e63c @jiangxin add ulink; add sidebar for snapshot
jiangxin authored Sep 10, 2008
98 <entry>$ python setup.py init_catalog -l zh_CN</entry>
cfecb0c @jiangxin initial
jiangxin authored Sep 10, 2008
99 </row>
100 <row>
101 <entry>翻译*.po文件(工具: kbabel)</entry>
102 <entry>$ kbabel pySvnManager/i18n/zh/LC_MESSAGES/pysvnmanager.po</entry>
103 </row>
104 <row>
105 <entry>编译*.po文件为*.mo文件</entry>
106 <entry>$ python setup.py compile_catalog</entry>
107 </row>
108 <row>
109 <entry>代码中字符串改变,重新提取模板文件(*.pot)</entry>
110 <entry>$ python setup.py extract_messages</entry>
111 </row>
112 <row>
113 <entry>用模板(*.pot)更新各语种的*.po文件</entry>
114 <entry>$ python setup.py update_catalog</entry>
115 </row>
116 <row>
117 <entry>翻译完毕,别忘了编译新的*.mo文件</entry>
118 <entry>$ python setup.py compile_catalog</entry>
119 </row>
120 </tbody>
121 </tgroup>
122 </table>
123
124 </sect2>
125
126 </sect1>
Something went wrong with that request. Please try again.