Translations
Default behaviour
The hanko-elements
package includes English translations by default and the lang
attribute can be omitted.
Script
Markup
Installing Additional Translations
Translations are currently available for the following languages:
Value | Language |
---|---|
bn | Bengali (Bangla) |
de | German |
en | English |
fr | French |
it | Italian |
pt-BR | Brazilian Portuguese |
zh | Chinese |
You can import them individually:
Or import all translations at once:
After importing, provide the translations through the register()
function:
You can now set the lang
attribute of the element to the desired language:
In contrast to the named import of the translation object for Brazilian Portuguese (“ptBR”), the lang
attribute
value must be provided as “pt-BR”. Otherwise the language is not recognized by the backend and outgoing emails will
default to English.
Modifying Translations
You can modify existing translations as follows
Adding New Translations
If you need to create a new translation, pass an object that implements (or partially implements) the Translation
interface.
Script
Markup
Using External Files
For languages provided via the element’s lang attribute, or via the fallback language option, that are not included in
the object passed to the translations
option, the component will fetch a JSON file from the location specified by the
translationsLocation
option. For example, if “en” is missing due to an empty object being passed, as shown in the
example below, the component will fetch a file named /i18n/en.json
.
Script
Markup
Fallback Language
The fallbackLanguage
option is used to specify a fallback language for the web components when translations are
missing or incomplete for a particular language. By setting the fallbackLanguage
option to a valid language string
like “en” or “de”, the missing translation strings will be automatically retrieved from the specified fallback language.
When the translation for the specified fallbackLanguage
is not available in the translations
option, the web
components will attempt to fetch it from an external file.
Script
Markup
Translation of outgoing emails
If you use Hanko Elements the language supplied to the lang
attribute of any of the components is also used to convey
to the Hanko API the language to use for outgoing emails. If you have disabled email delivery through Hanko and
configured a webhook for the email.send
event, the value for the lang
attribute is reflected in the JWT payload of
the token contained in the webhook request in the language
claim.
If you do not use Hanko Elements but use the Hanko Frontend SDK to build your own UI you can provide a lang
option when instantiating the main
Hanko
client. Again, if you choose to
opt out of email delivery by Hanko and subscribe to the email.send
event via webhook, the value used as the argument
is reflected in the JWT payload of the token contained in the webhook request in the language
claim.
If you do not use the Hanko frontend SDK but communicate with the Hanko API directly, then you must supply an
X-Language
header to requests targeting the Flow API endpoints
(/registration
,
/login
,
/profile
).
Was this page helpful?