Skip to content

Commit

Permalink
translations#2
Browse files Browse the repository at this point in the history
  • Loading branch information
folland87 committed Mar 25, 2024
1 parent f36b98d commit 9d12dc0
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 107 deletions.
18 changes: 14 additions & 4 deletions client/locales.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
| Path | Status | Coder | Languages |
| ---------------------------------- | :----: | :----: | ----------: |
| /components/api-deprecation-banner | OK | FRED | FR,EN |
| /components/contact-form | OK | FRED | FR,EN |
| /components/api-deprecation-banner | OK | FRED | FR,EN |
| /components/contact-form | OK | FRED | FR,EN |
| /pages/about/contact | OK | Mihoub | FR,EN,ES,DE |
| /pages/about/resources | OK | Mihoub | FR,EN,ES,DE |
| /pages/about/team | OK | Mihoub | FR,EN,ES,DE |
| /pages/patents | TODO | Mihoub | FR |
| /pages/search/patent | TODO | Mihoub | FR |
| /pages/patents | TODO | Mihoub | FR |
| /pages/search/patent | TODO | Mihoub | FR |
| /components/copy | OK | FRED | FR,EN |
| /components/errors | OK | FRED | FR,EN |
| /components/footer | OK | FRED | FR,EN |
| /components/more-like-this | OK | FRED | FR,EN |
| /components/networks-notice | OK | FRED | FR,EN,ES,DE |
| /components/operator-button | OK | FRED | FR,EN |
| /components/truncate | OK | FRED | FR,EN,ES,DE |
| /components/websites | OK | FRED | FR,EN |
| /components/wiki | OK | FRED | FR,EN |
| /components/share | TODO | FRED | FR,EN |
27 changes: 24 additions & 3 deletions client/src/components/copy/copy-badge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import classNames from 'classnames';
import useCopyToClipboard from '../../hooks/useCopyToClipboard';
import styles from './styles.module.scss';
import { RawIntlProvider, createIntl } from 'react-intl';
import { useDSFRConfig } from '@dataesr/dsfr-plus';


const modules = import.meta.glob('./locales/*.json', { eager: true, import: 'default' })
const messages = Object.keys(modules).reduce((acc, key) => {
const locale = key.match(/\.\/locales\/(.+)\.json$/)?.[1];
if (locale) {
return { ...acc, [locale]: modules[key] }
}
return acc;
}, {});

