📖 Scenario: You are building a simple web page that greets users in different languages based on their choice. This helps people from different countries feel welcome.
🎯 Goal: Create a Remix app that shows a greeting message in English or Spanish depending on a language setting. You will set up the data, add a language selector, use i18n logic to pick the right greeting, and complete the component to display it.
📋 What You'll Learn
Create a dictionary with greetings in English and Spanish
Add a variable to hold the selected language code
Use a function to get the greeting based on the selected language
Render the greeting message inside a React component
💡 Why This Matters
🌍 Real World
Internationalization helps websites greet users in their own language, making the experience friendly and inclusive.
💼 Career
Many web apps need to support multiple languages. Knowing how to set up i18n basics in Remix is useful for frontend and full-stack developers.
Progress0 / 4 steps
1
Create greetings dictionary
Create a constant called greetings that is an object with two keys: en and es. Each key should have a string greeting: 'Hello!' for en and '¡Hola!' for es.
Remix
Hint
Use an object with keys 'en' and 'es' and assign the greetings as strings.
2
Add selected language variable
Add a constant called selectedLang and set it to the string 'es' to represent the chosen language code.
Remix
Hint
Use const selectedLang = 'es'; to set Spanish as the selected language.
3
Create function to get greeting
Write a function called getGreeting that takes a parameter lang and returns the greeting from greetings for that language code.
Remix
Hint
Use bracket notation to access the greeting for the given language code.
4
Render greeting in React component
Create a React functional component called Greeting that returns a <div> containing the greeting message by calling getGreeting(selectedLang).
Remix
Hint
Use a functional component that returns a div with the greeting text inside curly braces.
Practice
(1/5)
1. What is the main purpose of internationalization (i18n) in a Remix app?
easy
A. To improve app loading speed
B. To display app text in multiple languages based on user preference
C. To add animations to the user interface
D. To secure user data with encryption
Solution
Step 1: Understand the goal of i18n
Internationalization means making your app support many languages so users see text in their own language.
Step 2: Match purpose to options
Only To display app text in multiple languages based on user preference talks about showing text in multiple languages, which matches i18n's goal.
Final Answer:
To display app text in multiple languages based on user preference -> Option B
Quick Check:
i18n = multi-language support [OK]
Hint: i18n means multi-language text display [OK]
Common Mistakes:
Confusing i18n with performance optimization
Thinking i18n is about security
Assuming i18n adds UI animations
2. Which of the following is the correct way to access a translation key using Remix loader data?
easy
A. const greeting = translations.get('greeting')
B. const greeting = useTranslation('greeting')
C. const greeting = i18n.t('greeting')
D. const greeting = loaderData.translations['greeting']
Solution
Step 1: Recall Remix loader data usage
Loader functions return data accessed in components via loaderData. Translations are often passed this way.
Step 2: Identify correct syntax for translation access
const greeting = loaderData.translations['greeting'] uses loaderData.translations['greeting'], which is valid JavaScript to get a translation string.
Final Answer:
const greeting = loaderData.translations['greeting'] -> Option D
Quick Check:
Access translations via loaderData object [OK]
Hint: Use loaderData to get translations in Remix [OK]
Common Mistakes:
Using React hooks like useTranslation inside loaders
Calling i18n.t() without importing or context
Trying to get translations directly without loader data