aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorAdrien Hopkins <[email protected]>2022-07-29 15:27:20 -0500
committerAdrien Hopkins <[email protected]>2022-07-29 15:27:20 -0500
commit11c725b7ac41fe75b54732b19814cffafdb2e7f9 (patch)
tree53e357f725becc1f3d5fe10e8105879df7aae18f /src/lib
parentf542f2f59eb1d4d6b1e04973d134901c2f9d02be (diff)
downloadcoinos-ui-11c725b7ac41fe75b54732b19814cffafdb2e7f9.tar.gz
coinos-ui-11c725b7ac41fe75b54732b19814cffafdb2e7f9.zip
Documented locale code
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/i18n.js23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/lib/i18n.js b/src/lib/i18n.js
index d3db2454..2d39e292 100644
--- a/src/lib/i18n.js
+++ b/src/lib/i18n.js
@@ -1,14 +1,25 @@
import { register, init, getLocaleFromNavigator } from 'svelte-i18n';
-// list of locales to load
+/** The list of locales to look for */
const localeCodes = ['en', 'fr'];
-// load locales
+/** The directory where locale files are stored */
+const localeDirectory = "../locales";
+
+/**
+ * Adds a new locale from the appropriate JSON file
+ * @param {string} localeCode - the code of the locale to add
+ */
function addLocale(localeCode) {
- register(localeCode, () => import(`../locales/${localeCode}.json`));
+ register(localeCode, () => import(`${localeDirectory}/${localeCode}.json`));
}
-// determine locale
+/**
+ * Determines the default locale.
+ * @param {string} navigatorLocale - the locale given by the navigator
+ * @param {array<string>} avalableLocales - a list of the available locales
+ * @returns {string} chosen default locale
+ */
function pickLocale(navigatorLocale, availableLocales) {
// determine langugage part of locale
// (e.g. if navigatorLocale is 'en-US', languageCode is 'en')
@@ -30,7 +41,9 @@ function pickLocale(navigatorLocale, availableLocales) {
}
}
-// setup internationalization
+/**
+ * Loads all of the locales, picks a default locale, and sets up internationalization in that locale.
+ */
export function setupI18n() {
localeCodes.forEach(addLocale);
let initialLocale = pickLocale(getLocaleFromNavigator(), localeCodes);