Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NextJS
  • Material UI
  • React Bootstrap
  • React Suite
  • Ant Design
  • Reactstrap
  • BlueprintJS
  • React Desktop
  • React Native
  • React Rebass
  • React Spring
  • React Evergreen
  • ReactJS
  • ReactJS
  • JS Formatter
  • Web Technology
Open In App
Next Article:
Language Translator using React
Next article icon

Build a Language Translator App Using React Native

Last Updated : 24 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we'll walk you through the process of creating a language translation app that allows users to translate text between different languages. The implementation involves utilizing Re­act Native components and integrating an efficient language translation API, ensuring the app's functionality is realized effectively.

Preview of final output: Let us have a look at how the final output will look like.

Screenshot-2023-10-12-170856

Prerequisites:

  • Introduction to React Native
  • React Native Components
  • React Hooks
  • Node.js and NPM

Approach:

  • Users can utilize­ this app to input text for translation and choose the source­ and target languages. The app e­mploys the useState hook to manage­ its state, which includes the inputte­d text, translated text, and se­lected languages.
  • The translate­ function handles the processing of translations. Whe­n the input is empty, it effe­ctively erases the­ translated text. On the othe­r hand, if there is input provided, it re­trieves translations using an API.
  • The function calle­d exchangeLanguages pe­rforms the task of swapping the input and translated te­xt, while also updating the sele­cted languages.
  • The use­r interface comprises of two Input compone­nts that allow for text input and translation display. The sele­ction of the source and target language­ is facilitated through ModalDropdown. To initiate the translation proce­ss, there is a dedicate­d translate button.

Steps to Create React Native Application:

Step 1: Create a React Native Application

npx create-expo-app LanguageTranslatorApp

Step 2: ​Change the directory to the project folder

cd LanguageTranslatorApp

Step 3: Install Dependencies

npm install react-native-modal-dropdown react-native-elements

Project Structure:

The updated dependencies in package.json file will look like:

"dependencies": {
"react-native-paper": "4.9.2",
"@expo/vector-icons": "^13.0.0",
"react-native-modal-dropdown": "*",
"react-native-elements": "*"
}

Example: Below is the implementation of the above approach

