Strategies
All the features of the framework are optional, following a declarative "opt-in" configuration method.
- Loading the initial language of the user
- CSR | Updating the language on the client
- CSR | Updating the language from initialization on the client
- CSR | Client side effects
- CSR + SSR | Names
Loading the initial language of the user
The initial language of the user can be set in different ways:
Strategy | CSR | SSR | Desktop | leptos_fluent! |
---|---|---|---|---|
URL parameter | ✅ | ✅ | ❌ | initial_language_from_url_param |
Cookie | ✅ | ✅ | ❌ | initial_language_from_cookie |
Server function | ✅ | ✅ | ❌ | initial_language_from_server_function |
Browser local storage | ✅ | ❌ | ❌ | initial_language_from_localstorage |
Browser navigator.languages | ✅ | ❌ | ❌ | initial_language_from_navigator |
Accept-Language header | ❌ | ✅ | ❌ | initial_language_from_accept_language_header |
System language | ❌ | ❌ | ✅ | initial_language_from_system |
Data file | ❌ | ❌ | ✅ | initial_language_from_data_file |
All of them can be defined at the same time or just one of them at the same time. The first language source found will be used and nexts discharged. The order of precedence is:
- SSR
- CSR
- Server function
- URL parameter
- Cookie
- Browser local storage
- Browser
navigator.languages
- Desktop (
system
feature)- Data file
- System language
CSR | Updating the language on the client
When the user changes the language and I18n::language.set
is called, the
framework can perform a side effect to update the language in the client. The
following strategies are available:
Strategy | leptos_fluent! |
---|---|
URL parameter | set_language_to_url_param |
Cookie | set_language_to_cookie |
Browser local storage | set_language_to_localstorage |
Server function | set_language_to_server_function |
system | Desktop applications
Strategy | leptos_fluent! |
---|---|
Data file | set_language_to_data_file |
CSR | Updating the language from initialization on the client
When a language is loaded from initialization, the framework can perform a side effect to persistently storage the language in the client. The following strategies are available:
Strategy | leptos_fluent! |
---|---|
URL parameter to local storage | initial_language_from_url_param_to_localstorage |
URL parameter to cookie | initial_language_from_url_param_to_cookie |
Cookie to local storage | initial_language_from_cookie_to_localstorage |
Local storage to cookie | initial_language_from_localstorage_to_cookie |
Local storage to server function | initial_language_from_localstorage_to_server_function |
navigator.languages to local storage | initial_language_from_navigator_to_localstorage |
navigator.languages to cookie | initial_language_from_navigator_to_cookie |
navigator.languages to server function | initial_language_from_navigator_to_server_function |
Server function to local storage | initial_language_from_server_function_to_localstorage |
CSR + SSR
Strategy | leptos_fluent! |
---|---|
URL parameter to server function | initial_language_from_url_param_to_server_function |
Cookie to server function | initial_language_from_cookie_to_server_function |
Server function to cookie | initial_language_from_server_function_to_cookie |
system | Desktop applications
Strategy | leptos_fluent! |
---|---|
System language to data file | initial_language_from_system_to_data_file |
CSR | Client side effects
When the user updates the language, the framework can perform side effects to update the language in the client. The following side effects are available:
Side effect | leptos_fluent! |
---|---|
<html lang="..."> attribute | sync_html_tag_lang |
<html dir="..."> attribute | sync_html_tag_dir |
CSR + SSR | Names
The names of the settings can be configured using the following parameters:
Strategy | leptos_fluent! | Default value |
---|---|---|
Cookie | cookie_name | "lf-lang" |
Cookie attributes | cookie_attrs | "" |
Browser local storage | localstorage_key | "lang" |
URL parameter | url_param | "lang" |
system | Desktop applications
Strategy | leptos_fluent! | Default value |
---|---|---|
Data file | data_file_key | "leptos-fluent" |