如何在TurboGears中翻译JavaScript字符串

2024-10-02 06:33:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以翻译python和html文件中的字符串。但当我翻译JavaScript字符串时,浏览器控制台会出现以下错误:

Uncaught ReferenceError: _ is not defined

我的设置.py公司名称:

message_extractors={'wiki20': [
        ('**.py', 'python', None),
        ('templates/**.html', 'genshi', None),
        ('public/javascript/index.js', 'javascript', None),
        ('public/**', 'ignore', None)
]},

JavaScript文件内容:

$("#bulbunu2").html(_('jquery two add this..! bla2'));

当我运行python setup.py extract_messages时,我在.pot文件中看到js字符串,(命令生成JavaScript字符串),但浏览器给出了错误。你知道吗

我怎样才能解决这个问题?你知道吗


Tags: 文件字符串pynoneishtml错误js
1条回答
网友
1楼 · 发布于 2024-10-02 06:33:59

TurboGears本身并不提供javascript gettext库,在收集和翻译字符串之后,您可能需要javascript库来读取.po文件,并需要javascript库来翻译字符串。你知道吗

您可以使用https://www.npmjs.com/package/po2json读取.po文件并将其转换为JSON,然后您可以使用http://slexaxton.github.io/Jed/_()函数本身的任何其他翻译库。你知道吗

相关问题 更多 >

    热门问题