【问题标题】:gettext: how to avoid fail at unicode character?gettext:如何避免 unicode 字符失败?
【发布时间】:2018-10-02 13:31:44
【问题描述】:

这是一个 python 文件,它导致 gettext 在 unicode 字符代码 \u2191 处失败。

texts = {
    'first': _(u'Hello world'),
    'fails': _(u'Arrow: \u2191'),  # This code causes problems for gettext
    'omitted': _(u'Innocent string here')
}

在命令行中运行C:\Python27\pythonw.exe C:\Python27\Tools\i18n\pygettext.py -d string_file string_file.py时,结果POT文件包含正确的标头但遇到unicode箭头时失败:

#: translate.py:2
msgid "Hello world"
msgstr ""

#: translate.py:3
msgid

我该怎么做才能让它与 unicode 字符代码一起使用?

【问题讨论】:

    标签: python unicode translation gettext pot


    【解决方案1】:

    一种解决方法是从待翻译的字符串中删除代码

    # Not wrapped in _() so does not enter gettext
    arrrow_char = u'\u2191'
    
    # These are now accessible to gettext
    texts = {
        'first': _(u'Hello world'),
        'fails': _(u'Arrow: %s') %arrow_char,  # No longer causes a problem
        'omitted': _(u'Innocent string here')
    }
    

    【讨论】:

      猜你喜欢
      • 2013-06-04
      • 1970-01-01
      • 1970-01-01
      • 2013-12-19
      • 1970-01-01
      • 2016-05-21
      • 2014-10-01
      • 2013-05-26
      • 1970-01-01
      相关资源
      最近更新 更多