const { t } = useTranslation(); return <Heading>{t("welcome.message")}</Heading>; CODE_BLOCK: const { t } = useTranslation(); return <Heading>{t("welcome.message")}</Heading>; CODE_BLOCK: const { t } = useTranslation(); return <Heading>{t("welcome.message")}</Heading>; CODE_BLOCK: // en.json { "welcome": { "message": "Welcome back!" } } // es.json { "welcome": {} } // oops - forgot this one CODE_BLOCK: // en.json { "welcome": { "message": "Welcome back!" } } // es.json { "welcome": {} } // oops - forgot this one CODE_BLOCK: // en.json { "welcome": { "message": "Welcome back!" } } // es.json { "welcome": {} } // oops - forgot this one CODE_BLOCK: const { t } = useI18n(); return <Heading> {t({ en: `Welcome back, ${name}!`, es: `¡Bienvenido de nuevo, ${name}!`, })} </Heading>; CODE_BLOCK: const { t } = useI18n(); return <Heading> {t({ en: `Welcome back, ${name}!`, es: `¡Bienvenido de nuevo, ${name}!`, })} </Heading>; CODE_BLOCK: const { t } = useI18n(); return <Heading> {t({ en: `Welcome back, ${name}!`, es: `¡Bienvenido de nuevo, ${name}!`, })} </Heading>; CODE_BLOCK: // i18n/index.ts import { createI18n } from "react-scoped-i18n"; export const { useI18n, I18nProvider } = createI18n({ languages: ["en", "es", "sl"], defaultLanguage: "en", }); CODE_BLOCK: // i18n/index.ts import { createI18n } from "react-scoped-i18n"; export const { useI18n, I18nProvider } = createI18n({ languages: ["en", "es", "sl"], defaultLanguage: "en", }); CODE_BLOCK: // i18n/index.ts import { createI18n } from "react-scoped-i18n"; export const { useI18n, I18nProvider } = createI18n({ languages: ["en", "es", "sl"], defaultLanguage: "en", }); CODE_BLOCK: type Language = "en" | "es" | "sl"; type Translations = Record<Language, string>; CODE_BLOCK: type Language = "en" | "es" | "sl"; type Translations = Record<Language, string>; CODE_BLOCK: type Language = "en" | "es" | "sl"; type Translations = Record<Language, string>; CODE_BLOCK: return <Heading> {t({ en: `Welcome back, ${name}!`, es: `¡Bienvenido de nuevo, ${name}!`, // TypeScript Error: Property 'sl' is missing in type // '{ en: string; es: string; }' // but required in type 'Translations' })} </Heading>; CODE_BLOCK: return <Heading> {t({ en: `Welcome back, ${name}!`, es: `¡Bienvenido de nuevo, ${name}!`, // TypeScript Error: Property 'sl' is missing in type // '{ en: string; es: string; }' // but required in type 'Translations' })} </Heading>; CODE_BLOCK: return <Heading> {t({ en: `Welcome back, ${name}!`, es: `¡Bienvenido de nuevo, ${name}!`, // TypeScript Error: Property 'sl' is missing in type // '{ en: string; es: string; }' // but required in type 'Translations' })} </Heading>; CODE_BLOCK: const { tPlural } = useI18n(); return <Text>{tPlural(count, { en: { one: `You have one apple.`, many: `You have ${count} apples.`, }, es: { one: `Tienes una manzana.`, many: `Tienes ${count} manzanas.`, }, sl: { one: `Imaš eno jabolko.`, two: `Imaš dve jabolki.`, // Slovenian has a dual form many: `Imaš ${count} jabolk.`, }, })}</Text>; CODE_BLOCK: const { tPlural } = useI18n(); return <Text>{tPlural(count, { en: { one: `You have one apple.`, many: `You have ${count} apples.`, }, es: { one: `Tienes una manzana.`, many: `Tienes ${count} manzanas.`, }, sl: { one: `Imaš eno jabolko.`, two: `Imaš dve jabolki.`, // Slovenian has a dual form many: `Imaš ${count} jabolk.`, }, })}</Text>; CODE_BLOCK: const { tPlural } = useI18n(); return <Text>{tPlural(count, { en: { one: `You have one apple.`, many: `You have ${count} apples.`, }, es: { one: `Tienes una manzana.`, many: `Tienes ${count} manzanas.`, }, sl: { one: `Imaš eno jabolko.`, two: `Imaš dve jabolki.`, // Slovenian has a dual form many: `Imaš ${count} jabolk.`, }, })}</Text>;