Add dark mode support (#16)
This commit is contained in:
1 parent
ddef4cec2a
commit
b8970e1373
46 files changed
+247
-166
No files matched your search
@@ -2,6 +2,10 @@ import { createI18n, I18n } from 'vue-i18n';
|
||||
import { nextTick } from 'vue';
|
||||
import axios from 'axios';
|
||||
|
||||
declare namespace Intl {
|
||||
function getCanonicalLocales(locales: string | string[] | undefined): string[];
|
||||
}
|
||||
|
||||
export const DEFAULT_LOCALE = 'en';
|
||||
|
||||
export const SUPPORTED_LOCALES = [
|
||||
@@ -43,6 +47,24 @@ export const loadLocalResource = async (name: string, locale: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getLocale = (): string => {
|
||||
const canonicalLang = Intl.getCanonicalLocales(navigator.language)?.[0];
|
||||
const supportedLocales = SUPPORTED_LOCALES.map((locale) => locale.value);
|
||||
// if the canonical language is supported, use it
|
||||
if (canonicalLang && supportedLocales.includes(canonicalLang)) {
|
||||
console.debug('canonicalLang', canonicalLang);
|
||||
return canonicalLang;
|
||||
} else {
|
||||
// if the canonical language prefix is supported, use it
|
||||
const canonicalLangPrefix = canonicalLang?.split('-')?.[0];
|
||||
if (canonicalLangPrefix && supportedLocales.includes(canonicalLangPrefix)) {
|
||||
console.debug('canonicalLangPrefix', canonicalLangPrefix);
|
||||
return canonicalLangPrefix;
|
||||
}
|
||||
}
|
||||
return DEFAULT_LOCALE;
|
||||
};
|
||||
|
||||
export const loadLocaleMessages = async (i18n: I18n, locale: string) => {
|
||||
const names = [
|
||||
'api',
|
||||
|
||||
Reference in new issue
Block a user