javascript - 如何在 Pylons 中翻译 javascript 文件

标签 javascript jquery python translation pylons

我们正在使用 Pylons 和 JQuery 制作一个应用程序。我们使用了标准的翻译方法,但它不太适用于 javascript。

js翻译方法的尴尬之处在于我们应该重复选择语言等过程。

Pylons 是否对 javascript 翻译提供适当的支持?

最佳答案

另一种方法是使用 pylons gettext 生成您自己的 JavaScript 字符串 ID,如下所示:

html 模板:

<script type="text/javascript">
   var i18n_strings = {
      hello_world = '${ugettext('Hello World!')}',
      goodbye_world = '${ugettext('Goodbye World!')}',
      enter_name = '${ugettext('Enter Name:')}'
   };
</script>

现在在你的 JavaScript 中:

$('#some-elem').html( i18n_strings.hello_world );

关于javascript - 如何在 Pylons 中翻译 javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3288726/

相关文章:

javascript - BackboneJS - 从 PHP 文件中获取数据并在 View 中显示

jquery - 使用 Jquery 更新 Azure 网页

jquery - HTML/jQuery - 防止空文本节点

python - 检查日期是否为 UTC 格式

python - 将列表拆分为具有多个整数定界符的 block

python - 如何在 Visual Studio Code 中运行调试 Django 应用程序?

javascript - Owl Carousel 不显示

javascript - 为 Handlebars 模板中的模型赋值

javascript - Freecodecamp 中的 Javascript 代码错误

jquery - 滚动时调整导航大小