From 84a31b3520dee9a67d4d24bbbd256f2de3ee48f6 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Mon, 8 Apr 2024 14:04:44 +0100 Subject: [PATCH] Broadcast when the language changes This is left open to future additions, by naming it 'locale', and having the language just be an object field. Side note, maybe we should have a LocaleService for this? --- src/helpers.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/helpers.js b/src/helpers.js index a8486d11..7a8731b8 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -722,7 +722,14 @@ window.mutate_user_preferences = function(user_preferences_delta) { window.update_user_preferences = function(user_preferences) { window.user_preferences = user_preferences; localStorage.setItem('user_preferences', JSON.stringify(user_preferences)); - window.locale = user_preferences.language ?? 'en'; + const language = user_preferences.language ?? 'en'; + window.locale = language; + + // Broadcast locale change to apps + const broadcastService = globalThis.services.get('broadcast'); + broadcastService.sendBroadcast('localeChanged', { + language: language, + }, { sendToNewAppInstances: true }); } window.sendWindowWillCloseMsg = function(iframe_element) {