embroidery-viewer/src/lib/translations/index.js

270 lines
7.6 KiB
JavaScript

import i18n from 'sveltekit-i18n';
/**
* A frozen object mapping locale identifiers to their respective locale codes.
*
* These values represent the supported languages in the application.
* Used for validating user preferences and loading the correct translations.
*
* @readonly
* @enum {string}
*/
export const SUPPORTED_LOCALES = Object.freeze({
EN_US: 'en-US',
PT_BR: 'pt-BR',
});
/** @type {import('sveltekit-i18n').Config} */
const config = {
initLocale: SUPPORTED_LOCALES.EN_US,
fallbackLocale: SUPPORTED_LOCALES.EN_US,
loaders: [
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'header',
loader: async () => (await import('./en-US/header.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'footer',
loader: async () => (await import('./en-US/footer.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'home',
routes: ['/'],
loader: async () => (await import('./en-US/home.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'about',
routes: ['/about'],
loader: async () => (await import('./en-US/about.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'support-us',
routes: ['/support-us'],
loader: async () => (await import('./en-US/support-us.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'privacy.policy',
routes: ['/privacy-policy'],
loader: async () => (await import('./en-US/privacy-policy.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'mobile.app.privacy.policy',
routes: ['/mobile-app/privacy-policy'],
loader: async () =>
(await import('./en-US/mobile-app-privacy-policy.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'terms.of.service',
routes: ['/terms-of-service'],
loader: async () =>
(await import('./en-US/terms-of-service.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'viewer',
routes: ['/viewer'],
loader: async () => (await import('./en-US/viewer.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'pes-file-viewer',
routes: ['/pes-file-viewer'],
loader: async () =>
(await import('./en-US/pes-file-viewer.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'dst-file-viewer',
routes: ['/dst-file-viewer'],
loader: async () =>
(await import('./en-US/dst-file-viewer.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'jef-file-viewer',
routes: ['/jef-file-viewer'],
loader: async () =>
(await import('./en-US/jef-file-viewer.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'exp-file-viewer',
routes: ['/exp-file-viewer'],
loader: async () =>
(await import('./en-US/exp-file-viewer.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'embroidery-viewer-android',
routes: ['/embroidery-viewer-android'],
loader: async () =>
(await import('./en-US/embroidery-viewer-android.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'header',
loader: async () => (await import('./pt-BR/header.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'footer',
loader: async () => (await import('./pt-BR/footer.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'home',
routes: ['/'],
loader: async () => (await import('./pt-BR/home.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'about',
routes: ['/about'],
loader: async () => (await import('./pt-BR/about.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'support-us',
routes: ['/support-us'],
loader: async () => (await import('./pt-BR/support-us.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'privacy.policy',
routes: ['/privacy-policy'],
loader: async () => (await import('./pt-BR/privacy-policy.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'mobile.app.privacy.policy',
routes: ['/mobile-app/privacy-policy'],
loader: async () =>
(await import('./pt-BR/mobile-app-privacy-policy.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'terms.of.service',
routes: ['/terms-of-service'],
loader: async () =>
(await import('./pt-BR/terms-of-service.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'viewer',
routes: ['/viewer'],
loader: async () => (await import('./pt-BR/viewer.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'pes-file-viewer',
routes: ['/pes-file-viewer'],
loader: async () =>
(await import('./pt-BR/pes-file-viewer.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'dst-file-viewer',
routes: ['/dst-file-viewer'],
loader: async () =>
(await import('./pt-BR/dst-file-viewer.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'jef-file-viewer',
routes: ['/jef-file-viewer'],
loader: async () =>
(await import('./pt-BR/jef-file-viewer.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'exp-file-viewer',
routes: ['/exp-file-viewer'],
loader: async () =>
(await import('./pt-BR/exp-file-viewer.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'embroidery-viewer-android',
routes: ['/embroidery-viewer-android'],
loader: async () =>
(await import('./pt-BR/embroidery-viewer-android.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'hero',
loader: async () => (await import('./pt-BR/hero.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'hero',
loader: async () => (await import('./en-US/hero.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'features',
loader: async () => (await import('./pt-BR/features.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'features',
loader: async () => (await import('./en-US/features.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'faq',
loader: async () => (await import('./pt-BR/faq.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'faq',
loader: async () => (await import('./en-US/faq.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'mobile',
loader: async () => (await import('./pt-BR/mobile.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'mobile',
loader: async () => (await import('./en-US/mobile.json')).default,
},
{
locale: SUPPORTED_LOCALES.PT_BR,
key: 'announcement',
loader: async () => (await import('./pt-BR/announcement.json')).default,
},
{
locale: SUPPORTED_LOCALES.EN_US,
key: 'announcement',
loader: async () => (await import('./en-US/announcement.json')).default,
},
],
};
export const {
t,
locale,
locales,
loading,
loadTranslations,
setRoute,
setLocale,
} = new i18n(config);
locale.subscribe(($locale) => {
if (typeof localStorage !== 'undefined' && $locale) {
const existing = localStorage.getItem('locale');
if (existing !== $locale) {
localStorage.setItem('locale', $locale);
}
}
});