【问题标题】:How to use T to tranlate strings in web2py module?如何使用 T 翻译 web2py 模块中的字符串?
【发布时间】:2013-11-03 19:31:19
【问题描述】:

我的 web2py 应用程序模块文件夹中有一个 countries.py 模块。它定义了以下元组:

COUNTRIES = (
    ('AF', T('Afghanistan')), 
    ('AX', T('Aland Islands')), 
    ('AL', T('Albania')), 
    ('DZ', T('Algeria')), 
    ('AS', T('American Samoa')), 
    ('AD', T('Andorra')), 
    ('AO', T('Angola')), 
    ('AI', T('Anguilla')), 
    ...

可用于创建国家/地区下拉列表。我遇到的问题是我收到一个错误:

<type 'exceptions.NameError'> name 'T' is not defined

那么如何使用来自 web2py 模块的翻译器T

【问题讨论】:

    标签: translation web2py web2py-modules


    【解决方案1】:

    根据谷歌组的这篇帖子:

    https://groups.google.com/forum/#!topic/web2py/cHSKbhbcSSA

    我加了

    from gluon import current
    T = current.T
    

    到我的 countries.py 模块的顶部,它现在似乎可以工作了。

    【讨论】:

      猜你喜欢
      • 2014-05-23
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      • 2013-05-01
      • 2015-01-04
      • 1970-01-01
      • 2018-08-03
      • 2021-04-05
      相关资源
      最近更新 更多