From 075e63f9b5130aa71e0cf44dff3b700bb7324956 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 24 Jul 2021 21:39:14 +0100 Subject: [PATCH] :fire: Adds language into Config handlers --- src/utils/ConfigAccumalator.js | 3 +++ src/utils/ConfigHelpers.js | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/utils/ConfigAccumalator.js b/src/utils/ConfigAccumalator.js index a93efb51..1237897c 100644 --- a/src/utils/ConfigAccumalator.js +++ b/src/utils/ConfigAccumalator.js @@ -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; } diff --git a/src/utils/ConfigHelpers.js b/src/utils/ConfigHelpers.js index a1848b66..d282c297 100644 --- a/src/utils/ConfigHelpers.js +++ b/src/utils/ConfigHelpers.js @@ -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; +};