Skip to content

Commit b653ca6

Browse files
Add comprehensive language/internationalization documentation
Co-authored-by: nonprofittechy <7645641+nonprofittechy@users.noreply.github.com>
1 parent 7651f65 commit b653ca6

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

docs/components/AssemblyLine/magic_variables.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ your interviews directly or via a shared YAML file.
199199

200200
### Localization and translation variables
201201

202+
These variables are used for basic address and language configuration.
203+
For the Assembly Line's advanced language switching system, see the
204+
[Assembly Line language system variables](#assembly-line-language-system-variables)
205+
section below and the [translation documentation](translation.md).
206+
202207
* `AL_DEFAULT_COUNTRY`: [ISO 3166](https://en.wikipedia.org/wiki/ISO_3166) 2
203208
letter code representing the default country of the interview user for address
204209
questions. E.g., `US` for United States of America, `UK` for United Kingdom of
@@ -390,6 +395,59 @@ choose to define this value on an organization-wide basis by placing it in a
390395
shared YAML file, such as the YAML that defines your theme or other branding
391396
elements.
392397

398+
### Assembly Line language system variables
399+
400+
These variables control the Assembly Line's built-in language switching system
401+
defined in `al_language.yml`. See the [translation documentation](translation.md)
402+
for complete usage examples.
403+
404+
#### `enable_al_language`
405+
406+
Controls whether the Assembly Line language system is active. Defaults to `True`.
407+
Set to `False` to disable the language switching functionality if you need to use
408+
a custom language system.
409+
410+
```yaml
411+
code: |
412+
enable_al_language = True
413+
```
414+
415+
#### `al_user_default_language`
416+
417+
The default language code (ISO 639-1 format) to use when a user hasn't selected
418+
a specific language. Defaults to `"en"` (English).
419+
420+
```yaml
421+
code: |
422+
al_user_default_language = "es" # Default to Spanish
423+
```
424+
425+
#### `al_interview_languages`
426+
427+
A list of language codes (ISO 639-1 format) that your interview supports.
428+
When this list contains more than one language, the Assembly Line will
429+
automatically show a language selection dropdown in the navigation bar.
430+
431+
```yaml
432+
code: |
433+
al_interview_languages = ["en", "es", "fr"] # English, Spanish, French
434+
```
435+
436+
#### `al_user_language`
437+
438+
The currently selected language for the user. This is typically set automatically
439+
through the language selection interface or URL parameters, but can be set directly
440+
if needed.
441+
442+
#### `al_change_language` (event)
443+
444+
An event triggered when the user clicks a language selection link. The event
445+
handler automatically updates `al_user_language` based on the `lang` action
446+
argument and calls Docassemble's `set_language()` function.
447+
448+
This event is used internally by the language switching functions like
449+
`get_language_list_dropdown()` and `get_language_list()`.
450+
393451
## Run-time options
394452

395453
These options are ones that you can sometimes configure when you author the

docs/components/AssemblyLine/translation.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ this.
5454

5555
## Variables used in translated interviews
5656

57+
These variables control the Assembly Line's language system. For a complete list of
58+
all Assembly Line special variables, see [Special variables](magic_variables.md).
59+
5760
* `enable_al_language`: defaults to True, turning it off can partially ensure the language system in AssemblyLine doesn't interfere with existing language systems. It should be relatively easy for authors to migrate to this new system though.
5861
* `al_user_default_language`: can be controlled by interview author, this determines the language when the user makes no selection of their own. Defaults to "en".
5962
* `al_interview_languages`: a list of language codes, presumably ISO-639-1 (Alpha-2), like ["en","es"] etc. The Assembly Line also contains a translation of several common language codes into the native-language version of the language (e.g., `es` is translated as `Español`).
@@ -172,6 +175,36 @@ If the URL already has a `?` in it, replace the `?` with an `&`.
172175
(this is a standard part of URL arguments).
173176
:::
174177

178+
## The `al_change_language` event
179+
180+
The Assembly Line language system uses a special event called `al_change_language`
181+
to handle language switching. This event is triggered automatically when a user
182+
clicks on a language selection link generated by functions like
183+
`get_language_list_dropdown()` or `get_language_list()`.
184+
185+
When the event is triggered, it:
186+
187+
1. Reads the `lang` parameter from the action arguments
188+
2. Sets `al_user_language` to the selected language code
189+
3. Calls Docassemble's `set_language()` function to apply the language change
190+
191+
You normally don't need to handle this event directly, as it's managed automatically
192+
by the language switching functions. However, if you want to add custom behavior
193+
when languages are switched, you can define additional logic after the language
194+
change:
195+
196+
```yaml
197+
event: al_change_language
198+
code: |
199+
# The built-in language switching happens first
200+
if 'lang' in action_arguments():
201+
al_user_language = action_argument('lang')
202+
set_language(al_user_language)
203+
204+
# Add your custom logic here
205+
log(f"User switched to language: {al_user_language}")
206+
```
207+
175208
## A complete example
176209

177210
```yaml
@@ -249,4 +282,4 @@ If a language code is not listed in `languages.yml`, the Assembly Line functions
249282

250283
You can read more about the stock language features in the official Docassemble [language features documentation](https://docassemble.org/docs/language.html).
251284

252-
Also, see the documentation for the [AL language module](components/AssemblyLine/language.md)
285+
Also, see the documentation for the [AL language module](language.md) for complete API documentation of all language-related functions.

0 commit comments

Comments
 (0)