From ae335df11e84cf1b5c832eaaaaac49700ce72c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Nj=C3=A5stad?= Date: Tue, 19 Mar 2024 05:51:01 +0100 Subject: [PATCH] Presist language user_preference --- src/UI/UIDesktop.js | 1 + src/helpers.js | 1 + src/i18n/i18n.js | 7 ++----- src/initgui.js | 3 --- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/UI/UIDesktop.js b/src/UI/UIDesktop.js index 3576fa80..8de879c9 100644 --- a/src/UI/UIDesktop.js +++ b/src/UI/UIDesktop.js @@ -503,6 +503,7 @@ async function UIDesktop(options){ // update local user preferences const user_preferences = { show_hidden_files: (await puter.kv.get('user_preferences.show_hidden_files')) === 'true', + language: (await puter.kv.get('user_preferences.language')) }; update_user_preferences(user_preferences); diff --git a/src/helpers.js b/src/helpers.js index a318fb73..f275342d 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -722,6 +722,7 @@ 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; } window.sendWindowWillCloseMsg = function(iframe_element) { diff --git a/src/i18n/i18n.js b/src/i18n/i18n.js index c3cea967..015cfaf7 100644 --- a/src/i18n/i18n.js +++ b/src/i18n/i18n.js @@ -10,11 +10,8 @@ window.i18n = function (key, replacements = [], encode_html = true) { replacements = [replacements]; } - // if locale is not set, default to en - if(!translations[window.locale]) - window.locale = 'en'; - - let str = translations[window.locale].dictionary[key]; + let language = translations[window.locale] ?? translations['en']; + let str = language.dictionary[key] ?? translations['en'].dictionary[key]; if (!str) { str = key; diff --git a/src/initgui.js b/src/initgui.js index b01bd6f1..5b0171b6 100644 --- a/src/initgui.js +++ b/src/initgui.js @@ -46,9 +46,6 @@ window.initgui = async function(){ if(window.api_origin && puter.APIOrigin !== window.api_origin) puter.setAPIOrigin(api_origin); - // determine locale - window.locale = window.user_preferences.language; - // Checks the type of device the user is on (phone, tablet, or desktop). // Depending on the device type, it sets a class attribute on the body tag // to style or script the page differently for each device type.