Django LiveView uses the same internationalization system as Django. You can read more about it in the Django documentation. However, let's go deeper.
Every time that the client sends a request for action, it sends the language that the user has set in the browser.
{
"action": "blog_list->send_page",
"data": {
"lang": "es"
}
}
The lang
attribute is extracted directly from the <html>
tag.
{% load static i18n %}
<!doctype html>{% get_current_language as CURRENT_LANGUAGE %}
<html lang="{{ CURRENT_LANGUAGE }}">
You can access the language with the lang
parameter of the action using the @enable_lang
decorator.
@enable_lang
@loading
async def send_page(consumer, client_data, lang=None):
print(lang)
Or you could read it with the lang
key of the client_data
parameter.
@loading
async def send_page(consumer, client_data):
print(client_data["data"]["lang"])
You can read the tutorial Internationalize with subdomains to see how to create a multilingual website with subdomains.