Skip to content

Commit f8786c3

Browse files
committed
Refactor i18n to enable Server Component
1 parent b14cb1c commit f8786c3

File tree

24 files changed

+95
-149
lines changed

24 files changed

+95
-149
lines changed

src/Accordion.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { fr } from "./fr";
77
import { cx } from "./tools/cx";
88
import { symToStr } from "tsafe/symToStr";
99
import { useConstCallback } from "./tools/powerhooks/useConstCallback";
10-
import "./dsfr/component/accordion/accordion.css";
1110

1211
export type AccordionProps = AccordionProps.Controlled | AccordionProps.Uncontrolled;
1312

src/Alert.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import { cx } from "./tools/cx";
99
import { assert } from "tsafe/assert";
1010
import type { Equals } from "tsafe";
1111
import { useConstCallback } from "./tools/powerhooks/useConstCallback";
12-
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
13-
import { useLang } from "./i18n/useLang";
12+
import { createComponentI18nApi } from "./i18n";
1413

1514
export type AlertProps = {
1615
className?: string;
@@ -132,7 +131,7 @@ export const Alert = memo(
132131
}
133132
});
134133

135-
const { t } = getTranslation(useLang());
134+
const { t } = useTranslation();
136135

137136
if (isClosed) {
138137
return null;
@@ -172,7 +171,7 @@ Alert.displayName = symToStr({ Alert });
172171

173172
export default Alert;
174173

175-
const { getTranslation, addAlertTranslations } = createComponentI18nApi({
174+
const { useTranslation, addAlertTranslations } = createComponentI18nApi({
176175
"componentName": symToStr({ Alert }),
177176
"frMessages": {
178177
/* spell-checker: disable */

src/Breadcrumb.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
"use client";
2-
31
import React, { memo, forwardRef, useId, ReactNode } from "react";
42
import { symToStr } from "tsafe/symToStr";
53
import { assert } from "tsafe/assert";
64
import type { Equals } from "tsafe";
75
import { getLink } from "./link";
86
import type { RegisteredLinkProps } from "./link";
9-
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
10-
import { useLang } from "./i18n/useLang";
7+
import { createComponentI18nApi } from "./i18n";
118
import { fr } from "./fr";
129
import { cx } from "./tools/cx";
1310

@@ -32,7 +29,7 @@ export const Breadcrumb = memo(
3229

3330
assert<Equals<keyof typeof rest, never>>();
3431

35-
const { t } = getTranslation(useLang());
32+
const { t } = useTranslation();
3633

3734
const { Link } = getLink();
3835
const breadcrumbId = useId();
@@ -80,7 +77,7 @@ export const Breadcrumb = memo(
8077

8178
Breadcrumb.displayName = symToStr({ Breadcrumb });
8279

83-
const { getTranslation, addBreadcrumbTranslations } = createComponentI18nApi({
80+
const { useTranslation, addBreadcrumbTranslations } = createComponentI18nApi({
8481
"componentName": symToStr({ Breadcrumb }),
8582
"frMessages": {
8683
/* spell-checker: disable */

src/Display.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
"use client";
2-
31
import React, { memo, forwardRef, useId } from "react";
42
import { fr } from "./fr";
53
import { symToStr } from "tsafe/symToStr";
6-
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
7-
import { useLang } from "./i18n/useLang";
4+
import { createComponentI18nApi } from "./i18n";
85
import { cx } from "./tools/cx";
96
import type { Equals } from "tsafe";
107
import { assert } from "tsafe/assert";
@@ -31,7 +28,7 @@ export const headerFooterDisplayItem: HeaderProps.QuickAccessItem.Button &
3128
"iconId": "fr-icon-theme-fill",
3229
"text": (() => {
3330
function Text() {
34-
const { t } = getTranslation(useLang());
31+
const { t } = useTranslation();
3532
return <>{t("display settings")}</>;
3633
}
3734

@@ -46,7 +43,7 @@ export const Display = memo(
4643

4744
assert<Equals<keyof typeof rest, never>>();
4845

49-
const { t } = getTranslation(useLang());
46+
const { t } = useTranslation();
5047

5148
return (
5249
<dialog
@@ -115,7 +112,7 @@ const RadioGroup = memo((props: { theme: "dark" | "light" | "system" }) => {
115112

116113
const inputId = useId();
117114

118-
const { t } = getTranslation(useLang());
115+
const { t } = useTranslation();
119116

120117
const pictogramUrl = getAssetUrl(
121118
(() => {
@@ -164,7 +161,7 @@ const RadioGroup = memo((props: { theme: "dark" | "light" | "system" }) => {
164161

165162
RadioGroup.displayName = symToStr({ RadioGroup });
166163

167-
const { getTranslation, addDisplayTranslations } = createComponentI18nApi({
164+
const { useTranslation, addDisplayTranslations } = createComponentI18nApi({
168165
"componentName": symToStr({ Display }),
169166
"frMessages": {
170167
/* spell-checker: disable */

src/Footer.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import React, { memo, forwardRef } from "react";
42
import type { ReactNode } from "react";
53
import { getLink } from "./link";
@@ -9,8 +7,7 @@ import { fr } from "./fr";
97
import { cx } from "./tools/cx";
108
import { assert } from "tsafe/assert";
119
import type { Equals } from "tsafe";
12-
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
13-
import { useLang } from "./i18n/useLang";
10+
import { createComponentI18nApi } from "./i18n";
1411
import type { FrIconClassName, RiIconClassName } from "./fr/generatedFromCss/classNames";
1512
import { id } from "tsafe/id";
1613

@@ -107,7 +104,7 @@ export const Footer = memo(
107104

108105
const { Link } = getLink();
109106

110-
const { t } = getTranslation(useLang());
107+
const { t } = useTranslation();
111108

112109
return (
113110
<footer
@@ -308,7 +305,7 @@ Footer.displayName = symToStr({ Footer });
308305

309306
export default Footer;
310307

311-
const { getTranslation, addFooterTranslations } = createComponentI18nApi({
308+
const { useTranslation, addFooterTranslations } = createComponentI18nApi({
312309
"componentName": symToStr({ Footer }),
313310
"frMessages": {
314311
/* spell-checker: disable */

src/Header/Header.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
"use client";
2-
31
import React, { memo, forwardRef, useId } from "react";
42
import type { ReactNode } from "react";
53
import { fr } from "../fr";
6-
import { createComponentI18nApi } from "../i18n/createComponentI18nApi";
7-
import { useLang } from "../i18n/useLang";
4+
import { createComponentI18nApi } from "../i18n";
85
import { symToStr } from "tsafe/symToStr";
96
import { cx } from "../tools/cx";
107
import { getLink } from "../link";
@@ -123,7 +120,7 @@ export const Header = memo(
123120
const searchModalId = `modal-${useId()}`;
124121
const searchInputId = `search-${useId()}-input`;
125122

126-
const { t } = getTranslation(useLang());
123+
const { t } = useTranslation();
127124

128125
const { Link } = getLink();
129126

@@ -374,7 +371,7 @@ Header.displayName = symToStr({ Header });
374371

375372
export default Header;
376373

377-
const { getTranslation, addHeaderTranslations } = createComponentI18nApi({
374+
const { useTranslation, addHeaderTranslations } = createComponentI18nApi({
378375
"componentName": symToStr({ Header }),
379376
"frMessages": {
380377
/* spell-checker: disable */

src/Header/MainNavigation/MainNavigation.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
"use client";
2-
31
import React, { memo, forwardRef, useId } from "react";
42
import type { ReactNode } from "react";
5-
import { createComponentI18nApi } from "../../i18n/createComponentI18nApi";
6-
import { useLang } from "../../i18n/useLang";
3+
import { createComponentI18nApi } from "../../i18n";
74
import { symToStr } from "tsafe/symToStr";
85
import { assert } from "tsafe/assert";
96
import type { Equals } from "tsafe";
@@ -76,7 +73,7 @@ export const MainNavigation = memo(
7673

7774
assert<Equals<keyof typeof rest, never>>();
7875

79-
const { t } = getTranslation(useLang());
76+
const { t } = useTranslation();
8077

8178
const { Link } = getLink();
8279

@@ -176,7 +173,7 @@ MainNavigation.displayName = symToStr({ MainNavigation });
176173

177174
export default MainNavigation;
178175

179-
const { getTranslation, addMainNavigationTranslations } = createComponentI18nApi({
176+
const { useTranslation, addMainNavigationTranslations } = createComponentI18nApi({
180177
"componentName": symToStr({ MainNavigation }),
181178
"frMessages": {
182179
/* spell-checker: disable */

src/Header/MainNavigation/MegaMenu.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
"use client";
2-
31
import React, { memo, forwardRef } from "react";
42
import type { ReactNode } from "react";
53
import { symToStr } from "tsafe/symToStr";
6-
import { createComponentI18nApi } from "../../i18n/createComponentI18nApi";
7-
import { useLang } from "../../i18n/useLang";
4+
import { createComponentI18nApi } from "../../i18n";
85
import { fr } from "../../fr";
96
import { cx } from "../../tools/cx";
107
import { assert } from "tsafe/assert";
@@ -46,7 +43,7 @@ export const MegaMenu = memo(
4643

4744
assert<Equals<keyof typeof rest, never>>();
4845

49-
const { t } = getTranslation(useLang());
46+
const { t } = useTranslation();
5047

5148
const { Link } = getLink();
5249

@@ -144,7 +141,7 @@ export const MegaMenu = memo(
144141

145142
MegaMenu.displayName = symToStr({ MegaMenu });
146143

147-
const { getTranslation, addMegaMenuTranslations } = createComponentI18nApi({
144+
const { useTranslation, addMegaMenuTranslations } = createComponentI18nApi({
148145
"componentName": symToStr({ MegaMenu }),
149146
"frMessages": {
150147
/* spell-checker: disable */

src/Highlight.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import React, { memo, forwardRef, ReactNode } from "react";
42
import { symToStr } from "tsafe/symToStr";
53
import { assert } from "tsafe/assert";

src/Notice.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { cx } from "./tools/cx";
77
import { assert } from "tsafe/assert";
88
import type { Equals } from "tsafe";
99
import { useConstCallback } from "./tools/powerhooks/useConstCallback";
10-
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
11-
import { useLang } from "./i18n/useLang";
10+
import { createComponentI18nApi } from "./i18n";
1211

1312
export type NoticeProps = {
1413
className?: string;
@@ -101,7 +100,7 @@ export const Notice = memo(
101100
}
102101
});
103102

104-
const { t } = getTranslation(useLang());
103+
const { t } = useTranslation();
105104

106105
if (isClosed) {
107106
return null;
@@ -138,7 +137,7 @@ Notice.displayName = symToStr({ Notice });
138137

139138
export default Notice;
140139

141-
const { getTranslation, addNoticeTranslations } = createComponentI18nApi({
140+
const { useTranslation, addNoticeTranslations } = createComponentI18nApi({
142141
"componentName": symToStr({ Notice }),
143142
"frMessages": {
144143
/* spell-checker: disable */

0 commit comments

Comments
 (0)