Skip to content

rabiloo/react-native-language-provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚩 Language-Provider

Wrapper of Context for Language.


Language-Provider example app.

Usage

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:


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>
  );
};

Properties

data?: object

Source for App Language.e.g.

data={{
        en: {
          title: 'English',
        },
        vi: {
          title: 'Tiếng Việt',
        },
      }}

cache?: boolean

Save your current language code to AsyncStorage

language code: en, vi....based on your define

Supported React Native Versions

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.

Licenses

MIT RABILOO

About

Wrapper of context for Language

Resources

Security policy

Stars

Watchers

Forks

Packages

No packages published