-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathwithLegal.tsx
More file actions
84 lines (74 loc) · 2.14 KB
/
withLegal.tsx
File metadata and controls
84 lines (74 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import NavItem from '@node-core/ui-components/Containers/NavBar/NavItem';
import { useTranslations } from 'next-intl';
import Link from '#site/components/Link';
import type { FC } from 'react';
type LegalProps = {
footerLinks: Array<{
text: string;
link: string;
translation: string;
}>;
};
/**
* These keys match the following locations, and are kept in sync to lessen duplication:
* - translation keys within [locale].json components.containers.footer.links
* - keys within the large [locale].json components.containers.footer.legal paragraph
* - used directly to find the passed links from navigation.footerLinks
*/
const RICH_TRANSLATION_KEYS = [
'foundationName',
'trademarkPolicy',
'trademarkList',
'aiCodingAssistantsPolicy',
'termsOfUse',
'privacyPolicy',
'bylaws',
'codeOfConduct',
'cookiePolicy',
];
const WithLegal: FC<LegalProps> = ({ footerLinks }) => {
const t = useTranslations();
/**
* Takes the footerLinks from navigation constants and returns the link based on the final part of the translation key.
*
* Example: {
"link": "https://openjsf.org/",
"text": "components.containers.footer.links.foundationName"
},
*
*
* @param key the final part of a translation string
* @returns the link URL matching the translation key
*/
const getLinkFromTranslationKey = (key: string) => {
return footerLinks.find(link => link.text.split('.').pop() === key)?.link;
};
const richComponents = RICH_TRANSLATION_KEYS.reduce(
(acc, key) => {
acc[key] = (chunks: React.ReactNode) => (
<Link href={getLinkFromTranslationKey(key)}>{chunks}</Link>
);
return acc;
},
{} as Record<string, (text: React.ReactNode) => React.ReactNode>
);
return (
<>
<p>{t.rich('components.containers.footer.legal', richComponents)}</p>
<p>
{footerLinks.map(link => (
<NavItem
key={link.link}
type="footer"
href={link.link}
as={Link}
pathname={'/'}
>
{link.translation}
</NavItem>
))}
</p>
</>
);
};
export default WithLegal;