Bird
Raised Fist0
NextJSframework~20 mins

Why i18n matters in NextJS - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
i18n Mastery in Next.js
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why is internationalization (i18n) important in web apps?

Imagine you build a website that only shows text in English. What problem might users from other countries face?

AThey will see the website in their own language automatically.
BThey might not understand the content because it’s only in English.
CThe website will load faster for them.
DThe website will have fewer images.
Attempts:
2 left
💡 Hint

Think about users who speak different languages than English.

❓ component_behavior
intermediate
1:30remaining
What happens if you don’t provide translations in Next.js i18n config?

In Next.js, if you set up i18n but forget to add translations for a language, what will the user see?

AThe user will see fallback content, usually in the default language.
BThe app will crash with an error.
CThe user will see blank text where translations are missing.
DThe app will automatically translate text using AI.
Attempts:
2 left
💡 Hint

Think about how apps handle missing translations gracefully.

📝 Syntax
advanced
2:00remaining
Which Next.js i18n config correctly sets English and Spanish as supported languages?

Choose the correct i18n configuration snippet for Next.js that supports English (default) and Spanish.

A{ locales: ['en', 'es'], defaultLocale: 'en' }
B{ languages: ['en', 'es'], default: 'en' }
C{ locales: ['en', 'es'], default: 'es' }
D{ locales: ['en', 'es'], defaultLocale: 'fr' }
Attempts:
2 left
💡 Hint

Check the exact property names Next.js expects for i18n.

❓ state_output
advanced
1:30remaining
What is the rendered output when switching locale in Next.js?

Given a Next.js app with English and Spanish translations for a greeting, what will the user see after switching locale from English to Spanish?

const translations = { en: 'Hello', es: 'Hola' };
AHelloHola
BHello
CHola
DError: Translation not found
Attempts:
2 left
💡 Hint

Think about what happens when you change the language setting.

🔧 Debug
expert
2:30remaining
Why does this Next.js i18n setup cause a 404 error on Spanish pages?

Look at this Next.js config snippet:

module.exports = { i18n: { locales: ['en', 'es'], defaultLocale: 'en' } }

Spanish pages return 404 errors. What is the likely cause?

ANext.js does not support multiple locales.
BThe defaultLocale should be 'es' instead of 'en'.
CThe locales array must include 'fr' for fallback.
DThe Spanish translation files are missing or misnamed.
Attempts:
2 left
💡 Hint

Check if translation files exist for all locales.

Practice

(1/5)
1. Why is internationalization (i18n) important in a Next.js app?
easy
A. It automatically fixes bugs in the code.
B. It allows the app to support multiple languages and cultures.
C. It improves the app's loading speed.
D. It reduces the app's file size.

Solution

  1. Step 1: Understand the purpose of i18n

    i18n stands for internationalization, which means making an app usable for people from different languages and cultures.
  2. Step 2: Identify what i18n affects in an app

    It handles language translations, date formats, number formats, and cultural differences to improve user experience worldwide.
  3. Final Answer:

    It allows the app to support multiple languages and cultures. -> Option B
  4. Quick Check:

    i18n = support multiple languages [OK]
Hint: i18n means making apps work worldwide [OK]
Common Mistakes:
  • Confusing i18n with performance improvements
  • Thinking i18n fixes bugs automatically
  • Believing i18n reduces file size
2. Which Next.js hook is commonly used to access translations in an i18n setup?
easy
A. useEffect
B. useRouter
C. useState
D. useTranslations

Solution

  1. Step 1: Recall Next.js i18n tools

    Next.js provides a hook called useTranslations to easily get translated strings in components.
  2. Step 2: Differentiate from other hooks

    useRouter manages routing, useState manages state, and useEffect handles side effects, none are for translations.
  3. Final Answer:

    useTranslations -> Option D
  4. Quick Check:

    Translation hook = useTranslations [OK]
Hint: Translation hook starts with 'useTranslations' [OK]
Common Mistakes:
  • Choosing useRouter for translations
  • Confusing useState or useEffect with i18n
  • Not knowing Next.js i18n hooks
3. Given this Next.js component using i18n:
import { useTranslations } from 'next-intl';

export default function Greeting() {
  const t = useTranslations('Home');
  return <h1>{t('welcomeMessage')}</h1>;
}

If the translation file for 'Home' has { "welcomeMessage": "Hello, world!" }, what will be rendered?
medium
A. <h1>welcomeMessage</h1>
B. An error because 't' is not a function
C. <h1>Hello, world!</h1>
D. <h1>Home</h1>

Solution

  1. Step 1: Understand useTranslations usage

    The hook useTranslations('Home') returns a function t that looks up keys in the 'Home' translation file.
  2. Step 2: Check the translation key value

    The key 'welcomeMessage' maps to "Hello, world!" in the translation file, so t('welcomeMessage') returns "Hello, world!".
  3. Final Answer:

    <h1>Hello, world!</h1> -> Option C
  4. Quick Check:

    t('welcomeMessage') = 'Hello, world!' [OK]
Hint: t('key') returns the translated string [OK]
Common Mistakes:
  • Thinking t returns the key name instead of value
  • Assuming t is not a function
  • Confusing component name with translation output
4. What is wrong with this Next.js i18n code snippet?
import { useTranslations } from 'next-intl';

export default function Header() {
  const t = useTranslations('Header');
  return <h2>t('title')</h2>;
}
medium
A. The translation function call is missing curly braces inside JSX.
B. useTranslations should be called with 'header' lowercase.
C. The component must return a fragment instead of <h2>.
D. The import statement is incorrect.

Solution

  1. Step 1: Check JSX syntax for function calls

    In JSX, JavaScript expressions must be inside curly braces. Here, t('title') is written as plain text, so it won't execute.
  2. Step 2: Identify the fix

    Wrapping t('title') in curly braces like {t('title')} correctly calls the function and renders the translation.
  3. Final Answer:

    The translation function call is missing curly braces inside JSX. -> Option A
  4. Quick Check:

    JSX expressions need curly braces [OK]
Hint: JSX needs curly braces for JS expressions [OK]
Common Mistakes:
  • Forgetting curly braces around function calls in JSX
  • Assuming case sensitivity causes error here
  • Thinking import is wrong without checking
5. You want to display a date in a Next.js app that supports i18n. Which approach best respects users' locale settings?
hard
A. Use JavaScript's Intl.DateTimeFormat with the user's locale from Next.js router.
B. Hardcode the date format as 'MM/DD/YYYY' in all components.
C. Convert dates to strings manually with string slicing.
D. Ignore locale and always show ISO date format.

Solution

  1. Step 1: Understand i18n date formatting needs

    Dates should appear in formats familiar to users based on their locale (language and region).
  2. Step 2: Identify the best tool for locale-aware formatting

    JavaScript's Intl.DateTimeFormat formats dates according to locale, which can be obtained from Next.js router or i18n context.
  3. Step 3: Evaluate other options

    Hardcoding or manual string slicing ignores locale differences and reduces usability. ISO format is not user-friendly for all locales.
  4. Final Answer:

    Use JavaScript's Intl.DateTimeFormat with the user's locale from Next.js router. -> Option A
  5. Quick Check:

    Locale-aware date formatting = Intl.DateTimeFormat [OK]
Hint: Use Intl.DateTimeFormat for locale dates [OK]
Common Mistakes:
  • Hardcoding date formats ignoring locale
  • Manually slicing date strings incorrectly
  • Showing ISO format without localization
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard