I have a placeholder in the search bar form. I want to translate it to the user's selected language. I tried to use the {% translate 'message to translate' %}
but only get the first word shown in the bar (maybe a problem with the quoatation marks?).
我在搜索栏表单中有一个占位符。我想把它翻译成用户选择的语言。我尝试使用{%Translate‘消息来翻译’%},但只得到栏中显示的第一个单词(可能是引号有问题?)。
The html
file:
Html文件:
<form class="form_search">
{% csrf_token %}
<div class="form-group input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-search" style="color:black"></i></span>
<input type="search" class="form-control home_search rounded-end" placeholder= {% translate "placeholder text here nicely..." %} name='keyword' id='inputsearch'>
</div>
</form>
The views.py
file:
Views.py文件:
def search_home(request):
return render(request, 'search_home.html',context)
Passing it from context
does not work either.
从上下文中传递也不起作用。
from django.utils.translation import gettext_lazy as lazy_
def search_home(request):
context = {'placeholder_search':lazy_('some placeholder here to be translated...')}
return render(request, 'search_home.html',context)
<form class="form_search">
{% csrf_token %}
<div class="form-group input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-search" style="color:black"></i></span>
<input type="search" class="form-control home_search rounded-end" placeholder={{context.placeholder_search}} name={{context.placeholder_search}} id='inputsearch'>
</div>
</form>
Anyone knows how to translate a placeholder?
有人知道如何翻译占位符吗?
更多回答
优秀答案推荐
I think what you need to do is place quotation marks around the translated message like this:
我认为您需要做的是在翻译后的消息两边加引号,如下所示:
<input type="search" class="form-control home_search rounded-end" placeholder="{% translate "placeholder text here nicely..." %}" name='keyword' id='inputsearch'>
更多回答
It is a beginners mistake but I am self-taugh beginner so... thanks so much for helping me out!
这是一个初学者的错误,但我是一个自以为是的初学者,所以…非常感谢你帮我走出困境!
我是一名优秀的程序员,十分优秀!