Implement multilingual support by integrating i18n for dynamic text rendering across the app. Added language selection modal in HomeScreen and updated various components to utilize localized strings. Updated package dependencies for async storage and localization.

This commit is contained in:
2025-08-16 22:24:47 +05:00
parent 0f8c9b5e55
commit e431c42df1
13 changed files with 460 additions and 38 deletions

29
i18n.ts Normal file
View File

@@ -0,0 +1,29 @@
import { I18n } from 'i18n-js';
import * as Localization from 'expo-localization';
import AsyncStorage from '@react-native-async-storage/async-storage';
import en from './locales/en.json';
import tk from './locales/tk.json';
import ru from './locales/ru.json';
const i18n = new I18n({
en,
tk,
ru,
});
i18n.enableFallback = true;
// Function to initialize the language
export const initializeLanguage = async () => {
const savedLanguage = await AsyncStorage.getItem('user-language');
if (savedLanguage) {
i18n.locale = savedLanguage;
} else {
// If no language is saved, detect from device and default to Turkmen
const userLanguageCode = Localization.getLocales()[0]?.languageCode;
i18n.locale = ['en', 'tk', 'ru'].includes(userLanguageCode || '') ? userLanguageCode! : 'tk';
}
};
export default i18n;