You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/components/AssemblyLine/translation.md
+34-1Lines changed: 34 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,6 +54,9 @@ this.
54
54
55
55
## Variables used in translated interviews
56
56
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
+
57
60
*`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.
58
61
*`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".
59
62
*`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 `&`.
172
175
(this is a standard part of URL arguments).
173
176
:::
174
177
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
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
+
175
208
## A complete example
176
209
177
210
```yaml
@@ -249,4 +282,4 @@ If a language code is not listed in `languages.yml`, the Assembly Line functions
249
282
250
283
You can read more about the stock language features in the official Docassemble [language features documentation](https://docassemble.org/docs/language.html).
251
284
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