-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from JosephGasiorekUSDS/jgasiorek-ffs-945
FFS-945: i18n Chooser
- Loading branch information
Showing
45 changed files
with
232 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use client' | ||
|
||
import { I18nextProvider } from 'react-i18next' | ||
import { initTranslations} from '@/app/i18n' | ||
import { createInstance } from 'i18next' | ||
|
||
interface TranslationsProviderProps { | ||
children: React.ReactNode | ||
locale: string | ||
} | ||
|
||
export default async function TranslationsProvider({ children, locale }: TranslationsProviderProps) { | ||
const i18n = createInstance() | ||
await initTranslations(locale, i18n) | ||
|
||
return (<I18nextProvider i18n={i18n}>{children}</I18nextProvider>) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { Metadata } from "next"; | ||
import { Inter } from "next/font/google"; | ||
import StoreProvider from '@/app/StoreProvider' | ||
import "./globals.css"; | ||
import GovernmentBanner from "@/app/components/GovernmentBanner"; | ||
import InitialStateLoader from "@/app/InitialStateLoader"; | ||
import TranslationsProvider from "../TranslationsProvider"; | ||
import { i18nConfig } from "@/app/constants"; | ||
const inter = Inter({ subsets: ["latin"] }); | ||
|
||
export const metadata: Metadata = { | ||
title: "Verify.gov", | ||
}; | ||
|
||
export function generateStaticParams() { | ||
return i18nConfig.locales.map(locale => { | ||
return {locale} | ||
}) | ||
} | ||
|
||
function RootLayout({ | ||
children, | ||
params | ||
}: Readonly<{ | ||
children: React.ReactNode | ||
params: any | ||
}>) { | ||
return ( | ||
<html lang={params.locale}> | ||
<body className={inter.className}> | ||
<StoreProvider> | ||
<InitialStateLoader> | ||
<TranslationsProvider locale={params.locale}> | ||
<GovernmentBanner /> | ||
{children} | ||
</TranslationsProvider> | ||
</InitialStateLoader> | ||
</StoreProvider> | ||
</body> | ||
</html> | ||
); | ||
} | ||
|
||
export default RootLayout |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Header, Link, NavMenuButton, PrimaryNav, Title } from "@trussworks/react-uswds" | ||
import { useState } from "react" | ||
import { useTranslation } from "react-i18next" | ||
import { i18nConfig } from "@/app/constants" | ||
import { usePathname, useRouter } from "next/navigation" | ||
import { useCookies } from "react-cookie" | ||
|
||
interface VerifyNavProps { | ||
title: string | ||
} | ||
|
||
export default function VerifyNav(props: VerifyNavProps) { | ||
const { t, i18n } = useTranslation() | ||
const router = useRouter() | ||
const currentPathname = usePathname() | ||
const [cookies, setCookie] = useCookies([i18nConfig.cookieName]); | ||
const currentLocale = i18n.language | ||
const [expanded, setExpanded] = useState(false) | ||
|
||
function changeLang(locale: string) { | ||
i18n.changeLanguage(locale) | ||
setCookie(i18nConfig.cookieName, locale) | ||
|
||
if (locale === i18nConfig.defaultLocale) { | ||
router.push(currentPathname.replace(`${currentLocale}`, '')); | ||
} else if (currentLocale == i18nConfig.defaultLocale) { | ||
router.push(`/${locale}/${currentPathname}`) | ||
} else { | ||
router.push(currentPathname.replace(`/${currentLocale}`, `/${locale}`) + "/") | ||
} | ||
router.refresh(); | ||
} | ||
|
||
function makeNavItem(text: string, lang: string) { | ||
const isCurrent = i18n.language?.startsWith(lang) ?? "en" | ||
return <Link | ||
href="#" | ||
className={`usa-nav__link ${isCurrent ? "usa-current" : ""}`} | ||
onClick={() => {changeLang(lang) }} | ||
>{text}</Link> | ||
} | ||
|
||
const navItems = [ | ||
makeNavItem(t('nav_english'), "en"), | ||
makeNavItem(t('nav_espanol'), "es"), | ||
] | ||
|
||
const onClick = () => { | ||
setExpanded(prev => !prev) | ||
} | ||
return ( | ||
<Header basic={true} showMobileOverlay={expanded}> | ||
<div className="usa-nav-container"> | ||
<div className="usa-navbar"> | ||
<Title>{props.title}</Title> | ||
<NavMenuButton onClick={onClick} label="Menu" /> | ||
</div> | ||
<PrimaryNav items={navItems} mobileExpanded={expanded} onToggleMobileNav={onClick} /> | ||
</div> | ||
</Header> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export const i18nConfig = { | ||
locales: ['en', 'es'], | ||
defaultLocale: 'en', | ||
cookieName: 'NEXT_LOCALE', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
import i18n from 'i18next'; | ||
import { initReactI18next } from 'react-i18next'; | ||
import LanguageDetector from 'i18next-browser-languagedetector'; | ||
import resourcesToBackend from 'i18next-resources-to-backend' | ||
import { i18nConfig } from './constants'; | ||
|
||
i18n | ||
.use(LanguageDetector) | ||
.use(initReactI18next) | ||
.use(resourcesToBackend((language, namespace) => import(`./i18n/locales/${language}/${namespace}.json`))) | ||
.init({ | ||
debug: process.env.NODE_ENV !== "production" , | ||
fallbackLng: 'en' | ||
}); | ||
export async function initTranslations( | ||
locale, | ||
i18nInstance | ||
) { | ||
i18nInstance = i18nInstance || createInstance() | ||
i18nInstance.use(initReactI18next) | ||
i18nInstance.use(resourcesToBackend((language, namespace) => import(`./i18n/locales/${language}/${namespace}.json`))) | ||
|
||
export default i18n; | ||
return i18nInstance.init({ | ||
debug: process.env.NODE_ENV !== "production" , | ||
lng: locale, | ||
fallbackLng: i18nConfig.defaultLocale, | ||
supportedLngs: i18nConfig.locales, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"intro_title": "Verify.gov | Auto-empleo", | ||
"intro_header": "Envíe prueba de sus ingresos por trabajo autónomo, por contrato independiente o por cuenta propia", | ||
"intro_subheader": "Le ayudaremos a documentar sus ingresos como trabajador independiente o en efectivo y enviarlos a su solicitud de beneficios para que pueda obtener beneficios más rápido.", | ||
"intro_secure": "Tu información está segura", | ||
"intro_get_started_button": "Empezar", | ||
"intro_how_do_i_know_header": "¿Cómo sé si soy autónomo?", | ||
"intro_how_do_i_know_body_list_header": "Una persona puede trabajar por cuenta propia si:", | ||
"intro_how_do_i_know_list_have_expenses": "Tienen gastos comerciales que nadie para quienes trabajan les paga.", | ||
"intro_how_do_i_know_list_they_receive": "Reciben el formulario de impuestos 1099-MISC de una empresa o individuo al final del año.", | ||
"intro_how_do_i_know_list_own": "Poseen o dirigen su propio negocio.", | ||
"intro_how_do_i_know_list_benefits": "No reciben beneficios laborales ni contribuciones fiscales del individuo o empresa para la que trabajan.", | ||
"nav_english": "English", | ||
"nav_espanol": "Español", | ||
"benefits_title": "Programas de beneficios", | ||
"benefits_header": "¿Cuándo deben demostrarse los programas de beneficios en el libro mayor?", | ||
"benefits_subheader_select": "Seleccione los beneficios de los que le gustaría ver una demostración.", | ||
"benefits_medicaid": "Medicaid (atención médica)", | ||
"benefits_snap": "SNAP (asistencia alimentaria)", | ||
"benefits_continue_button": "Continuar", | ||
"benefits_snap_hint": "Nota: Actualmente, el libro mayor asumirá que hay una deducción estándar del 50 % disponible para SNAP.", | ||
"benefits_error_message": "Debes seleccionar al menos uno de los siguientes beneficios" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { i18nRouter } from 'next-i18n-router'; | ||
import { i18nConfig } from './app/constants'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export function middleware(request: NextRequest) { | ||
return i18nRouter(request, i18nConfig); | ||
} | ||
|
||
export const config = { | ||
matcher: '/((?!api|static|.*\\..*|_next).*)' | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters