先举个栗子吧
如:申请
1.作为一个名词,翻译为英文是apply
2.作为一个动词,翻译为因为是application
所以,国际化时候这类多义词就要做特殊处理
发现喜欢贴官网说明 上图:
将多义词以msgctxt在做个标记
msgctxt "apply none"
msgid "申请"
msgstr "apply"
msgctxt "apply verb"
msgid "申请"
msgstr "application"
在python页面上 用法:
{% trans "申请" context "apply none" %}
{% trans "申请" context "apply verb" %}
关于po文件编译时候报错,在这描述下
G:\install\work\python35\Tools\i18n>python msgfmt.py G:\workspace_python\testsit
e1\test1\locale\en_US\LC_MESSAGES\django_en_US_testsite.po
Traceback (most recent call last):
File "msgfmt.py", line 236, in
main()
File "msgfmt.py", line 232, in main
make(filename, outfile)
File "msgfmt.py", line 184, in make
l = ast.literal_eval(l)
File "G:\install\work\python35\lib\ast.py", line 46, in literal_eval
node_or_string = parse(node_or_string, mode='eval')
File "G:\install\work\python35\lib\ast.py", line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "", line 1
msgctxt "test"
SyntaxError: invalid syntax
gettext翻译模块的问题,后来我到ubuntu中编译
sudo apt-get install gettext
安装完成后会新增加相关的一些命令:
另外,在ubuntu想安装gettext,但不知到安装的名称是啥,分享一个不知道安装名称时候用的命令:
apt-cache search gettext
(python-django)vagrant@precise64:/vagrant$ msgcat django_en_US_testsite.po |msgfmt -o testc2.mo -