export type CopyBadgeProps = {
lowercase?: boolean,
Expand All @@ -20,6 +32,8 @@ export default function CopyBadge({
children,
...remainingProps
}: CopyBadgeProps) {
const { locale } = useDSFRConfig();
const intl = createIntl({ locale, messages: messages[locale] });
const { copyStatus, copy } = useCopyToClipboard();
const _className = classNames(
'fr-badge',
Expand All @@ -35,11 +49,18 @@ export default function CopyBadge({
className,
);

const copyBadgeTitles = [
intl.formatMessage({ id: "copy-badge.copy" }),
intl.formatMessage({ id: "copy-badge.copied" }),
intl.formatMessage({ id: "copy-badge.error" }),
]

return (
<button title="Copier" onClick={() => copy(copyText)} type="button" className={_className} {...remainingProps}>
{children}
</button>
<RawIntlProvider value={intl}>
<button aria-label={copyBadgeTitles?.[copyStatus]} onClick={() => copy(copyText)} type="button" className={_className} {...remainingProps}>
{children}
</button>
</RawIntlProvider>
);
}

5 changes: 5 additions & 0 deletions client/src/components/copy/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"copy-badge.copy": "Copy value to clipboard",
"copy-badge.copied": "Value copied to clipboard",
"copy-badge.error": "Error copying value to clipboard"
}
5 changes: 5 additions & 0 deletions client/src/components/copy/locales/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"copy-badge.copy": "Copier la valeur dans le presse-papier",
"copy-badge.copied": "Valeur copié dans le presse-papier",
"copy-badge.error": "Erreur lors de la copie de la valeur dans le presse-papier"
}
106 changes: 61 additions & 45 deletions client/src/components/errors/error-404.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,68 @@
import { Notice } from "@dataesr/dsfr-plus";
import { Notice, useDSFRConfig } from "@dataesr/dsfr-plus";
import { RawIntlProvider, createIntl } from "react-intl";

const modules = import.meta.glob('./locales/*.json', { eager: true, import: 'default' })
const messages = Object.keys(modules).reduce((acc, key) => {
const locale = key.match(/\.\/locales\/(.+)\.json$/)?.[1];
if (locale) {
return { ...acc, [locale]: modules[key] }
}
return acc;
}, {});


export default function Error404({ error }: { error?: unknown }) {
const { locale } = useDSFRConfig();
const intl = createIntl({ locale, messages: messages[locale] });
return (
<div className="fr-container">
<div className="fr-my-7w fr-mt-md-12w fr-mb-md-10w fr-grid-row fr-grid-row--gutters fr-grid-row--middle fr-grid-row--center">
<div className="fr-py-0 fr-col-12 fr-col-md-6">
<h1>Page non trouvée</h1>
<p className="fr-text--sm fr-mb-3w">Erreur 404</p>
<p className="fr-text--lead fr-mb-3w">La page que vous cherchez est introuvable. Excusez-nous pour la gène occasionnée.</p>
<p className="fr-text--sm fr-mb-5w">
Si vous avez tapé l'adresse web dans le navigateur, vérifiez qu'elle est correcte. La page n’est peut-être plus disponible.
<br />
Dans ce cas, pour continuer votre visite vous pouvez consulter notre page d’accueil, ou effectuer une recherche avec notre moteur de recherche en haut de page.
<br />
Sinon contactez-nous pour que l’on puisse vous rediriger vers la bonne information.
</p>
<ul className="fr-btns-group fr-btns-group--inline-md">
<li>
<a className="fr-btn" href="/">
Page d'accueil
</a>
</li>
<li>
<a className="fr-btn fr-btn--secondary" href="[À MODIFIER - lien vers un formulaire de contact]">
Contactez-nous
</a>
</li>
</ul>
{error && <Notice className="fr-my-5w" type="error" closeMode="disallow">
<pre>
<code>
{JSON.stringify(error, null, 2)}
</code>
</pre>
</Notice>}
</div>
<div className="fr-col-12 fr-col-md-3 fr-col-offset-md-1 fr-px-6w fr-px-md-0 fr-py-0">
<svg xmlns="http://www.w3.org/2000/svg" className="fr-responsive-img fr-artwork" aria-hidden="true" width="160" height="200" viewBox="0 0 160 200">
<use className="fr-artwork-motif" href="/artwork/pictograms/system/ovoid.svg#artwork-motif" />
<use className="fr-artwork-background" href="/artwork/pictograms/system/ovoid.svg#artwork-background" />
<g transform="translate(40, 60)">
<use className="fr-artwork-decorative" href="/artwork/pictograms/system/technical-error.svg#artwork-decorative" />
<use className="fr-artwork-minor" href="/artwork/pictograms/system/technical-error.svg#artwork-minor" />
<use className="fr-artwork-major" href="/artwork/pictograms/system/technical-error.svg#artwork-major" />
</g>
</svg>
<RawIntlProvider value={intl}>
<div className="fr-container">
<div className="fr-my-7w fr-mt-md-12w fr-mb-md-10w fr-grid-row fr-grid-row--gutters fr-grid-row--middle fr-grid-row--center">
<div className="fr-py-0 fr-col-12 fr-col-md-6">
<h1>{intl.formatMessage({ id: "error404.title" })}</h1>
<p className="fr-text--sm fr-mb-3w">{intl.formatMessage({ id: "error404.code" })}</p>
<p className="fr-text--lead fr-mb-3w">{intl.formatMessage({ id: "error404.message" })}</p>
<p className="fr-text--sm fr-mb-5w">
{intl.formatMessage({ id: "error404.checkUrl" })}
<br />
{intl.formatMessage({ id: "error404.continue" })}
<br />
{intl.formatMessage({ id: "error404.contact" })}
</p>
<ul className="fr-btns-group fr-btns-group--inline-md">
<li>
<a className="fr-btn" href="/">
{intl.formatMessage({ id: "error.home" })}
</a>
</li>
<li>
<a className="fr-btn fr-btn--secondary" href="[À MODIFIER - lien vers un formulaire de contact]">
{intl.formatMessage({ id: "error.contactUs" })}
</a>
</li>
</ul>
{error && <Notice className="fr-my-5w" type="error" closeMode="disallow">
<pre>
<code>
{JSON.stringify(error, null, 2)}
</code>
</pre>
</Notice>}
</div>
<div className="fr-col-12 fr-col-md-3 fr-col-offset-md-1 fr-px-6w fr-px-md-0 fr-py-0">
<svg xmlns="http://www.w3.org/2000/svg" className="fr-responsive-img fr-artwork" aria-hidden="true" width="160" height="200" viewBox="0 0 160 200">
<use className="fr-artwork-motif" href="/artwork/pictograms/system/ovoid.svg#artwork-motif" />
<use className="fr-artwork-background" href="/artwork/pictograms/system/ovoid.svg#artwork-background" />
<g transform="translate(40, 60)">
<use className="fr-artwork-decorative" href="/artwork/pictograms/system/technical-error.svg#artwork-decorative" />
<use className="fr-artwork-minor" href="/artwork/pictograms/system/technical-error.svg#artwork-minor" />
<use className="fr-artwork-major" href="/artwork/pictograms/system/technical-error.svg#artwork-major" />
</g>
</svg>
</div>
</div>
</div>
</div>
</RawIntlProvider>

)
}
31 changes: 25 additions & 6 deletions client/src/components/errors/error-500.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
import { Notice } from "@dataesr/dsfr-plus";
import { Notice, useDSFRConfig } from "@dataesr/dsfr-plus";
import { createIntl } from "react-intl";

const modules = import.meta.glob('./locales/*.json', { eager: true, import: 'default' })
const messages = Object.keys(modules).reduce((acc, key) => {
const locale = key.match(/\.\/locales\/(.+)\.json$/)?.[1];
if (locale) {
return { ...acc, [locale]: modules[key] }
}
return acc;
}, {});


export default function Error500({ error }: { error: unknown }) {
const { locale } = useDSFRConfig();
const intl = createIntl({ locale, messages: messages[locale] });
return (
<div className="fr-container">
<div className="fr-my-7w fr-mt-md-12w fr-mb-md-10w fr-grid-row fr-grid-row--gutters fr-grid-row--middle fr-grid-row--center">
<div className="fr-py-0 fr-col-12 fr-col-md-6">
<h1>Erreur inattendue</h1>
<p className="fr-text--sm fr-mb-3w">Erreur 500</p>
<h1>
{intl.formatMessage({ id: "error500.title" })}
</h1>
<p className="fr-text--sm fr-mb-3w">
{intl.formatMessage({ id: "error500.code" })}
</p>
<p className="fr-text--sm fr-mb-5w">
Désolé, le service rencontre un problème, nous travaillons pour le résoudre le plus rapidement possible.
{intl.formatMessage({ id: "error500.message" })}
</p>
<p className="fr-text--md fr-mb-3w">
{intl.formatMessage({ id: "error500.tryAgain" })}
</p>
<p className="fr-text--md fr-mb-3w">Essayez de rafraîchir la page ou bien ressayez plus tard.</p>
<ul className="fr-btns-group fr-btns-group--inline-md">
<li>
<a className="fr-btn fr-btn--secondary" href="[À MODIFIER - lien vers un formulaire de contact]">
Contactez-nous
{intl.formatMessage({ id: "error.contactUs" })}
</a>
</li>
</ul>
Expand Down
14 changes: 14 additions & 0 deletions client/src/components/errors/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"error404.title": "Page not found",
"error404.code": "Error 404",
"error404.message": "The page you are looking for could not be found. We apologize for the inconvenience.",
"error404.checkUrl": "If you typed the web address in the browser, please make sure it is correct. The page may no longer be available.",
"error404.continue": "In this case, to continue your visit, you can check our homepage or perform a search using our search engine at the top of the page.",
"error404.contact": "Otherwise, please contact us so that we can redirect you to the correct information.",
"error.home": "Home",
"error.contactUs": "Contact Us",
"error500.title": "Unexpected Error",
"error500.code": "Error 500",
"error500.message": "Sorry, the service is experiencing a problem. We are working to resolve it as quickly as possible.",
"error500.tryAgain": "Please try refreshing the page or try again later."
}
14 changes: 14 additions & 0 deletions client/src/components/errors/locales/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"error404.title": "Page non trouvée",
"error404.code": "Erreur 404",
"error404.message": "La page que vous cherchez est introuvable. Excusez-nous pour la gène occasionnée.",
"error404.checkUrl": "Si vous avez tapé l'adresse web dans le navigateur, vérifiez qu'elle est correcte. La page n’est peut-être plus disponible.",
"error404.continue": "Dans ce cas, pour continuer votre visite vous pouvez consulter notre page d’accueil, ou effectuer une recherche avec notre moteur de recherche en haut de page.",
"error404.contact": "Sinon contactez-nous pour que l’on puisse vous rediriger vers la bonne information.",
"error.home": "Page d'accueil",
"error.contactUs": "Contactez-nous",
"error500.title": "Erreur inattendue",
"error500.code": "Erreur 500",
"error500.message": "Désolé, le service rencontre un problème, nous travaillons pour le résoudre le plus rapidement possible.",
"error500.tryAgain": "Essayez de rafraîchir la page ou bien ressayez plus tard."
}
14 changes: 0 additions & 14 deletions client/src/components/footer/locales/de.json

This file was deleted.

18 changes: 8 additions & 10 deletions client/src/components/footer/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"layout.header.nav.home": "Home",
"layout.header.nav.search": "Search",
"layout.header.nav.search.organizations": "Organizations",
"layout.header.nav.search.publications": "Publications",
"layout.header.nav.search.projects": "Fundings",
"layout.header.nav.search.authors": "Authors",
"layout.header.nav.search.patents": "Patents",
"layout.footer.top.about": "About",
"layout.footer.top.about.help": "Help",
"layout.footer.top.about.also": "See also",
"layout.footer.top.about.follow": "Follow us",
"layout.footer.top.about.faq": "FAQ",
"layout.footer.top.about.team": "Team",
"layout.switch-theme": "Display Settings",
"layout.header.nav.networks": "Explore Networks"
"layout.footer.top.about.team": "The team",
"layout.footer.top.about.resources": "Data sources",
"layout.footer.top.about.tutorial": "Tutorial",
"layout.footer.top.about.glossary": "Glossary",
"layout.footer.top.about.contact": "Contact"
}
14 changes: 0 additions & 14 deletions client/src/components/footer/locales/es.json

