0
0
Remixframework~20 mins

Internationalization (i18n) in Remix - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
i18n Mastery in Remix
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Remix handle locale detection in loaders?
Consider a Remix loader that needs to detect the user's locale from the request headers. Which option correctly extracts the preferred locale from the Accept-Language header and falls back to en if none is found?
Aconst locale = request.headers.get('Accept-Language')?.split(',')[0] || 'en-US';
Bconst locale = request.headers.get('accept-language')?.split(';')[0] || 'en';
Cconst locale = request.headers.get('Accept-Language')?.split(',')[0] ?? 'en';
Dconst locale = request.headers.get('Accept-Language')?.split(',')[1] ?? 'en';
Attempts:
2 left
💡 Hint
Remember that header names are case-insensitive but usually accessed with exact casing in Node.js. Also, the first language in the Accept-Language header is the preferred one.
📝 Syntax
intermediate
2:00remaining
Correct syntax for using useLoaderData with i18n data
You want to access localized messages loaded in the Remix loader using useLoaderData. Which option correctly types and uses the hook in a React component?
Aconst messages = useLoaderData().messages as Record<string, string>;
Bconst messages = useLoaderData<{ messages: Record<string, string> }>().messages;
Cconst { messages } = useLoaderData<Record<string, string>>();
Dconst messages = useLoaderData<{ messages: string[] }>().messages;
Attempts:
2 left
💡 Hint
The loader returns an object with a 'messages' property that is a dictionary of strings.
🔧 Debug
advanced
2:00remaining
Why does the localized string not update on locale change?
You have a Remix app that loads translations in the loader and passes them to the component. When the user changes the locale, the displayed text does not update. What is the most likely cause?
AThe loader is not re-run because the route params or URL did not change to trigger a new request.
BThe translations object is mutated directly causing React not to detect changes.
CThe translations are loaded client-side but not stored in state, so React does not re-render.
DThe useLoaderData hook caches data and does not update on locale changes.
Attempts:
2 left
💡 Hint
Think about when Remix loaders run and what triggers them.
🧠 Conceptual
advanced
2:00remaining
How to implement fallback locale in Remix i18n?
You want your Remix app to serve translations in the user's preferred locale but fall back to English if translations are missing. Which approach best implements this fallback behavior?
AUse a try-catch block in the loader to load user locale, and if it fails, load English translations.
BLoad only the user's locale translations and if a key is missing, show an empty string.
CLoad English translations client-side and replace missing keys after rendering.
DLoad the user's locale translations in the loader, then merge them with English translations, prioritizing user locale keys.
Attempts:
2 left
💡 Hint
Think about how to combine two sets of translations so missing keys fall back gracefully.
state_output
expert
3:00remaining
What is the rendered output after locale switch with server and client state?
Given a Remix component that uses useLoaderData to get initial translations and a client-side signal to track locale, what will be the displayed greeting after the user switches locale from 'en' to 'fr' if the loader does not re-run?
Remix
import { useLoaderData } from '@remix-run/react';
import { useState } from 'react';

export default function Greeting() {
  const { messages } = useLoaderData();
  const [locale, setLocale] = useState('en');

  function switchLocale() {
    setLocale(locale === 'en' ? 'fr' : 'en');
  }

  return (
    <div>
      <button onClick={switchLocale}>Switch Locale</button>
      <p>{messages[locale === 'en' ? 'hello' : 'bonjour']}</p>
    </div>
  );
}

// Loader returns: { messages: { hello: 'Hello', bonjour: 'Bonjour' } }
A<button>Switch Locale</button><p>Hello</p> then <p>Bonjour</p> after click
B<button>Switch Locale</button><p>Hello</p> then <p>Hello</p> after click
C<button>Switch Locale</button><p>Bonjour</p> then <p>Hello</p> after click
D<button>Switch Locale</button><p>Bonjour</p> then <p>Bonjour</p> after click
Attempts:
2 left
💡 Hint
The messages object contains both greetings, but the displayed text depends on the locale state.