Skip to content

Commit

Permalink
perf: séparation des textes de traduction de leur composant #571 #461 (
Browse files Browse the repository at this point in the history
…#577)

* perf: séparation des textes de traduction de leur composant #571 #461

* chore: déplace fichiers traductions proche de leur composant

* chore: convention de nommage .locale pour les fichiers contenant les traductions #571

* fix: corrections suite rebase

* chore: rangement dossiers
  • Loading branch information
ocruze authored Dec 13, 2024
1 parent 3a6adaf commit 92e3713
Show file tree
Hide file tree
Showing 99 changed files with 2,284 additions and 2,210 deletions.
4 changes: 2 additions & 2 deletions assets/components/Layout/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { useQuery } from "@tanstack/react-query";
import { FC, PropsWithChildren, ReactNode, memo, useMemo } from "react";

import { ConsentBannerAndConsentManagement } from "../../config/consentManagement";
import { defaultNavItems } from "../../config/navItems";
import { defaultNavItems } from "../../config/navItems/navItems";
import api from "../../entrepot/api";
import useDocumentTitle from "../../hooks/useDocumentTitle";
import { useTranslation } from "../../i18n/i18n";
import Translator from "../../modules/Translator";
import RQKeys from "../../modules/entrepot/RQKeys";
import getBreadcrumb from "../../modules/entrepot/breadcrumbs";
import getBreadcrumb from "../../modules/entrepot/breadcrumbs/Breadcrumb";
import { useRoute } from "../../router/router";
import SessionExpiredAlert from "../Utils/SessionExpiredAlert";
import SnackbarMessage from "../Utils/SnackbarMessage";
Expand Down
4 changes: 2 additions & 2 deletions assets/components/Layout/DatastoreLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { BreadcrumbProps } from "@codegouvfr/react-dsfr/Breadcrumb";
import { useQuery } from "@tanstack/react-query";
import { FC, PropsWithChildren, memo, useMemo } from "react";

import type { Datastore } from "../../@types/app";
import { datastoreNavItems } from "../../config/datastoreNavItems";
import { Datastore } from "../../@types/app";
import { datastoreNavItems } from "../../config/navItems/datastoreNavItems";
import api from "../../entrepot/api";
import RQKeys from "../../modules/entrepot/RQKeys";
import { CartesApiException } from "../../modules/jsonFetch";
Expand Down
3 changes: 2 additions & 1 deletion assets/components/Utils/LanguageSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { fr } from "@codegouvfr/react-dsfr";
import { memo, useId } from "react";
import { symToStr } from "tsafe/symToStr";

import { languagesDisplayNames, languages, type Language } from "../../i18n/i18n";
import { Language } from "../../i18n";
import { languages, languagesDisplayNames } from "../../i18n/types";

type Props = {
lang: Language;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MainNavigationProps } from "@codegouvfr/react-dsfr/MainNavigation";
import { TranslationFunction } from "i18nifty/typeUtils/TranslationFunction";

import { ComponentKey } from "../i18n/i18n";
import { routes } from "../router/router";
import { ComponentKey } from "../../i18n/types";
import { routes } from "../../router/router";

export const assistanceNavItems = (t: TranslationFunction<"navItems", ComponentKey>): MainNavigationProps.Item.Menu => {
return {
Expand Down
30 changes: 30 additions & 0 deletions assets/config/navItems/datastoreNavItems.locale.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { declareComponentKeys } from "i18nifty";

import { Translations } from "../../i18n/types";

const { i18n } = declareComponentKeys<
"dashboard" | "data" | "members" | "manage_storage" | "consumption_monitoring" | "permissions_granted" | "my_account" | "my_access_keys"
>()("datastoreNavItems");
export type I18n = typeof i18n;

export const datastoreNavItemsFrTranslations: Translations<"fr">["datastoreNavItems"] = {
dashboard: "Tableau de bord",
data: "Données",
members: "Membres",
manage_storage: "Gérer l’espace de travail",
consumption_monitoring: "Suivi des consommations",
permissions_granted: "Permissions accordées",
my_account: "Mon compte",
my_access_keys: "Mes clés d’accès",
};

export const datastoreNavItemsEnTranslations: Translations<"en">["datastoreNavItems"] = {
dashboard: undefined,
data: undefined,
members: undefined,
manage_storage: undefined,
consumption_monitoring: undefined,
permissions_granted: undefined,
my_account: undefined,
my_access_keys: undefined,
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type MainNavigationProps } from "@codegouvfr/react-dsfr/MainNavigation/MainNavigation";
import { declareComponentKeys } from "i18nifty";

import { Datastore } from "../@types/app";
import { Translations, getTranslation } from "../i18n/i18n";
import { routes } from "../router/router";
import { useAuthStore } from "../stores/AuthStore";
import { Datastore } from "../../@types/app";
import { getTranslation } from "../../i18n/i18n";
import { routes } from "../../router/router";
import { useAuthStore } from "../../stores/AuthStore";
import { assistanceNavItems } from "./assistanceNavItems";

const { t } = getTranslation("datastoreNavItems");
Expand Down Expand Up @@ -59,30 +58,3 @@ export const datastoreNavItems = (currentDatastore?: Datastore): MainNavigationP

return navItems;
};

// traductions
export const { i18n } = declareComponentKeys<
"dashboard" | "data" | "members" | "manage_storage" | "consumption_monitoring" | "permissions_granted" | "my_account" | "my_access_keys"
>()("datastoreNavItems");

export const datastoreNavItemsFrTranslations: Translations<"fr">["datastoreNavItems"] = {
dashboard: "Tableau de bord",
data: "Données",
members: "Membres",
manage_storage: "Gérer l’espace de travail",
consumption_monitoring: "Suivi des consommations",
permissions_granted: "Permissions accordées",
my_account: "Mon compte",
my_access_keys: "Mes clés d’accès",
};

export const datastoreNavItemsEnTranslations: Translations<"en">["datastoreNavItems"] = {
dashboard: undefined,
data: undefined,
members: undefined,
manage_storage: undefined,
consumption_monitoring: undefined,
permissions_granted: undefined,
my_account: undefined,
my_access_keys: undefined,
};
38 changes: 38 additions & 0 deletions assets/config/navItems/navItems.locale.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { declareComponentKeys } from "i18nifty";

import { Translations } from "../../i18n/types";

const { i18n } = declareComponentKeys<
"documentation" | "offer" | "join" | "faq" | "nous écrire" | "start" | "maps" | "catalog" | "news" | "assistance" | "service status" | "about"
>()("navItems");
export type I18n = typeof i18n;

export const navItemsFrTranslations: Translations<"fr">["navItems"] = {
"nous écrire": "Nous écrire",
documentation: "Documentation",
offer: "Offre",
join: "Nous rejoindre",
faq: "Questions fréquentes",
start: "Commencer avec cartes.gouv",
catalog: "Catalogue",
maps: "Cartes",
news: "Actualités",
assistance: "Assistance",
"service status": "Niveau de service",
about: "À propos",
};

export const navItemsEnTranslations: Translations<"en">["navItems"] = {
"nous écrire": "Contact us",
documentation: "Documentation",
offer: "Offer",
join: "Join us",
faq: "Frequently asked questions",
start: "Start with cartes.gouv",
catalog: "Catalog",
maps: "Maps",
news: "News",
assistance: "Assistance",
"service status": "Level of service",
about: "About",
};
39 changes: 2 additions & 37 deletions assets/config/navItems.ts → assets/config/navItems/navItems.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MainNavigationProps } from "@codegouvfr/react-dsfr/MainNavigation";
import { TranslationFunction } from "i18nifty/typeUtils/TranslationFunction";

import { ComponentKey, Translations, declareComponentKeys } from "../i18n/i18n";
import { routes } from "../router/router";
import { ComponentKey } from "../../i18n/types";
import { routes } from "../../router/router";
import { assistanceNavItems } from "./assistanceNavItems";

// dans ce cas précise, getTranslation ne marche pas parce que les traductions sont pas encore chargées, on est donc obglié de passer la fonction t en paramètre
Expand Down Expand Up @@ -46,38 +46,3 @@ export const defaultNavItems = (t: TranslationFunction<"navItems", ComponentKey>

return navItems;
};

// traductions
export const { i18n } = declareComponentKeys<
"documentation" | "offer" | "join" | "faq" | "nous écrire" | "start" | "maps" | "catalog" | "news" | "assistance" | "service status" | "about"
>()("navItems");

export const navItemsFrTranslations: Translations<"fr">["navItems"] = {
"nous écrire": "Nous écrire",
documentation: "Documentation",
offer: "Offre",
join: "Nous rejoindre",
faq: "Questions fréquentes",
start: "Commencer avec cartes.gouv",
catalog: "Catalogue",
maps: "Cartes",
news: "Actualités",
assistance: "Assistance",
"service status": "Niveau de service",
about: "À propos",
};

export const navItemsEnTranslations: Translations<"en">["navItems"] = {
"nous écrire": "Contact us",
documentation: "Documentation",
offer: "Offer",
join: "Join us",
faq: "Frequently asked questions",
start: "Start with cartes.gouv",
catalog: "Catalog",
maps: "Maps",
news: "News",
assistance: "Assistance",
"service status": "Level of service",
about: "About",
};
54 changes: 54 additions & 0 deletions assets/entrepot/pages/accesses-request/AccessesRequest.locale.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { declareComponentKeys } from "i18nifty";
import { Translations } from "../../../i18n/types";

const { i18n } = declareComponentKeys<
| "title"
| { K: "explain"; P: { url: string }; R: JSX.Element }
| "explain_no_access"
| "back_to_dashboard"
| "beneficiaries"
| { K: "beneficiaries_hintext"; R: JSX.Element }
| "myself"
| { K: "community"; P: { name: string }; R: string }
| "min_layers_error"
| "sending_message"
>()("AccessesRequest");
export type I18n = typeof i18n;

export const AccessesRequestFrTranslations: Translations<"fr">["AccessesRequest"] = {
title: "Demande d’accès",
explain: ({ url }) => (
<p>
Vous souhaitez demander au producteur des données décrites sur cette <a href={url}>fiche du catalogue</a> un accès aux services de diffusion de
données dont l&apos;accès est restreint. Sélectionnez les couches de données et types de services auxquels vous souhaitez accéder : (sélectionner au
moins une couche)
</p>
),
explain_no_access: "Cette fiche ne décrit aucun service de diffusion dont l’accès est restreint. Vous avez déjà accès à toutes les données décrites.",
back_to_dashboard: "Retour au tableau de bord",
beneficiaries: "Bénéficiaires",
beneficiaries_hintext: (
<span>
Vous pouvez demander au producteur des données de vous accorder une permission d&apos;accès personnelle ou
<br />
demander qu&apos;il accorde cette permission à tous les membres d&apos;une communauté à laquelle vous appartenez.
</span>
),
myself: "Moi-même",
community: ({ name }) => `La communauté ${name}`,
min_layers_error: "Vous devez sélectionner au moins une couche",
sending_message: "Votre message est en cours d’envoi ...",
};

export const AccessesRequestEnTranslations: Translations<"en">["AccessesRequest"] = {
title: undefined,
explain: undefined,
explain_no_access: undefined,
back_to_dashboard: undefined,
beneficiaries: "Bénéficiaries",
beneficiaries_hintext: undefined,
myself: "Myself",
community: ({ name }) => `Community ${name}`,
min_layers_error: undefined,
sending_message: undefined,
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import { ComponentProps, FC, ReactNode, useMemo, useState } from "react";
import { useForm } from "react-hook-form";
import * as yup from "yup";

import type { GeonetworkMetadataResponse } from "../../@types/app";
import AppLayout from "../../components/Layout/AppLayout";
import LoadingText from "../../components/Utils/LoadingText";
import Wait from "../../components/Utils/Wait";
import { Translations, declareComponentKeys, useTranslation } from "../../i18n/i18n";
import SymfonyRouting from "../../modules/Routing";
import RQKeys from "../../modules/entrepot/RQKeys";
import { CartesApiException, jsonFetch } from "../../modules/jsonFetch";
import { catalogueUrl, routes } from "../../router/router";
import { useAuthStore } from "../../stores/AuthStore";
import api from "../api";
import { GeonetworkMetadataResponse } from "../../../@types/app";
import AppLayout from "../../../components/Layout/AppLayout";
import LoadingText from "../../../components/Utils/LoadingText";
import Wait from "../../../components/Utils/Wait";
import { useTranslation } from "../../../i18n/i18n";
import SymfonyRouting from "../../../modules/Routing";
import RQKeys from "../../../modules/entrepot/RQKeys";
import { CartesApiException, jsonFetch } from "../../../modules/jsonFetch";
import { catalogueUrl, routes } from "../../../router/router";
import { useAuthStore } from "../../../stores/AuthStore";
import api from "../../api";

type AskForAccesses = {
fileIdentifier: string;
Expand Down Expand Up @@ -227,57 +227,3 @@ const AccessesRequest: FC<AskForAccesses> = ({ fileIdentifier }) => {
};

export default AccessesRequest;

// traductions
export const { i18n } = declareComponentKeys<
| "title"
| { K: "explain"; P: { url: string }; R: JSX.Element }
| "explain_no_access"
| "back_to_dashboard"
| "beneficiaries"
| { K: "beneficiaries_hintext"; R: JSX.Element }
| "myself"
| { K: "community"; P: { name: string }; R: string }
| "min_layers_error"
| "sending_message"
>()({
AccessesRequest,
});

export const AccessesRequestFrTranslations: Translations<"fr">["AccessesRequest"] = {
title: "Demande d’accès",
explain: ({ url }) => (
<p>
Vous souhaitez demander au producteur des données décrites sur cette <a href={url}>fiche du catalogue</a> un accès aux services de diffusion de
données dont l&apos;accès est restreint. Sélectionnez les couches de données et types de services auxquels vous souhaitez accéder : (sélectionner au
moins une couche)
</p>
),
explain_no_access: "Cette fiche ne décrit aucun service de diffusion dont l’accès est restreint. Vous avez déjà accès à toutes les données décrites.",
back_to_dashboard: "Retour au tableau de bord",
beneficiaries: "Bénéficiaires",
beneficiaries_hintext: (
<span>
Vous pouvez demander au producteur des données de vous accorder une permission d&apos;accès personnelle ou
<br />
demander qu&apos;il accorde cette permission à tous les membres d&apos;une communauté à laquelle vous appartenez.
</span>
),
myself: "Moi-même",
community: ({ name }) => `La communauté ${name}`,
min_layers_error: "Vous devez sélectionner au moins une couche",
sending_message: "Votre message est en cours d’envoi ...",
};

export const AccessesRequestEnTranslations: Translations<"en">["AccessesRequest"] = {
title: undefined,
explain: undefined,
explain_no_access: undefined,
back_to_dashboard: undefined,
beneficiaries: "Bénéficiaries",
beneficiaries_hintext: undefined,
myself: "Myself",
community: ({ name }) => `Community ${name}`,
min_layers_error: undefined,
sending_message: undefined,
};
28 changes: 28 additions & 0 deletions assets/entrepot/pages/communities/AddMember/AddMember.locale.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { declareComponentKeys } from "i18nifty";

import { Translations } from "../../../../i18n/types";

const { i18n } = declareComponentKeys<
"add_user_title" | "user_id" | "rights_granted" | "id_mandatory" | "id_must_be_uuid" | { K: "already_member"; P: { userId: string }; R: string } | "running"
>()("AddMember");
export type I18n = typeof i18n;

export const AddMemberFrTranslations: Translations<"fr">["AddMember"] = {
add_user_title: "Ajouter un utilisateur",
user_id: "Identifiant de l’utilisateur",
rights_granted: "Permissions accordées",
id_mandatory: "L’identifiant est obligatoire",
id_must_be_uuid: "L’Identifiant doit être un UUID",
already_member: ({ userId }) => `l’utilisateur ${userId} est déjà membre de cet espace de travail`,
running: "Ajout d’utilisateur en cours ...",
};

export const AddMemberEnTranslations: Translations<"en">["AddMember"] = {
add_user_title: "Add user",
user_id: "User identifier",
rights_granted: "Rights granted",
id_mandatory: "Identifier is mandatory",
id_must_be_uuid: "Identifier must be an UUID",
already_member: ({ userId }) => `User ${userId} is already a member of this community`,
running: "Ajout d’utilisateur running ...",
};
Loading

0 comments on commit 92e3713

Please sign in to comment.