简体   繁体   English

django通过名称而不是内容来翻译变量

[英]django translating variable by name instead of content

I would like to use django i18n system for translating content of my website. 我想使用django i18n系统翻译我的网站内容。

One of this purpuse would be <meta keywords="word1, word2"> tag. 这个目的之一就是<meta keywords="word1, word2">标签。 At the moment I am translating "word1, word2" string but if I change it the rest of translations won't work. 目前,我正在翻译"word1, word2"字符串,但是如果更改它,其余的翻译将无法正常工作。

The best would be just setting the variable and saying the translation system "Use english version of the content of this variable". 最好的办法就是设置变量并说翻译系统“使用该变量内容的英文版本”。

I would like to avoid setting this in the database as this can be specified in the template or other html/python file. 我想避免在数据库中进行设置,因为可以在模板或其他html / python文件中指定它。 I'd like to avoid the additional database/cache hit. 我想避免额外的数据库/缓存命中。

Is there any way of displaying different language versions of variable - not the content ? 有什么方法可以显示变量的不同语言版本-而不是内容?

I know this can be done by including template with {% if LANGUAGE_CODE == "xx" %} conditions but maybe there is the other way ? 我知道可以通过在{% if LANGUAGE_CODE == "xx" %}条件下包含模板来完成此操作,但也许还有其他方法吗?

Use placeholder text and create a en.po file with only that one translation containing the values. 使用占位符文本并创建一个en.po文件,其中只有一个包含值的翻译。 Note that you will then be responsible for making the translators aware of the English content instead of it being contained in their corresponding .po file. 请注意,您将负责使翻译人员知道英语内容,而不是将其包含在相应的.po文件中。

<meta keywords={% trans "META KEYWORDS" %} />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Django 中翻译动态内容 - Translating dynamic content in django 翻译django模板中的动态内容 - Translating dynamic content in django templates 在Django查询比较中使用变量而不是字段名称 - Using variable instead of field name in Django query comparions Django删除确认视图显示变量名称而不是信息 - Django delete confirmation view displaying variable name instead of information 在内容处置响应文件名-python / django中添加变量 - Adding a variable in Content disposition response file name-python/django 在 django 模板中动态翻译 {{ model.name }} 数据 - Translating {{ model.name }} data dynamically in django template 如何在 Django 的包含 function 中添加“variable.html”而不是硬编码模板名称? - How to add "variable.html" in include function of Django instead of hard coding the template name? 从Django中的外键设置会话变量:需要字段名称而不是主键 - Setting session variable from foreign key in Django: Need field name instead of primary key 在 Javascript 中获取 Django 视图字典键,但不是将其视为字符串,而是将其视为变量名称 - Getting Django view dictionary key in Javascript, but instead of considering it a String, considers a Variable Name 表单中的 Django 文本未翻译 - Django text in form is not translating
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM