localization_form
Generates a form for country or region switching or language switching.
This form is applicable to the following scenarios:
- Country or region selector
- Language selector
{{#localization_form}} custom code {{/localization_form}}
Optional params
return_to string: The redirect URL after form submission. Defaults to the current page.
Examples
Country or region selector
The form submission field is country_code, and its value is the corresponding country or region code. You can obtain it from the iso_code field of each country or region object by iterating through the localization.available_countries list.
{{#localization_form enctype="multipart/form-data" accept-charset="UTF-8"}}
<select name="country_code" onchange="this.form.submit();">
{{#for country in localization.available_countries}}
<option value="{{country.iso_code}}" {{#if localization.country.iso_code == country.iso_code}}selected{{/if}}>
{{country.name}}({{country.currency.iso_code}}
{{country.currency.symbol}})
</option>
{{/for}}
</select>
{{/localization_form}}
Language selector
The form submission field is locale_code, and its value is the corresponding language code. You can obtain it from the iso_code field of each language object by iterating through the localization.available_languages list.
{{#localization_form enctype="multipart/form-data" accept-charset="UTF-8"}}
<select name="locale_code" onchange="this.form.submit();">
{{#for language in localization.available_languages}}
<option value="{{language.iso_code}}" {{#if localization.language.endonym_name == language.endonym_name}}selected{{/if}}>
{{language.endonym_name}}
</option>
{{/for}}
</select>
{{/localization_form}}
Adding HTML attributes
Pass in standard HTML form attributes, such as name and accept-charset.
{{#localization_form id="localization-form" enctype="multipart/form-data" accept-charset="UTF-8"}}
custom code
{{/localization_form}}
Was this article helpful to you?