Skip to content

Commit c98824c

Browse files
committed
Decouple useLang and getTranslation (for prepare to accomodate server components)
1 parent 0c24e87 commit c98824c

File tree

15 files changed

+106
-92
lines changed

15 files changed

+106
-92
lines changed

src/Alert.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ 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/i18n";
12+
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
13+
import { useLang } from "./i18n/useLang";
1314

1415
export type AlertProps = {
1516
className?: string;
@@ -131,7 +132,7 @@ export const Alert = memo(
131132
}
132133
});
133134

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

136137
if (isClosed) {
137138
return null;
@@ -171,7 +172,7 @@ Alert.displayName = symToStr({ Alert });
171172

172173
export default Alert;
173174

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

src/Breadcrumb.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { assert } from "tsafe/assert";
66
import type { Equals } from "tsafe";
77
import { getLink } from "./link";
88
import type { RegisteredLinkProps } from "./link";
9-
import { createComponentI18nApi } from "./i18n/i18n";
9+
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
10+
import { useLang } from "./i18n/useLang";
1011
import { fr } from "./fr";
1112
import { cx } from "./tools/cx";
1213

@@ -31,7 +32,7 @@ export const Breadcrumb = memo(
3132

3233
assert<Equals<keyof typeof rest, never>>();
3334

34-
const { t } = useTranslation();
35+
const { t } = getTranslation(useLang());
3536

3637
const { Link } = getLink();
3738
const breadcrumbId = useId();
@@ -79,11 +80,13 @@ export const Breadcrumb = memo(
7980

8081
Breadcrumb.displayName = symToStr({ Breadcrumb });
8182

82-
const { useTranslation, addBreadcrumbTranslations } = createComponentI18nApi({
83+
const { getTranslation, addBreadcrumbTranslations } = createComponentI18nApi({
8384
"componentName": symToStr({ Breadcrumb }),
8485
"frMessages": {
86+
/* spell-checker: disable */
8587
"show breadcrumb": "Voir le fil d’Ariane",
8688
"navigation label": "vous êtes ici"
89+
/* spell-checker: enable */
8790
}
8891
});
8992

src/Display.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import React, { memo, forwardRef, useId } from "react";
44
import { fr } from "./fr";
55
import { symToStr } from "tsafe/symToStr";
6-
import { createComponentI18nApi } from "./i18n/i18n";
6+
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
7+
import { useLang } from "./i18n/useLang";
78
import { cx } from "./tools/cx";
89
import type { Equals } from "tsafe";
910
import { assert } from "tsafe/assert";
@@ -30,7 +31,7 @@ export const headerFooterDisplayItem: HeaderProps.QuickAccessItem.Button &
3031
"iconId": "fr-icon-theme-fill",
3132
"text": (() => {
3233
function Text() {
33-
const { t } = useTranslation();
34+
const { t } = getTranslation(useLang());
3435
return <>{t("display settings")}</>;
3536
}
3637

@@ -45,7 +46,7 @@ export const Display = memo(
4546

4647
assert<Equals<keyof typeof rest, never>>();
4748

48-
const { t } = useTranslation();
49+
const { t } = getTranslation(useLang());
4950

5051
return (
5152
<dialog
@@ -114,7 +115,7 @@ const RadioGroup = memo((props: { theme: "dark" | "light" | "system" }) => {
114115

115116
const inputId = useId();
116117

117-
const { t } = useTranslation();
118+
const { t } = getTranslation(useLang());
118119

119120
const pictogramUrl = getAssetUrl(
120121
(() => {
@@ -163,7 +164,7 @@ const RadioGroup = memo((props: { theme: "dark" | "light" | "system" }) => {
163164

164165
RadioGroup.displayName = symToStr({ RadioGroup });
165166

166-
const { useTranslation, addDisplayTranslations } = createComponentI18nApi({
167+
const { getTranslation, addDisplayTranslations } = createComponentI18nApi({
167168
"componentName": symToStr({ Display }),
168169
"frMessages": {
169170
/* spell-checker: disable */

src/Footer.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { fr } from "./fr";
99
import { cx } from "./tools/cx";
1010
import { assert } from "tsafe/assert";
1111
import type { Equals } from "tsafe";
12-
import { createComponentI18nApi } from "./i18n/i18n";
12+
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
13+
import { useLang } from "./i18n/useLang";
1314
import type { FrIconClassName, RiIconClassName } from "./fr/generatedFromCss/classNames";
1415
import { id } from "tsafe/id";
1516

@@ -106,7 +107,7 @@ export const Footer = memo(
106107

107108
const { Link } = getLink();
108109

109-
const { t } = useTranslation();
110+
const { t } = getTranslation(useLang());
110111

111112
return (
112113
<footer
@@ -307,7 +308,7 @@ Footer.displayName = symToStr({ Footer });
307308

308309
export default Footer;
309310

310-
const { useTranslation, addFooterTranslations } = createComponentI18nApi({
311+
const { getTranslation, addFooterTranslations } = createComponentI18nApi({
311312
"componentName": symToStr({ Footer }),
312313
"frMessages": {
313314
/* spell-checker: disable */

src/Header/Header.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import React, { memo, forwardRef, useId } from "react";
44
import type { ReactNode } from "react";
55
import { fr } from "../fr";
6-
import { createComponentI18nApi } from "../i18n/i18n";
6+
import { createComponentI18nApi } from "../i18n/createComponentI18nApi";
7+
import { useLang } from "../i18n/useLang";
78
import { symToStr } from "tsafe/symToStr";
89
import { cx } from "../tools/cx";
910
import { getLink } from "../link";
@@ -122,7 +123,7 @@ export const Header = memo(
122123
const searchModalId = `modal-${useId()}`;
123124
const searchInputId = `search-${useId()}-input`;
124125

125-
const { t } = useTranslation();
126+
const { t } = getTranslation(useLang());
126127

127128
const { Link } = getLink();
128129

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

374375
export default Header;
375376

376-
const { useTranslation, addHeaderTranslations } = createComponentI18nApi({
377+
const { getTranslation, addHeaderTranslations } = createComponentI18nApi({
377378
"componentName": symToStr({ Header }),
378379
"frMessages": {
379380
/* spell-checker: disable */

src/Header/MainNavigation/MainNavigation.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import React, { memo, forwardRef, useId } from "react";
44
import type { ReactNode } from "react";
5-
import { createComponentI18nApi } from "../../i18n/i18n";
5+
import { createComponentI18nApi } from "../../i18n/createComponentI18nApi";
6+
import { useLang } from "../../i18n/useLang";
67
import { symToStr } from "tsafe/symToStr";
78
import { assert } from "tsafe/assert";
89
import type { Equals } from "tsafe";
@@ -75,7 +76,7 @@ export const MainNavigation = memo(
7576

7677
assert<Equals<keyof typeof rest, never>>();
7778

78-
const { t } = useTranslation();
79+
const { t } = getTranslation(useLang());
7980

8081
const { Link } = getLink();
8182

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

176177
export default MainNavigation;
177178

178-
const { useTranslation, addMainNavigationTranslations } = createComponentI18nApi({
179+
const { getTranslation, addMainNavigationTranslations } = createComponentI18nApi({
179180
"componentName": symToStr({ MainNavigation }),
180181
"frMessages": {
181182
/* spell-checker: disable */

src/Header/MainNavigation/MegaMenu.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import React, { memo, forwardRef } from "react";
44
import type { ReactNode } from "react";
55
import { symToStr } from "tsafe/symToStr";
6-
import { createComponentI18nApi } from "../../i18n/i18n";
6+
import { createComponentI18nApi } from "../../i18n/createComponentI18nApi";
7+
import { useLang } from "../../i18n/useLang";
78
import { fr } from "../../fr";
89
import { cx } from "../../tools/cx";
910
import { assert } from "tsafe/assert";
@@ -45,7 +46,7 @@ export const MegaMenu = memo(
4546

4647
assert<Equals<keyof typeof rest, never>>();
4748

48-
const { t } = useTranslation();
49+
const { t } = getTranslation(useLang());
4950

5051
const { Link } = getLink();
5152

@@ -143,7 +144,7 @@ export const MegaMenu = memo(
143144

144145
MegaMenu.displayName = symToStr({ MegaMenu });
145146

146-
const { useTranslation, addMegaMenuTranslations } = createComponentI18nApi({
147+
const { getTranslation, addMegaMenuTranslations } = createComponentI18nApi({
147148
"componentName": symToStr({ MegaMenu }),
148149
"frMessages": {
149150
/* spell-checker: disable */

src/Notice.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ 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/i18n";
10+
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
11+
import { useLang } from "./i18n/useLang";
1112

1213
export type NoticeProps = {
1314
className?: string;
@@ -100,7 +101,7 @@ export const Notice = memo(
100101
}
101102
});
102103

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

105106
if (isClosed) {
106107
return null;
@@ -137,7 +138,7 @@ Notice.displayName = symToStr({ Notice });
137138

138139
export default Notice;
139140

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

src/SkipLinks.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import React, { forwardRef, memo } from "react";
44
import { assert, Equals } from "tsafe";
55
import { symToStr } from "tsafe/symToStr";
66
import { fr } from "./fr";
7-
import { createComponentI18nApi } from "./i18n/i18n";
7+
import { createComponentI18nApi } from "./i18n/createComponentI18nApi";
8+
import { useLang } from "./i18n/useLang";
89
import { cx } from "./tools/cx";
910

1011
export type SkipLink = {
@@ -22,7 +23,7 @@ export type SkipLinksProps = {
2223
export const SkipLinks = memo(
2324
forwardRef<HTMLDivElement, SkipLinksProps>((props, ref) => {
2425
const { className, classes = {}, links, ...rest } = props;
25-
const { t } = useTranslation();
26+
const { t } = getTranslation(useLang());
2627
assert<Equals<keyof typeof rest, never>>();
2728

2829
return (
@@ -49,7 +50,7 @@ export const SkipLinks = memo(
4950

5051
SkipLinks.displayName = symToStr({ SkipLinks });
5152

52-
const { useTranslation, addSkipLinksTranslations } = createComponentI18nApi({
53+
const { getTranslation, addSkipLinksTranslations } = createComponentI18nApi({
5354
"componentName": symToStr({ SkipLinks }),
5455
"frMessages": {
5556
/* spell-checker: disable */

src/Stepper.tsx

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

1213
export type StepperProps = {
1314
className?: string;
@@ -33,7 +34,7 @@ export const Stepper = memo(
3334

3435
assert<Equals<keyof typeof rest, never>>();
3536

36-
const { t } = useTranslation();
37+
const { t } = getTranslation(useLang());
3738

3839
return (
3940
<div className={cx(fr.cx("fr-stepper"), classes.root, className)} ref={ref}>
@@ -60,7 +61,7 @@ export const Stepper = memo(
6061

6162
Stepper.displayName = symToStr({ Stepper });
6263

63-
const { useTranslation, addStepperTranslations } = createComponentI18nApi({
64+
const { getTranslation, addStepperTranslations } = createComponentI18nApi({
6465
"componentName": symToStr({ Stepper }),
6566
"frMessages": {
6667
/* spell-checker: disable */

0 commit comments

Comments
 (0)