From 0a74db568c21d44f785ccd8824d73695d05975b4 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Sun, 24 Mar 2024 14:05:32 +0300 Subject: [PATCH] [mobile] add localization support --- mobile/App.tsx | 5 ++++- mobile/index.js | 1 + mobile/src/localization/en.ts | 5 +++++ mobile/src/localization/i18n.ts | 21 +++++++++++++++++++++ mobile/src/localization/tr.ts | 5 +++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 mobile/src/localization/en.ts create mode 100644 mobile/src/localization/i18n.ts create mode 100644 mobile/src/localization/tr.ts diff --git a/mobile/App.tsx b/mobile/App.tsx index badfa05..d294934 100644 --- a/mobile/App.tsx +++ b/mobile/App.tsx @@ -4,6 +4,7 @@ import { View, Text, Button } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import type { NativeStackScreenProps } from '@react-navigation/native-stack'; +import { useTranslation } from 'react-i18next'; type RootStackParamList = { Home: undefined, @@ -25,9 +26,11 @@ function HomeScreen({ navigation, route }: HomeScreenProps) { } function LobyScreen({ navigation, route }: LobyScreenProps) { + const { t } = useTranslation(); + return ( - Loby Screen + {t('hello')} ); } diff --git a/mobile/index.js b/mobile/index.js index a850d03..cf7e487 100644 --- a/mobile/index.js +++ b/mobile/index.js @@ -5,5 +5,6 @@ import {AppRegistry} from 'react-native'; import App from './App'; import {name as appName} from './app.json'; +import './src/localization/i18n'; AppRegistry.registerComponent(appName, () => App); diff --git a/mobile/src/localization/en.ts b/mobile/src/localization/en.ts new file mode 100644 index 0000000..e23e378 --- /dev/null +++ b/mobile/src/localization/en.ts @@ -0,0 +1,5 @@ +export default { + translation: { + hello: 'Hello', + } +}; \ No newline at end of file diff --git a/mobile/src/localization/i18n.ts b/mobile/src/localization/i18n.ts new file mode 100644 index 0000000..f8fc9d6 --- /dev/null +++ b/mobile/src/localization/i18n.ts @@ -0,0 +1,21 @@ +// https://medium.com/@yashpalraj/implement-i18n-in-react-native-application-a4c573e2e2a6 + +import i18n from 'i18next'; +import { initReactI18next } from 'react-i18next'; +import en from './en'; +import tr from './tr'; +const resources = { // list of languages + en, + tr, +}; +i18n.use(initReactI18next) // passes i18n down to react-i18next + .init({ + compatibilityJSON: 'v3', //To make it work for Android devices, add this line. + resources, + lng: 'en', // default language to use. + // if you're using a language detector, do not define the lng option + interpolation: { + escapeValue: false, + }, + }); +export default i18n; \ No newline at end of file diff --git a/mobile/src/localization/tr.ts b/mobile/src/localization/tr.ts new file mode 100644 index 0000000..308ddc5 --- /dev/null +++ b/mobile/src/localization/tr.ts @@ -0,0 +1,5 @@ +export default { + translation: { + hello: 'Merhaba', + } +}; \ No newline at end of file