Internationalization | Django LiveView

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.

async def send_page(consumer, client_data, lang=None):

Or you could read it with the lang key of the client_data parameter.

async def send_page(consumer, client_data):

You can read the tutorial Internationalize with subdomains to see how to create a multilingual website with subdomains.