0

所以我正在做一个 django 项目,我们正在将英语翻译成捷克语(不重要)。我可以很好地处理被翻译的常规标签{% trans 'sample text' %}

但是,我在链接中有一个按钮,点击后,此链接会返回确认信息。完整的 html 看起来像这样

<a href="{% url 'foo' %}" onclick="return confirm(
       'Sample text')">
   <button>
       {% trans 'Regular trans tag' %}
  </button>
</a>

现在我想以某种方式翻译确认中的“示例文本”文本,但是当我尝试使用它时,{% trans %}它给了我错误“foo/bar expected (js)”

4

1 回答 1

0

在 JS 中翻译“示例文本”:

<a href="{% url 'foo' %}" onclick="return confirm('{% trans "Sample text" %}')">
   <button>
       {% trans 'Regular trans tag' %}
  </button>
</a>

或者还有其他选项,如果您需要在运行时在客户端上提供所有语言。你需要这个吗?

于 2021-07-08T14:56:52.313 回答