Add Locale URL

This commit is contained in:
Restray
2022-04-02 16:15:00 +02:00
parent 741db1778b
commit d910b21185
187 changed files with 683 additions and 532 deletions

View File

@@ -1,10 +1,15 @@
import { toast } from '@zerodevx/svelte-toast';
export function errorNotification(message: string) {
import { t } from '$lib/translations';
let formatMessage;
t.subscribe((storeFormat) => (formatMessage = storeFormat));
export function errorNotification(message: string): void {
console.error(message);
if (typeof message !== 'string') {
toast.push('Ooops, something is not okay, are you okay?');
toast.push(formatMessage('error.generic_message'));
} else {
toast.push(message);
toast.push(formatMessage(message));
}
}
export function enhance(

4
src/lib/lang.json Normal file
View File

@@ -0,0 +1,4 @@
{
"en": "English",
"fr": "Français"
}

View File

@@ -1,4 +1,4 @@
export const publicPaths = [
const publicPaths = [
'/login',
'/register',
'/reset',
@@ -8,3 +8,7 @@ export const publicPaths = [
'/webhooks/github/install',
'/webhooks/gitlab'
];
export function isPublicPath(path: string): boolean {
return publicPaths.includes(path);
}

26
src/lib/translations.ts Normal file
View File

@@ -0,0 +1,26 @@
import i18n from 'sveltekit-i18n';
import lang from './lang.json';
/** @type {import('sveltekit-i18n').Config} */
export const config = {
fallbackLocale: 'en',
translations: {
en: { lang },
fr: { lang }
},
loaders: [
{
locale: 'en',
key: '',
loader: async () => (await import('../../static/locales/en.json')).default
},
{
locale: 'fr',
key: '',
loader: async () => (await import('../../static/locales/fr.json')).default
}
]
};
export const { t, loading, locales, locale, loadTranslations } = new i18n(config);
loading.subscribe(($loading) => $loading && console.log('Loading translations...'));