fitst commit
This commit is contained in:
37
i18n/i18n.ts
Normal file
37
i18n/i18n.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
// i18n.ts
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
|
||||
import en from './locales/en.json';
|
||||
import ru from './locales/ru.json';
|
||||
import uz from './locales/uz.json';
|
||||
|
||||
const languageDetector = {
|
||||
type: 'languageDetector' as const,
|
||||
async: true,
|
||||
detect: async (callback: (lang: string) => void) => {
|
||||
const savedLang = await AsyncStorage.getItem('lang');
|
||||
callback(savedLang || 'uz');
|
||||
},
|
||||
init: () => {},
|
||||
cacheUserLanguage: async (lang: string) => {
|
||||
await AsyncStorage.setItem('lang', lang);
|
||||
},
|
||||
};
|
||||
|
||||
i18n
|
||||
.use(languageDetector as any)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
resources: {
|
||||
uz: { translation: uz },
|
||||
ru: { translation: ru },
|
||||
en: { translation: en },
|
||||
},
|
||||
fallbackLng: 'uz',
|
||||
interpolation: { escapeValue: false },
|
||||
react: { useSuspense: false },
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
Reference in New Issue
Block a user