-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added internationalization option
- Loading branch information
Showing
10 changed files
with
181 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
baseProject/src/i18n/ChangeLanguageButton/ChangeLanguage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { FC, useState } from 'react'; | ||
import { StyleSheet, Text, TouchableOpacity } from 'react-native'; | ||
import { bg, en } from '../locals'; | ||
import i18next from '../i18n.config'; | ||
|
||
interface ChangeLanguageProps {} | ||
|
||
const ChangeLanguage: FC<ChangeLanguageProps> = () => { | ||
const [selectedLocal, setSelectedLocal] = useState(en.locale); | ||
|
||
const handlePress = () => { | ||
const newLocal = selectedLocal === en.locale ? bg.locale : en.locale; | ||
i18next.changeLanguage(newLocal); | ||
setSelectedLocal(newLocal); | ||
}; | ||
|
||
return ( | ||
<TouchableOpacity onPress={handlePress} style={styles.container}> | ||
<Text>{selectedLocal}</Text> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
marginHorizontal: 10, | ||
}, | ||
}); | ||
|
||
export default ChangeLanguage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import i18next from 'i18next'; | ||
import { initReactI18next } from 'react-i18next'; | ||
import { bg, en } from './locals'; | ||
|
||
export const resources = { | ||
en: { | ||
translation: en, | ||
}, | ||
bg: { | ||
translation: bg, | ||
}, | ||
}; | ||
|
||
i18next.use(initReactI18next).init({ | ||
debug: true, | ||
resources: resources, | ||
lng: 'en', | ||
fallbackLng: 'en', | ||
compatibilityJSON: 'v3', | ||
}); | ||
|
||
export default i18next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"locale": "bg", | ||
"Step One": "Първа стъпка", | ||
"Edit": "Редактирай", | ||
"Screen Change": ", за да промениш този екран и после се върни, за да видиш промените си.", | ||
"See Your Changes": "Виж промените си", | ||
"Press": "Натисни", | ||
"Reload": ", за да презаредиш промените в кода.", | ||
"Simulator": "в симулатора", | ||
"Debug": "Отстраняване на грешки", | ||
"Or": "или", | ||
"Shake": "разтърси", | ||
"Dev Menu": "устройство си, за да отвориш менюто за разработчици.", | ||
"Learn More": "Научи повече", | ||
"Read Docs": "Прочети документацията, за да научиш какво да правиш нататък:" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"locale": "en", | ||
"Step One": "Step One", | ||
"Edit": "Edit", | ||
"Screen Change": "to change this screen and then come back to see your edits.", | ||
"See Your Changes": "See Your Changes", | ||
"Press": "Press", | ||
"Reload": "to reload your app's code.", | ||
"Simulator": "in the simulator", | ||
"Debug": "Debug", | ||
"Or": "or", | ||
"Shake": "Shake", | ||
"Dev Menu": "your device to open the Dev Menu.", | ||
"Learn More": "Learn More", | ||
"Read Docs": "Read the docs to discover what to do next:" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as en } from './en.json'; | ||
export { default as bg } from './bg.json'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters