From f58d93b618a3cc6fcb8f826314a9f4b0f63bdb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Wed, 23 Nov 2022 18:32:37 +0100 Subject: [PATCH] Fix i18n type error --- site/scripts/search/update-data.ts | 5 ++++- site/source/locales/i18n.ts | 1 + site/source/pages/Simulateurs/metadata-src.ts | 4 ++-- site/source/pages/Simulateurs/metadata.tsx | 8 ++++---- site/source/types/react-i18next.d.ts | 8 ++++++++ 5 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 site/source/types/react-i18next.d.ts diff --git a/site/scripts/search/update-data.ts b/site/scripts/search/update-data.ts index de76a56e5..2f99cd7df 100644 --- a/site/scripts/search/update-data.ts +++ b/site/scripts/search/update-data.ts @@ -1,5 +1,6 @@ import algoliasearch from 'algoliasearch' import dotenv from 'dotenv' +import { TFunction } from 'i18next' import rawRules from 'modele-social' import Engine, { ParsedRules } from 'publicodes' @@ -152,7 +153,9 @@ try { console.log('Uploading: simulateurs') await simulateursIndex .saveObjects( - formatSimulationDataToAlgolia(getSimulationData((_, text) => text)) + formatSimulationDataToAlgolia( + getSimulationData(((_: string, text: string) => text) as TFunction) + ) ) .wait() diff --git a/site/source/locales/i18n.ts b/site/source/locales/i18n.ts index 1012f132c..a3c51fe2b 100644 --- a/site/source/locales/i18n.ts +++ b/site/source/locales/i18n.ts @@ -13,6 +13,7 @@ interface Units { i18next .use(initReactI18next) .init({ + returnNull: false, resources: { fr: { units: (unitsTranslations as Units).fr }, en: { units: (unitsTranslations as Units).en }, diff --git a/site/source/pages/Simulateurs/metadata-src.ts b/site/source/pages/Simulateurs/metadata-src.ts index 9022aa829..0d8781246 100644 --- a/site/source/pages/Simulateurs/metadata-src.ts +++ b/site/source/pages/Simulateurs/metadata-src.ts @@ -1,11 +1,11 @@ -import { TFunction } from 'react-i18next' +import { TFunction } from 'i18next' /** * Contient l'intégralité des données concernant les différents simulateurs * sans dépendance qui compliquerait leur import dans le script de mise à jour * des données pour Algolia. */ -const getMetadataSrc = (t: TFunction<'translation', string>) => { +const getMetadataSrc = (t: TFunction) => { const data = { salarié: { tracking: 'salarie', diff --git a/site/source/pages/Simulateurs/metadata.tsx b/site/source/pages/Simulateurs/metadata.tsx index d2b4bdd2a..67fd887ac 100644 --- a/site/source/pages/Simulateurs/metadata.tsx +++ b/site/source/pages/Simulateurs/metadata.tsx @@ -1,5 +1,6 @@ +import type { TFunction } from 'i18next' import { createContext, useMemo } from 'react' -import { TFunction, Trans, useTranslation } from 'react-i18next' +import { Trans, useTranslation } from 'react-i18next' import styled, { css } from 'styled-components' import { PlaceDesEntreprisesButton } from '@/components/PlaceDesEntreprises' @@ -62,7 +63,7 @@ import urlIllustrationNetBrut from './images/illustration-net-brut.png' import getData from './metadata-src.js' interface SimulatorsDataParams { - t: TFunction<'translation', string> + t: TFunction sitePaths: AbsoluteSitePaths language: string } @@ -109,7 +110,6 @@ function getSimulatorsData({ t, sitePaths, language }: SimulatorsDataParams) { 'pages.simulateurs.salarié.alt-image1', 'Salaire net (perçu par le salarié) est égal à Salaire brut (inscrit dans le contrat de travail) moins cotisations salariales (retraite, csg, etc)' )} - css={``} /> Par ailleurs depuis 2019, l' @@ -746,7 +746,7 @@ export type ExtractFromSimuData = ExtractOrUndefined< >[T] export default function useSimulatorsData(): SimulatorData { - const { t, i18n } = useTranslation() + const [t, i18n] = useTranslation() const { absoluteSitePaths } = useSitePaths() return useMemo( diff --git a/site/source/types/react-i18next.d.ts b/site/source/types/react-i18next.d.ts new file mode 100644 index 000000000..2733181eb --- /dev/null +++ b/site/source/types/react-i18next.d.ts @@ -0,0 +1,8 @@ +import 'react-i18next' + +declare module 'i18next' { + interface CustomTypeOptions { + returnNull: false + allowObjectInHTMLChildren: true + } +}