i18n by python不能在web上工作

时间:2013-08-13 02:59:30

标签: python web internationalization po

  1. “cn”和“en”都在终端中工作
  2. “en”适用于网络,但“cn”不起作用;
  3. 如何让“cn”在网络上运作?

    BTW:msgfmt,Fedora18,httpd;

    test.py:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import gettext
    gettext.install('lang', './locale', unicode=True)
    gettext.translation('lang', './locale', languages=['cn']).install(True)
    
    print "Content-type: text/plain\n" 
    print _("Hello world!")
    print "中文"
    

    终端输出“cn”:

    [root@localhost cgi-bin]# ./test.py 
    Content-type: text/plain
    
    中文
    

    “en”终端输出:

    [root@localhost cgi-bin]# ./test.py 
    Content-type: text/plain
    
    It works.
    中文
    

    网页“en”:

    It works.
    中文
    

    网页“cn”: 什么都不显示

    “curl locahost / cgi-bin / test.py”by“cn”: 什么都不返回

    区域设置/ CN / LC_MESSAGES / lang.po:

    # SOME DESCRIPTIVE TITLE.
    # Copyright (C) YEAR ORGANIZATION
    # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
    #
    msgid ""
    msgstr ""
    "Project-Id-Version: PACKAGE VERSION\n"
    "POT-Creation-Date: 2013-08-12 05:20+EDT\n"
    "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    "Language-Team: LANGUAGE <LL@li.org>\n"
    "MIME-Version: 1.0\n"
    "Content-Type: text/plain; charset=UTF-8\n"
    "Content-Transfer-Encoding: utf-8\n"
    "Generated-By: pygettext.py 1.5\n"
    
    msgid "Hello world!"
    msgstr "你好!"
    

    区域设置/ EN / LC_MESSAGES / lang.po:

    # SOME DESCRIPTIVE TITLE.
    # Copyright (C) YEAR ORGANIZATION
    # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
    #
    msgid ""
    msgstr ""
    "Project-Id-Version: PACKAGE VERSION\n"
    "POT-Creation-Date: 2013-08-12 05:20+EDT\n"
    "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    "Language-Team: LANGUAGE <LL@li.org>\n"
    "MIME-Version: 1.0\n"
    "Content-Type: text/plain; charset=UTF-8\n"
    "Content-Transfer-Encoding: utf-8\n"
    "Generated-By: pygettext.py 1.5\n"
    
    msgid "Hello world!"
    msgstr "It works."
    

    路径:

    /var/www/cgi-bin/
    |-- locale
    |   |-- cn
    |   |   `-- LC_MESSAGES
    |   |       |-- lang.mo
    |   |       `-- lang.po
    |   `-- en
    |       `-- LC_MESSAGES
    |           |-- lang.mo
    |           `-- lang.po
    `-- test.py
    

0 个答案:

没有答案