我有一个更改语言的表格(到目前为止,有3种语言),除了页面重新加载时,内容会更改为新语言,但从下拉列表中选择的选项丢失了(而是显示默认语言),它可以工作。页面重新加载后如何保持所选语言?感谢您的帮助
<form action="{% url 'set_language' %}" method="POST">
{% csrf_token %}
<input type="hidden" id="languageSwitcher" name="selected" value="{{ redirect_to}}">
<select name ="language" id="languageField">
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages%}
<option value="{{language.code}}" {% if language.code == LANGUAGE_CODE %} selected {% endif %}>
{{language.name_local}}
</option>
{% endfor %}
</select>
<input type="submit" id ="languageSwitcher" value="Change">
</form>
答案 0 :(得分:1)
要在模板中使用LoginRequest
变量,必须首先加载var result = await _client.LoginAsync(
new LoginRequest{ FrontChannelExtraParameters = new { ui_locales = "en-US" }} );
。
将以下代码行放在html模板的顶部:
"https://demo.identityserver.io/connect/authorize?response_type=code&nonce=20c640......&ui_locales=en-US"
还要确保在设置和上下文处理器中启用了LANGUAGE_CODE
:
i18n