docutils 0.3.7 已經有 zh_tw 的 language code,其中包括了許多關鍵字的翻譯。這要感謝 joeysj 的貢獻。
不過,針對不同特性的文件與書籍,標準的 zh_tw i18n module 會有一點不夠用;docutils 目前也還沒有提供可以自訂關鍵字翻譯的組態工具。如果我們有自訂關鍵字翻譯的需要,可以對 rst2html.py 動點手腳:
#!/usr/bin/python # Author: David Goodger # Contact: goodger@python.org # Revision: $Revision: 1.2 $ # Date: $Date: 2004/03/28 15:39:27 $ # Copyright: This module has been placed in the public domain. """ A minimal front end to the Docutils Publisher, producing HTML. """ try: import locale locale.setlocale(locale.LC_ALL, '') except: pass from docutils.core import publish_cmdline, default_description import zh_tw description = ('Generates (X)HTML documents from standalone reStructuredText ' 'sources. ' + default_description) publish_cmdline(writer_name='html', description=description)
而另外建立 zh_tw.py 檔:
from docutils.languages.zh_tw import * from docutils.parsers.rst.languages.zh_tw import * labels['note'] = u'\u8a3b\u8a18' # 註記
上例中的
labels['note'] = u'\u8a3b\u8a18' # 註記
就是我想要自訂的關鍵字,如果指定成 non-ascii 字串,我發現會發生錯誤,請照上例寫成 raw_unicode_escape 。
用一段簡單的 Python script 就可以產生 raw unicode escape sequence:
import codecs e = codecs.getencoder( 'raw_unicode_escape' ) d = codecs.getdecoder( 'utf8' ) # whatever encoding your string read from print e(d(str)[0])[0]
Posted by yungyuc
at 20:05,
0 comment,
0 trackback.
Navigate
- Previous: 今日清境 @2005/07/10
- Next: Linux PXE/nfsroot 網路開機配合 initrd @2005/07/13
Add a trackback
Please send trackback to: http://blog.seety.org/everydaywork/2005/7/11/376/trackback/.
Add a comment