Plone翻译之i18n设定翻译字符串
Plone翻译之i18n设定翻译字符串
http://www.315ok.org/blogfolder/189
http://www.315ok.org/logo.png
Plone翻译之i18n设定翻译字符串
Plone翻译之i18n设定翻译字符串
本文将阐述怎样在页面模版中设置i18n元素以用于网页界面翻译。
Plone的多语言支持及翻译分为两个部分:
Getting started:下面是一个简单的页面模版,我们将以这个模版为例来设置i18n元素,完成翻译:
<html>
<body>
<p>Welcome to Plone.</p>
<img src="plone.gif" alt="Plone Icon" />
<p>There have been over
<span tal:content="here/download_count">100,000</span>
downloads of Plone.
</p>
<p>Please visit
<a href="about">About Plone</a>
for more information.
</p>
</body>
</html>
可以看到有几个地方需要翻译
<p i18n:translate="XXX">Welcome to Plone.</p>
第二种情况:图片的 Alt 文本翻译
这种情况我们用i18n:attributes 元素
例如: <img src="plone.gif" alt="Plone Icon" i18n:attributes="alt" />
[align=left]如果有两个或两个以上的tag属性,属性间用空格分隔,如:[/align]<img src="plone.gif" alt="Plone Icon" title="Plone Icon Title"
i18n:attributes="alt title">
[align=left]另外,可以指定msgid来标识特定的属性,这时多个属性间要用";"分隔,如:[/align]<img src="plone.gif" alt="Plone Icon" title="Plone Icon Title"
i18n:attributes="alt plone-icon; title plone-icon-title">
[align=left]上例意思是指明我们标识了两个i18n动态属性元素,一个是图片的alt属性,用msgid为 "plone-icon"来标识, 两一个是图片的title属性,用msgid为 "plone-icon-title"来标识。[/align]
第三种情况:动态内容翻译定位例中如下段:
<p>There have been over
<span tal:content="here/download_count">100,000</span>
downloads of Plone.
</p>
为了翻译动态内容,我们用 i18n:name 元素.
段中要翻译的文本将表现如下:
There have been over ${count} downloads of Plone.
其中
${count}是可以动态替换的,我们的i18n元素将应如下标识:
<p i18n:translate="">There have been over
<span tal:content="here/download_count"
i18n:name="count">100,000</span>
downloads of Plone.
</p>
如果有两处以上的动态内容要替换,则参考下例:
<p i18n:translate="">My name is
<span tal:content="here/first" i18n:name="first">first</span>
<span tal:content="here/last" i18n:name="last">last</span>
</p>
生成的待翻译的文本应如下:
My name is ${first} ${last}
第四种情况:前叙情况的组合
<p>Please visit
<a href="about">About Plone</a>
for more information.
</p>
我们想形成的待翻译的文本如下:
Please visit ${about-plone} for more information.
不完全等同如动态内容替换,我们想"About Plone"也能被翻译,为实现这个,我们放一个 i18n:name 元素在 link tag, 并且放一个 i18n:translate tag , 如下:
<p i18n:translate="">Please visit
<span i18n:name="about-plone">
<a href="about" i18n:translate="">
About Plone</a>
</span>
for more information.
</p>
加入第二种情况的i18n元素标识如下:
<p i18n:translate="">Please visit
<span i18n:name="about-plone">
<a href="about" i18n:translate=""
i18n:attributes="title" title="Go to About Page">
About Plone</a>
</span>
for more information.
</p>
提示:
不要在同一个tag中同时使用i18n:name 和 i18n:translate
即不要这样:
<p i18n:translate="text_long">
Bar
<a href="" i18n:name="foo"
i18n:translate="text_used_other_places">
Foo
</a>
Baz
</p>
而要:
<p i18n:translate="text_long">
Bar
<span i18n:name="foo">
<a href="" i18n:translate="text_used_other_places">Foo</a>
</span>
Baz
</p>
在tag中包括标点符号
不要:
<span i18n:translate="">The participants</span>:
而要:
<span i18n:translate="">The participants:</span>
不要将一个句子分离在不同的tag中:
不要:
<p>
<span i18n:translate="">Hello, my name is</span>
<span tal:content="user/name">user</span>
<span i18n:translate=""> and I live in Zopeville.</span>
</p>
而要:
<p i18n:translate="">
Hello, my name is
<span tal:content="user/name" i18n:name="user" >user</span>
and I live in Zopeville.
</p>
Plone的多语言支持及翻译分为两个部分:
- 开发人员设置i18n元素
- 翻译人员为各种语言创建翻译文件
Getting started:下面是一个简单的页面模版,我们将以这个模版为例来设置i18n元素,完成翻译:
<html>
<body>
<p>Welcome to Plone.</p>
<img src="plone.gif" alt="Plone Icon" />
<p>There have been over
<span tal:content="here/download_count">100,000</span>
downloads of Plone.
</p>
<p>Please visit
<a href="about">About Plone</a>
for more information.
</p>
</body>
</html>
可以看到有几个地方需要翻译
- "Welcome to Plone"
- 图片的alt, "Plone Icon"
- 句子 "There have been over 100,000 downloads of Plone." 请注意,句子中的数字100,000应该是动态变化的,不应该直接翻译.
- 句子 "Please visit About Plone for more information.", 请注意,句子中的"About Plone" 是一个link,应保持其link.
- In some languages, the sentence "There have been over ${number} downloads of Plone" will have different translations depending on the value of ${number}. This case is not currently supported by Plone and Zope.
<p i18n:translate="XXX">Welcome to Plone.</p>
第二种情况:图片的 Alt 文本翻译
这种情况我们用i18n:attributes 元素
例如: <img src="plone.gif" alt="Plone Icon" i18n:attributes="alt" />
[align=left]如果有两个或两个以上的tag属性,属性间用空格分隔,如:[/align]<img src="plone.gif" alt="Plone Icon" title="Plone Icon Title"
i18n:attributes="alt title">
[align=left]另外,可以指定msgid来标识特定的属性,这时多个属性间要用";"分隔,如:[/align]<img src="plone.gif" alt="Plone Icon" title="Plone Icon Title"
i18n:attributes="alt plone-icon; title plone-icon-title">
[align=left]上例意思是指明我们标识了两个i18n动态属性元素,一个是图片的alt属性,用msgid为 "plone-icon"来标识, 两一个是图片的title属性,用msgid为 "plone-icon-title"来标识。[/align]
第三种情况:动态内容翻译定位例中如下段:
<p>There have been over
<span tal:content="here/download_count">100,000</span>
downloads of Plone.
</p>
为了翻译动态内容,我们用 i18n:name 元素.
段中要翻译的文本将表现如下:
There have been over ${count} downloads of Plone.
其中
${count}是可以动态替换的,我们的i18n元素将应如下标识:
<p i18n:translate="">There have been over
<span tal:content="here/download_count"
i18n:name="count">100,000</span>
downloads of Plone.
</p>
如果有两处以上的动态内容要替换,则参考下例:
<p i18n:translate="">My name is
<span tal:content="here/first" i18n:name="first">first</span>
<span tal:content="here/last" i18n:name="last">last</span>
</p>
生成的待翻译的文本应如下:
My name is ${first} ${last}
第四种情况:前叙情况的组合
<p>Please visit
<a href="about">About Plone</a>
for more information.
</p>
我们想形成的待翻译的文本如下:
Please visit ${about-plone} for more information.
不完全等同如动态内容替换,我们想"About Plone"也能被翻译,为实现这个,我们放一个 i18n:name 元素在 link tag, 并且放一个 i18n:translate tag , 如下:
<p i18n:translate="">Please visit
<span i18n:name="about-plone">
<a href="about" i18n:translate="">
About Plone</a>
</span>
for more information.
</p>
加入第二种情况的i18n元素标识如下:
<p i18n:translate="">Please visit
<span i18n:name="about-plone">
<a href="about" i18n:translate=""
i18n:attributes="title" title="Go to About Page">
About Plone</a>
</span>
for more information.
</p>
提示:
不要在同一个tag中同时使用i18n:name 和 i18n:translate
即不要这样:
<p i18n:translate="text_long">
Bar
<a href="" i18n:name="foo"
i18n:translate="text_used_other_places">
Foo
</a>
Baz
</p>
而要:
<p i18n:translate="text_long">
Bar
<span i18n:name="foo">
<a href="" i18n:translate="text_used_other_places">Foo</a>
</span>
Baz
</p>
在tag中包括标点符号
不要:
<span i18n:translate="">The participants</span>:
而要:
<span i18n:translate="">The participants:</span>
不要将一个句子分离在不同的tag中:
不要:
<p>
<span i18n:translate="">Hello, my name is</span>
<span tal:content="user/name">user</span>
<span i18n:translate=""> and I live in Zopeville.</span>
</p>
而要:
<p i18n:translate="">
Hello, my name is
<span tal:content="user/name" i18n:name="user" >user</span>
and I live in Zopeville.
</p>