Complete the code to import the Next.js internationalized routing hook.
import { [1] } from 'next/navigation';
The useLocale hook from next/navigation helps get the current locale for content translation management.
Complete the code to fetch translated messages for the current locale.
const messages = await import(`../locales/$[1].json`);
The variable locale typically holds the current language code like 'en' or 'fr' to load the correct translation file.
Fix the error in the code to correctly use the translation messages in a React component.
export default async function Greeting() {
const locale = useLocale();
const messages = await import(`../locales/$[1].json`);
return <p>{messages.greeting}</p>;
}The variable locale must be used to dynamically import the correct translation file.
Also, await cannot be used directly inside the component body; it should be handled in a server component or with hooks.
Fill both blanks to create a server component that loads translations and renders a greeting.
export default async function Greeting() {
const language = [1]();
const messages = await import(`../locales/$[2].json`);
return <p>{messages.greeting}</p>;
}The useLocale hook gets the current locale, stored in language variable to import the correct JSON file.
Fill all three blanks to create a translation dictionary comprehension filtering keys starting with 'g'.
const filteredMessages = Object.fromEntries( Object.entries(messages).filter(([[1]]) => [2].startsWith('[3]')) );
In the filter, the first element of the entry tuple is the key, here named k. We check if k starts with 'g' to keep those entries.