Logo

dev-resources.site

for different kinds of informations.

Translate & Guess: Build a Flag Quiz with Expo and Tolgee

Published at
10/25/2024
Categories
tolgee
reactnative
expo
tailwindcss
Author
vaishali785
Author
11 person written this
vaishali785
open
Translate & Guess: Build a Flag Quiz with Expo and Tolgee

Introduction

In today’s globalized world, apps that support multiple languages enhance user experience and accessibility. In this tutorial, I’ll guide you through the development of a simple yet engaging quiz app built with Expo, where users guess the country name based on a displayed flag. We’ll integrate Tolgee, an open-source localization library, to provide seamless translations in English, Italian, Japanese, and Korean. Whether you're a beginner or an intermediate developer, this tutorial will help you learn how to set up multilingual support in a React Native app.

FlagPro Home Screen

Steps to Create and Set Up Your Flag Quiz App

  1. Create a New Folder
    • Start by creating a new folder for your project.
   mkdir flag-quiz-app
Enter fullscreen mode Exit fullscreen mode
  1. Navigate to the Folder
    • Change your working directory to the newly created folder.
   cd flag-quiz-app
Enter fullscreen mode Exit fullscreen mode
  1. Install Dependencies
    • Install the major libraries you'll need for your app. In this case, you'll be using Expo, Tailwind CSS (or NativeWind), and Tolgee for localization.
   npx create-expo-app .
   npm install nativewind tolgee
Enter fullscreen mode Exit fullscreen mode
  1. Set Up Dependencies

  2. Integrating Tolgee for Localization

  • Tolgee is an open-source library that provides easy-to-implement localization.

    • Setting Up Tolgee: Sign up at Tolgee.io and create a new project. Note down your API key for the project.
    • Integrate Tolgee into Your App: In App.js, set up Tolgee and wrap your app in the TolgeeProvider:
    import React from 'react';
    import { TolgeeProvider, Tolgee } from '@tolgee/react';
    import { NavigationContainer } from '@react-navigation/native';
    import QuizScreen from './screens/Quiz';
    const tolgee = Tolgee()
     .use({ apiKey: 'YOUR_API_KEY', apiUrl: 'https://app.tolgee.io' })
     .init();
    export default function App() {
     return (
       <TolgeeProvider tolgee={tolgee}>
         <NavigationContainer>
           <QuizScreen />
         </NavigationContainer>
       </TolgeeProvider>
     );
    }
    
    • Translate Text in the Quiz App:
      • Wrap translatable strings with T from Tolgee to make them dynamic.
      • For example, replace button titles with Tolgee keys:
     import { T } from '@tolgee/react';
     <Button title={<T keyName="countryA" />} onPress={() => checkAnswer('Country A')} />
    
    • Add Translations on Tolgee.io:
      • Head to your project in Tolgee.io, where you can add translations for each key. For example:
      • Key: countryA
      • Translations: Country A in English, Paese A in Italian, etc.

Conclusion

Congratulations! You’ve built a multilingual flag quiz app using Expo and Tolgee. By following this guide, you’ve learned the basics of setting up a quiz app, integrating translations, and adding language-switching support with Tolgee. This framework and localization setup can now serve as a foundation for adding even more features, languages, and levels.

For the complete source code, visit my GitHub and don't forget to star my repo: GitHub Repo Link.

expo Article's
30 articles in total
Favicon
Read Text Asset File in Expo
Favicon
Run Storybook with NX Expo and React Native Paper
Favicon
Explorando Notificações Push no React Native com Expo e OneSignal!
Favicon
Starting React Native Project in 2025
Favicon
Guia Completo: Como Integrar WatermelonDB no React Native 0.76 com Expo 52 e TypeScript
Favicon
How to create authenticated routes with the new Expo SDK 51 using Expo Router
Favicon
React Native Expo with NativeWind v4 and Typescript
Favicon
Translate & Guess: Build a Flag Quiz with Expo and Tolgee
Favicon
How i implemented my server login screen for Mastodon
Favicon
How to Change iOS Push Notifications Permission Dialog with Expo
Favicon
Exploring React Native Navigation with Expo: A Complete Guide
Favicon
How to Render OpenStreetMap in an Expo React Native Web App Using React Leaflet
Favicon
EAS build reads your .gitignore file
Favicon
#2 - Expo apk keeps on crashing after build
Favicon
Dear expo, who are you?
Favicon
npm i openai-react-native
Favicon
Expo51 Jotai Template + flashlist + tamagui
Favicon
Scroll-Responsive Animated Header Bar with Expo Router
Favicon
Expo vs. React Native: Pros, Cons, and Key Differences
Favicon
To Obfuscate or Not Obfuscate (React Native)
Favicon
How to disable keyboard suggestions for Android in React Native
Favicon
Expo51 Jotai Template, ready to use
Favicon
Let's get started with React Native + Expo
Favicon
Generar APK con EAS ⚛️ React Native
Favicon
How to publish your React Native app to Expo Store 2024
Favicon
Creating a WebView app in React Native using Expo
Favicon
Embracing Expo: The New Standard for Creating React Native Apps
Favicon
Automate Your Expo Builds with EAS Using GitHub Actions: A Step-by-Step Guide (Android)
Favicon
How to Generate APK Using React Native Expo
Favicon
Creating Chat Bubbles with curls in React Native (svg)

Featured ones: