🔥 Adds language into Config handlers

This commit is contained in:
Alicia Sykes 2021-07-24 21:39:14 +01:00
parent 1faa36f7df
commit 075e63f9b5
2 changed files with 22 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import {
pageInfo as defaultPageInfo,
iconSize as defaultIconSize,
layout as defaultLayout,
language as defaultLanguage,
} from '@/utils/defaults';
import conf from '../../public/conf.yml';
@ -33,6 +34,8 @@ export default class ConfigAccumulator {
|| appConfigFile.layout || defaultLayout;
usersAppConfig.iconSize = localStorage[localStorageKeys.ICON_SIZE]
|| appConfigFile.iconSize || defaultIconSize;
usersAppConfig.language = localStorage[localStorageKeys.LANGUAGE]
|| appConfigFile.language || defaultLanguage;
return usersAppConfig;
}

View File

@ -1,5 +1,11 @@
import ConfigAccumulator from '@/utils/ConfigAccumalator';
import { visibleComponents, localStorageKeys, theme as defaultTheme } from '@/utils/defaults';
import { languages } from '@/utils/languages';
import {
visibleComponents,
localStorageKeys,
theme as defaultTheme,
language as defaultLanguage,
} from '@/utils/defaults';
/**
* Initiates the Accumulator class and generates a complete config object
@ -74,3 +80,15 @@ export const getCustomKeyShortcuts = () => {
});
return results.flat();
};
/**
* Gets the users chosen language. Defaults to English.
* @returns {object} Language, including code, name and flag
*/
export const getUsersLanguage = () => {
const langCode = localStorage[localStorageKeys.LANGUAGE]
|| config.appConfig.language
|| defaultLanguage;
const langObj = languages.find(lang => lang.code === langCode);
return langObj;
};