JavaScript
import React, { useState } from 'react'; import { View,  		Text, TouchableOpacity, StyleSheet } from 'react-native'; import { Input } from 'react-native-elements'; import ModalDropdown from 'react-native-modal-dropdown'; import { styles } from "./Style";  const languages = { 	"am-ET": "Amharic", 	"ar-SA": "Arabic", 	"be-BY": "Bielarus", 	"bem-ZM": "Bemba", 	"bi-VU": "Bislama", 	"bjs-BB": "Bajan", 	"bn-IN": "Bengali", 	"bo-CN": "Tibetan", 	"br-FR": "Breton", 	"bs-BA": "Bosnian", 	"ca-ES": "Catalan", 	"cop-EG": "Coptic", 	"cs-CZ": "Czech", 	"cy-GB": "Welsh", 	"da-DK": "Danish", 	"dz-BT": "Dzongkha", 	"de-DE": "German", 	"dv-MV": "Maldivian", 	"el-GR": "Greek", 	"en-GB": "English", 	"es-ES": "Spanish", 	"et-EE": "Estonian", 	"eu-ES": "Basque", 	"fa-IR": "Persian", 	"fi-FI": "Finnish", 	"fn-FNG": "Fanagalo", 	"fo-FO": "Faroese", 	"fr-FR": "French", 	"gl-ES": "Galician", 	"gu-IN": "Gujarati", 	"ha-NE": "Hausa", 	"he-IL": "Hebrew", 	"hi-IN": "Hindi", 	"hr-HR": "Croatian", 	"hu-HU": "Hungarian", 	"id-ID": "Indonesian", 	"is-IS": "Icelandic", 	"it-IT": "Italian", 	"ja-JP": "Japanese", 	"kk-KZ": "Kazakh", 	"km-KM": "Khmer", 	"kn-IN": "Kannada", 	"ko-KR": "Korean", 	"ku-TR": "Kurdish", 	"ky-KG": "Kyrgyz", 	"la-VA": "Latin", 	"lo-LA": "Lao", 	"lv-LV": "Latvian", 	"men-SL": "Mende", 	"mg-MG": "Malagasy", 	"mi-NZ": "Maori", 	"ms-MY": "Malay", 	"mt-MT": "Maltese", 	"my-MM": "Burmese", 	"ne-NP": "Nepali", 	"niu-NU": "Niuean", 	"nl-NL": "Dutch", 	"no-NO": "Norwegian", 	"ny-MW": "Nyanja", 	"ur-PK": "Pakistani", 	"pau-PW": "Palauan", 	"pa-IN": "Panjabi", 	"ps-PK": "Pashto", 	"pis-SB": "Pijin", 	"pl-PL": "Polish", 	"pt-PT": "Portuguese", 	"rn-BI": "Kirundi", 	"ro-RO": "Romanian", 	"ru-RU": "Russian", 	"sg-CF": "Sango", 	"si-LK": "Sinhala", 	"sk-SK": "Slovak", 	"sm-WS": "Samoan", 	"sn-ZW": "Shona", 	"so-SO": "Somali", 	"sq-AL": "Albanian", 	"sr-RS": "Serbian", 	"sv-SE": "Swedish", 	"sw-SZ": "Swahili", 	"ta-LK": "Tamil", 	"te-IN": "Telugu", 	"tet-TL": "Tetum", 	"tg-TJ": "Tajik", 	"th-TH": "Thai", 	"ti-TI": "Tigrinya", 	"tk-TM": "Turkmen", 	"tl-PH": "Tagalog", 	"tn-BW": "Tswana", 	"to-TO": "Tongan", 	"tr-TR": "Turkish", 	"uk-UA": "Ukrainian", 	"uz-UZ": "Uzbek", 	"vi-VN": "Vietnamese", 	"wo-SN": "Wolof", 	"xh-ZA": "Xhosa", 	"yi-YD": "Yiddish", 	"zu-ZA": "Zulu" };  export default function LanguageTranslator() { 	const [fromText, setFromText] = useState(''); 	const [toText, setToText] = useState(''); 	const [fromLanguage, setFromLanguage] =  		useState('en-GB'); 	const [toLanguage, setToLanguage] =  		useState('fa-IR');  	const translate = () => { 		if (!fromText) { 			setToText(''); 			return; 		}  		setToText('Translating...');  		const apiUrl =  `https://api.mymemory.translated.net/get?q= 	${fromText}&langpair=${fromLanguage}|${toLanguage}`;  		fetch(apiUrl) 			.then((res) => res.json()) 			.then((data) => { 				setToText(data.responseData.translatedText); 				data.matches.forEach((data) => { 					if (data.id === 0) { 						setToText(data.translation); 					} 				}); 			}); 	};  	const exchangeLanguages = () => { 		const tempText = fromText; 		const tempLang = fromLanguage;  		setFromText(toText); 		setToText(tempText); 		setFromLanguage(toLanguage); 		setToLanguage(tempLang); 	};  	return ( 		<View style={styles.container}> 			<View style={styles.wrapper}> 				<Input 					placeholder="Enter text" 					value={fromText} 					onChangeText={(text) =>  						setFromText(text)} 					inputContainerStyle= 						{styles.textInputContainer} 					multiline={true}  					// Allow multiline input 					numberOfLines={4}  					// Limit the number of lines shown (adjust as needed) 				/> 				<View style={styles.controls}> 					<ModalDropdown 						options={Object.values(languages)} 						defaultValue={languages[fromLanguage]} 						onSelect={(index, value) => { 							setFromLanguage(Object.keys(languages).find(key =>  								languages[key] === value)); 						}} 						style={styles.picker} 					/> 					<TouchableOpacity style={styles.exchangeButton}  						onPress={exchangeLanguages}> 						<Text style={styles.exchangeButtonText}>↔</Text> 					</TouchableOpacity> 					<ModalDropdown 						options={Object.values(languages)} 						defaultValue={languages[toLanguage]} 						onSelect={(index, value) => { 							setToLanguage(Object.keys(languages) 								.find(key => languages[key] === value)); 						}} 						style={styles.picker} 					/> 				</View> 				<Input 					placeholder="Translation" 					value={toText} 					inputContainerStyle= 						{styles.translationTextContainer} 					disabled 					multiline={true}  					 					// Allow multiline input for translation text 					numberOfLines={4}  					 					// Limit the number of lines shown (adjust as needed) 				/> 				<TouchableOpacity style={styles.button} onPress={translate}> 					<Text style={styles.buttonText}>Translate it</Text> 				</TouchableOpacity> 			</View> 		</View> 	); } 
JavaScript
import { StyleSheet } from 'react-native';  const styles = StyleSheet.create({  	container: { 		flex: 1, 		alignItems: 'center', 		justifyContent: 'center', 		backgroundColor: '#f0f0f0', 	}, 	wrapper: { 		width: '90%', 		padding: 20, 		backgroundColor: 'white', 		borderRadius: 16, 		shadowColor: '#000', 		shadowOffset: { width: 0, height: 2 }, 		shadowOpacity: 0.2, 		shadowRadius: 4, 		elevation: 5, 	}, 	controls: { 		flexDirection: 'row', 		justifyContent: 'space-between', 		marginBottom: 10, 	}, 	picker: { 		height: 40, 		backgroundColor: '#f9f9f9', 		padding: 10, 		flex: 1, 		borderRadius: 8, 	}, 	exchangeButton: { 		alignItems: 'center', 		justifyContent: 'center', 		backgroundColor: '#0984e3', 		width: 40, 		height: 40, 		borderRadius: 20, 	}, 	exchangeButtonText: { 		color: 'white', 		fontSize: 20, 	}, 	button: { 		backgroundColor: '#0984e3', 		borderRadius: 8, 		height: 40, 		alignItems: 'center', 		justifyContent: 'center', 	}, 	buttonText: { 		fontSize: 18, 		color: 'white', 	},  });  export { styles } 

Steps to run the application:

Step 1: To run react native application use the following command:

npx expo start

Step 2: Depending on your operating system type the following command.

  • To run on Android:
npx react-native run-android
  • To run on iOS:
npx react-native run-ios

Output:


Next Article
Language Translator using React
author
saurabhkumarsharma05
Improve
Article Tags :
  • Web Technologies
  • ReactJS
  • React-Native

Similar Reads

  • Language Translator using React
    Translator is a web application software tool that facilitate the translation of text from one language to another language using ReactJS. This application allows users to give input Text and select input and output language Format from the list of languages and uses Microsoft Translator API. Users
    8 min read
  • Create a Bill Splitter App using React-Native
    We are going to implement the Bill Splitter App using React Native. Bill Splitter App is a mobile application that helps us divide expenses and bills among a group of people. For example, when we are dining at a restaurant with friends, going on a trip, or sharing household expenses with roommates.
    4 min read
  • Create a Task Manager App using React-Native
    In this article, we'll walk you through the process of building a basic Task Manager app using React Native. The application enables users to effortlessly create, edit, complete/incomplete, and delete­ tasks, providing an uncomplicated yet impactful introduction to Re­act Native's mobile app develop
    7 min read
  • Build a Dictionary App Using React Native
    In this article, we are going to implement a Dictionary app using React Native. The app allows users to effortlessly search for word meanings, access definitions, listen to pronunciations, and examine example sentences. Preview of final output: Let us look at what the final output will look like. Pr
    5 min read
  • Translator App Project using Django
    Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source. R
    2 min read
  • Create a Resume Builder using React-Native
    A resume is like a personal marketing document that shows off your skills, work history, and achievements to a potential employer. Resume builder apps help you to create this document more easily. In this article, we are going to implement a resume builder app using React Native. Preview of final ou
    5 min read
  • Create a Blog App using React-Native
    This article shows how to create a basic blog app using react native. This app contains functionalities such as adding a blog and a delete button to remove the blogs using react native. The user can enter content with a title and then click on 'Add New Post' to create a new blog post Preview of fina
    4 min read
  • Create a Calling App using React-Native
    Building a Calling App using React-Native allows you to create a cross-platform application that supports voice calling. This tutorial will guide you through the process of integrating voice calling functionality into a React-Native app, enabling users to make and receive calls seamlessly. Preview o
    5 min read
  • Create an Image to Text App using React-Native
    In this article, we are going to build a step-by-step Image to Text app using React-Native. This application will allow users to extract the text from the image using OCR (Optical Character Recognition) and later copy it to the clipboard or share it with others. This application is a perfect usage o
    4 min read
  • Build a Calculator using React Native
    React Native is a well-known technology for developing mobile apps that can run across many platforms. It enables the creation of native mobile apps for iOS and Android from a single codebase. React Native makes it simple to construct vibrant, engaging, and high-performing mobile apps. In this tutor
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences