如何在 Django 中翻译按钮上的文本?

问题描述 投票:0回答:1

我尝试在 Django 上制作双语网站。

Frontend 不是我写的,不幸的是,我不能为做它的人问这个问题。

const configButton = {
    purchases: {
        attr: 'data-out',
        default: {
            class: 'button_style_blue',
            text: '<span class="icon-plus button__icon"></span>Add to purchase list'
        },
        active: {
            class: 'button_style_light-blue-outline',
            text: '<span class="icon-check button__icon"></span>Recipe in purchase list'
        }
    }
}

如何使用 Django 内部化工具在按钮上添加文本翻译?

javascript html django translation
1个回答
0
投票

在你的文件中导入

from django.utils.translation import gettext as _

然后无论您要翻译的文本是什么,都将其放入变量中,例如您的情况-

addToList = _("Add to purchase list")
reciepeInList = _("Recipe in purchase list")

const configButton = {
    purchases: {
        attr: 'data-out',
        default: {
            class: 'button_style_blue',
            text: '<span class="icon-plus button__icon"></span>' + addToList
        },
        active: {
            class: 'button_style_light-blue-outline',
            text: '<span class="icon-check button__icon"></span>' + reciepeInList
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.