This file was deleted.

11 changes: 1 addition & 10 deletions client/src/components/footer/locales/fr.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
{
"layout.header.nav.home": "Accueil",
"layout.header.nav.search": "Rechercher",
"layout.header.nav.search.organizations": "Structures",
"layout.header.nav.search.publications": "Publications",
"layout.header.nav.search.projects": "Financements",
"layout.header.nav.search.authors": "Auteurs",
"layout.header.nav.search.patents": "Brevets",
"layout.footer.top.about": "A propos",
"layout.footer.top.about.help": "Aide",
"layout.footer.top.about.also": "Voir aussi",
Expand All @@ -15,7 +8,5 @@
"layout.footer.top.about.resources": "Sources de données",
"layout.footer.top.about.tutorial": "Tutoriel",
"layout.footer.top.about.glossary": "Glossaire",
"layout.footer.top.about.contact": "Contact",
"layout.switch-theme": "Paramètres d'affichage",
"layout.header.nav.networks": "Explorer les réseaux"
"layout.footer.top.about.contact": "Contact"
}
4 changes: 4 additions & 0 deletions client/src/components/more-like-this/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"more-like-this.error": "An error occurred while loading the data",
"more-like-this.empty": "No results"
}
2 changes: 1 addition & 1 deletion client/src/components/more-like-this/locales/fr.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"more-like-this.error": "Erreur lors du chargement des données",
"more-like-this.error": "Une erreur est survenue lors du chargement des données",
"more-like-this.empty": "Aucun résultat"
}
6 changes: 6 additions & 0 deletions client/src/components/operator-button/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"operator-button.label.and": "Intersection",
"operator-button.label.or": "Union",
"operator-button.switch.and": "Switch operator to 'OR'",
"operator-button.switch.or": "Switch operator to 'AND'"
}
Empty file.
Loading

0 comments on commit 9d12dc0

Please sign in to comment.