Example of Localization in React Native Multi Language App

Here is an Example of Localization in React Native Multi Language App. Localization is the process of making something local in character or restricting it to a particular place. In case of application development, it is related to the development of the application according to the local language.

For the localization, we are going to use LocalizedStrings component from react-native-localization library.

How to Use

Here is the code snippet of LocalizedStrings we have used in this Example.

In this example below, we will make a home screen to select the language and will show the text content on the next screen accordingly from a common string repository where we have defined same text for each language code.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Installation of Dependencies

To use LocalizedStrings we need to install react-native-localization dependency and to switch between different screens we are going to use react-native-navigation dependency.

To install these dependencies open the terminal and jump into your project

Run the following command to install react-native-localization

Run the following command to install react-native-navigation

For the new React Navigation 3.+, you also have to install the react-native-gesture-handler using the following command

This command will copy all the dependencies into your node_module directory.

Linking of Dependencies

After the installation of dependencies, you need to link it with your project using

This is an automatic process to link the libraries with the project. If you have any issue or you want to install it manually you can see the process of manual linking of react-native-localization and manual linking of react-native-gesture-handler.

Here we have done with our installation of the dependencies. If you are facing any issue then please comment below so that we can help you out from the problem. Now let’s move towards the code.

You can download the source code from Github

OR

Follow the steps below

We are using the following project structure. So please make the following project structure and replace the code.

App.js

LanguageSelectionScreen.js

ContentScreen.js

stringsoflanguages.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

Android

      

IOS

        

This is how you can make a multi-language React Native Application (Localization). If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

How useful was this post?

Click on a star to rate us!

Average rating / 5. Vote count:

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

0 replies

Leave a Reply

Want to join the discussion?   Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.