Change i18n package to paraglideJs
also refactor auth provider
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
import { createIsomorphicFn } from '@tanstack/react-start';
|
||||
import { getCookie } from '@tanstack/react-start/server';
|
||||
import i18n from 'i18next';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
import enTranslations from '../locales/en.json';
|
||||
import viTranslations from '../locales/vi.json';
|
||||
|
||||
export const resources = {
|
||||
en: {
|
||||
translation: enTranslations,
|
||||
},
|
||||
vi: {
|
||||
translation: viTranslations,
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const defaultNS = 'translation';
|
||||
|
||||
const i18nCookieName = 'i18nextLng';
|
||||
|
||||
i18n
|
||||
.use(LanguageDetector)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
resources,
|
||||
defaultNS,
|
||||
fallbackLng: 'vi',
|
||||
supportedLngs: ['en', 'vi'],
|
||||
detection: {
|
||||
order: ['cookie'],
|
||||
lookupCookie: i18nCookieName,
|
||||
caches: ['cookie'],
|
||||
cookieMinutes: 60 * 24 * 365,
|
||||
},
|
||||
interpolation: { escapeValue: false },
|
||||
});
|
||||
|
||||
export const setSSRLanguage = createIsomorphicFn().server(async () => {
|
||||
const language = getCookie(i18nCookieName);
|
||||
await i18n.changeLanguage(language || 'vi');
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
Reference in New Issue
Block a user