Skip to content

Commit

Permalink
Merge pull request #138 from SondreNjaastad/base
Browse files Browse the repository at this point in the history
Presist language user_preference
  • Loading branch information
jelveh authored Mar 19, 2024
2 parents 0f867d9 + ae335df commit 6e5b97d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/UI/UIDesktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 2 additions & 5 deletions src/i18n/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/initgui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6e5b97d

Please sign in to comment.