Wrapper of Context for Language.
Language-Provider example app.
Note: You must be using React Native 0.60.0 or higher to use the most recent version of @rabiloo/react-native-language-provider
.
Install AsyncStorage:
Install react-native-localize:
Follow react-native-localize
yarn add @rabiloo/react-native-language-provider
OR FROM GIT
yarn add https://github.com/rabiloo/react-native-language-provider.git
- Step 1: Wrapper your App Root
import {LanguageContainer} from '@rabiloo/react-native-language-provider';
const App = () => (
<LanguageContainer
cache={true}
data={{
en: {
title: 'English',
},
vi: {
title: 'Tiếng Việt',
},
}}
initialLanguageCode={'en'}>
<Demo />
</LanguageContainer>
)
- Step 2: use useLanguageString hook to get Strings data
import {
useLanguageString,
LanguageService,
} from '@rabiloo/react-native-language-provider';
const Demo = () => {
const {Strings, setLanguageCode} = useLanguageString();
return (
<View
style={{
flex:1,
}}>
<Text
style={{ fontSize: 40}}
onPress={() => {
//your current language code
const currentLanguageCode = LanguageService.getLanguageCode();
//set to new language code, all app will be updated
setLanguageCode({
languageCode: currentLanguageCode === 'en' ? 'vi' : 'en',
});
}}>
{Strings.title}
</Text>
</View>
);
};
Source for App Language.e.g.
data={{
en: {
title: 'English',
},
vi: {
title: 'Tiếng Việt',
},
}}
Save your current language code to AsyncStorage
language code: en, vi....based on your define
This project only aims to support the latest version of React Native.
This simplifies the development and the testing of the project.
If you require new features or bug fixes for older versions you can fork this project.
MIT RABILOO