【问题标题】:French locale is breaking button function法语语言环境正在破坏按钮功能
【发布时间】:2021-12-27 04:04:31
【问题描述】:

问题

如果用户在法语语言环境中查看网站,按钮将无法正常工作。

背景信息

我正在使用{% trans %} 标签直接在我的 Django 模板中翻译按钮文本。在我的脚本标签中,我还使用{% trans %} 标签在触发按钮操作(onclick)后添加翻译:let show_correction = '{% trans "Show native corrections" %}';

在法语语言环境中,它变为:let show_correction='Afficher les corrections d'autres locuteurs natifs';。我认为这个问题具体发生在d'autres

我的猜测

也许函数由于撇号而提前终止?


我该如何解决这个问题?

【问题讨论】:

  • 翻译代码有没有转义引号?
  • @epascarello 针对这个问题发布了一个可行的解决方案。

标签: javascript django string django-templates


【解决方案1】:

解决方案:https://docs.djangoproject.com/en/3.2/topics/i18n/translation/#module-django.views.i18n

基本用法:

let foo = gettext("Your string to be translated");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    • 2020-03-23
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    相关资源
    最近更新 更多