<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Xhacker&#039;s Base &#187; PyGTK</title>
	<atom:link href="http://xhacker.shiyiquan.cn/tag/pygtk/feed/" rel="self" type="application/rss+xml" />
	<link>http://xhacker.shiyiquan.cn</link>
	<description>Since June, 2009.</description>
	<lastBuildDate>Thu, 05 Jan 2012 13:43:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>PyGTK 多语言</title>
		<link>http://xhacker.shiyiquan.cn/pygtk-multilanguage/</link>
		<comments>http://xhacker.shiyiquan.cn/pygtk-multilanguage/#comments</comments>
		<pubDate>Thu, 27 May 2010 03:33:05 +0000</pubDate>
		<dc:creator>Xhacker</dc:creator>
				<category><![CDATA[太阳不错]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[PyGTK]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://xhacker.shiyiquan.cn/?p=479</guid>
		<description><![CDATA[今天上午折腾了半天，不妨记个笔记。 我们假设一个傻傻的 app 叫做 foo_app，再虚构一些目录。真正使用的时候可别直接照抄哦。 1.Python 文件 首先要加入下面的三行 import gettext from gettext import gettext as _ gettext.textdomain&#40;'foo_app'&#41; 然后就可以用 gettext 通用的格式了。例： print _&#40;'Beautiful day!'&#41; 貌似 Python 里面还不支持嵌入给翻译者的注释，所以这里一定要用表达清晰的英文。 2.Glade 文件 对于 Glade 文件来说是非常简单的，只要把某个部件的“可译的”勾上就万事大吉了。还是那句话，要用人类可读的英语。 当然为了感谢一下冒着烈日辛勤翻译的 translators，不妨在“翻译者致谢”中写上 translator-credits。这样翻译者可以轻松地将这个字串换成自己的大名然后臭显摆去。 3.转换 Glade 的 XML 文件为 .h &#8230; <a href="http://xhacker.shiyiquan.cn/pygtk-multilanguage/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>今天上午折腾了半天，不妨记个笔记。</p>
<p>我们假设一个傻傻的 app 叫做 foo_app，再虚构一些目录。真正使用的时候可别直接照抄哦。</p>
<h2>1.Python 文件</h2>
<p>首先要加入下面的三行</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">gettext</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">gettext</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">gettext</span> <span style="color: #ff7700;font-weight:bold;">as</span> _
<span style="color: #dc143c;">gettext</span>.<span style="color: black;">textdomain</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'foo_app'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>然后就可以用 gettext 通用的格式了。例：</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">print</span> _<span style="color: black;">&#40;</span><span style="color: #483d8b;">'Beautiful day!'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>貌似 Python 里面还不支持嵌入给翻译者的注释，所以这里一定要用表达清晰的英文。</p>
<h2>2.Glade 文件</h2>
<p>对于 Glade 文件来说是非常简单的，只要把某个部件的“可译的”勾上就万事大吉了。还是那句话，要用人类可读的英语。<br />
当然为了感谢一下冒着烈日辛勤翻译的 translators，不妨在“翻译者致谢”中写上 translator-credits。这样翻译者可以轻松地将这个字串换成自己的大名然后臭显摆去。</p>
<h2>3.转换 Glade 的 XML 文件为 .h 文件</h2>
<p>第一步要把 .glade 的 XML 文件转换成一些 .h 文件，以便生成 pot 文件。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">intltool-extract <span style="color: #660033;">--type</span>=gettext<span style="color: #000000; font-weight: bold;">/</span>glade some_dir<span style="color: #000000; font-weight: bold;">/</span>FooWindow.glade</pre></div></div>

<h2>4.生成 pot 文件</h2>
<p>这一步很爽，直接通配符就行了。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">xgettext <span style="color: #660033;">--language</span>=Python <span style="color: #660033;">--keyword</span>=_ <span style="color: #660033;">--keyword</span>=N_ <span style="color: #660033;">--output</span>=po<span style="color: #000000; font-weight: bold;">/</span>foo_app.pot some_dir<span style="color: #000000; font-weight: bold;">/*</span>.h some_other_dir<span style="color: #000000; font-weight: bold;">/*</span>.py <span style="color: #000000; font-weight: bold;">*</span>.py</pre></div></div>

<p>这样就产生了一个 pot 文件，然后你就可以考虑用这个 pot 泡壶茶喝了。</p>
<h2>5.开始翻译吧！</h2>
<p>这里的内容就不赘述了，详细的可以看<a href="http://docs.google.com/View?docID=0ATMcdwxwhYuQZGM1eHJuNGtfMWZ6MjRwd2c0&amp;revision=_latest&amp;hgd=1">自由软件中文化工作指南(L10N)</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://xhacker.shiyiquan.cn/pygtk-multilanguage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

