@canonical/summon-application 0.34.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/dist/esm/application/react/index.js +403 -277
- package/dist/esm/application/react/index.js.map +1 -1
- package/dist/esm/application/react/templates/.storybook/decorators/index.ts.ejs +4 -0
- package/dist/esm/application/react/templates/.storybook/decorators/withI18n.tsx +35 -0
- package/dist/esm/application/react/templates/.storybook/decorators/withRouter.tsx +18 -20
- package/dist/esm/application/react/templates/.storybook/preview.ts.ejs +35 -0
- package/dist/esm/application/react/templates/index.html.ejs +2 -1
- package/dist/esm/application/react/templates/package.json.ejs +34 -3
- package/dist/esm/application/react/templates/src/client/entry.tsx.ejs +109 -10
- package/dist/esm/application/react/templates/src/domains/account/{AccountPage.tsx → AccountPage.tsx.ejs} +13 -0
- package/dist/esm/application/react/templates/src/domains/account/LoginPage.tsx.ejs +51 -0
- package/dist/esm/application/react/templates/src/domains/account/routes.ts +21 -8
- package/dist/esm/application/react/templates/src/domains/catalog/CatalogPage.tsx.ejs +97 -0
- package/dist/esm/application/react/templates/src/domains/catalog/{ErrorBoundary.tests.tsx → ErrorBoundary.tests.tsx.ejs} +24 -0
- package/dist/esm/application/react/templates/src/domains/catalog/{ProductCard.tsx → ProductCard.tsx.ejs} +31 -0
- package/dist/esm/application/react/templates/src/domains/catalog/{ProductList.stories.tsx → ProductList.stories.tsx.ejs} +63 -4
- package/dist/esm/application/react/templates/src/domains/catalog/{ProductList.tests.tsx → ProductList.tests.tsx.ejs} +44 -0
- package/dist/esm/application/react/templates/src/domains/catalog/{ProductList.tsx → ProductList.tsx.ejs} +30 -2
- package/dist/esm/application/react/templates/src/domains/catalog/routes.ts +25 -0
- package/dist/esm/application/react/templates/src/domains/contact/{ContactPage.tsx → ContactPage.tsx.ejs} +40 -0
- package/dist/esm/application/react/templates/src/domains/marketing/GuidePage.tsx.ejs +33 -0
- package/dist/esm/application/react/templates/src/domains/marketing/{HomePage.tsx → HomePage.tsx.ejs} +30 -0
- package/dist/esm/application/react/templates/src/domains/marketing/routes.ts +25 -0
- package/dist/esm/application/react/templates/src/i18n/ar.ts +74 -0
- package/dist/esm/application/react/templates/src/i18n/catalogs.ts +14 -0
- package/dist/esm/application/react/templates/src/i18n/config.ts +19 -0
- package/dist/esm/application/react/templates/src/i18n/en.ts +73 -0
- package/dist/esm/application/react/templates/src/i18n/fr.ts +70 -0
- package/dist/esm/application/react/templates/src/i18n/index.ts +5 -0
- package/dist/esm/application/react/templates/src/i18n/negotiation.tests.ts +92 -0
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/LocaleSelector.tests.tsx +60 -0
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/LocaleSelector.tsx +44 -0
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/index.ts +1 -0
- package/dist/esm/application/react/templates/src/lib/Navigation/Navigation.tsx.ejs +34 -0
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/{ThemeSelector.tsx → ThemeSelector.tsx.ejs} +16 -0
- package/dist/esm/application/react/templates/src/lib/index.ts.ejs +3 -0
- package/dist/esm/application/react/templates/src/relay/environment.ts +153 -5
- package/dist/esm/application/react/templates/src/routes.tsx.ejs +137 -33
- package/dist/esm/application/react/templates/src/server/entry.tsx.ejs +293 -11
- package/dist/esm/application/react/templates/src/server/preview.bun.ts +30 -7
- package/dist/esm/application/react/templates/src/server/preview.express.ts +19 -4
- package/dist/esm/application/react/templates/src/server/renderer.tsx.ejs +125 -0
- package/dist/esm/application/react/templates/src/server/{server.bun.ts → server.bun.ts.ejs} +56 -4
- package/dist/esm/application/react/templates/src/server/{server.express.ts → server.express.ts.ejs} +48 -4
- package/dist/esm/application/react/templates/test/e2e/servers.e2e.ts.ejs +197 -0
- package/dist/esm/application/react/templates/tsconfig.json.ejs +3 -0
- package/dist/esm/application/react/templates/vite.config.ts.ejs +5 -0
- package/dist/esm/domain/index.js +8 -1
- package/dist/esm/domain/index.js.map +1 -1
- package/dist/esm/route/index.js +12 -2
- package/dist/esm/route/index.js.map +1 -1
- package/dist/esm/route/insertRoute.js +39 -11
- package/dist/esm/route/insertRoute.js.map +1 -1
- package/dist/esm/shared/packageName.js +7 -0
- package/dist/esm/shared/packageName.js.map +1 -0
- package/dist/esm/shared/packageVersion.js +50 -0
- package/dist/esm/shared/packageVersion.js.map +1 -0
- package/dist/esm/shared/validators.js +61 -0
- package/dist/esm/shared/validators.js.map +1 -0
- package/dist/esm/shared/versions.js +87 -55
- package/dist/esm/shared/versions.js.map +1 -1
- package/dist/esm/shared/workspace.js +57 -0
- package/dist/esm/shared/workspace.js.map +1 -1
- package/dist/esm/wrapper/index.js +8 -1
- package/dist/esm/wrapper/index.js.map +1 -1
- package/dist/types/application/react/index.d.ts +1 -2
- package/dist/types/application/react/index.d.ts.map +1 -1
- package/dist/types/domain/index.d.ts.map +1 -1
- package/dist/types/route/index.d.ts.map +1 -1
- package/dist/types/shared/packageName.d.ts +7 -0
- package/dist/types/shared/packageName.d.ts.map +1 -0
- package/dist/types/shared/packageVersion.d.ts +15 -0
- package/dist/types/shared/packageVersion.d.ts.map +1 -0
- package/dist/types/shared/validators.d.ts +21 -0
- package/dist/types/shared/validators.d.ts.map +1 -0
- package/dist/types/shared/versions.d.ts +14 -5
- package/dist/types/shared/versions.d.ts.map +1 -1
- package/dist/types/shared/workspace.d.ts.map +1 -1
- package/dist/types/wrapper/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/esm/application/react/templates/.storybook/decorators/index.ts +0 -1
- package/dist/esm/application/react/templates/.storybook/preview.ts +0 -10
- package/dist/esm/application/react/templates/src/domains/account/LoginPage.tsx +0 -27
- package/dist/esm/application/react/templates/src/domains/catalog/CatalogPage.tsx +0 -50
- package/dist/esm/application/react/templates/src/domains/marketing/GuidePage.tsx +0 -17
- package/dist/esm/application/react/templates/src/server/renderer.tsx +0 -50
- package/dist/esm/application/react/templates/test/e2e/servers.e2e.ts +0 -99
|
@@ -1,7 +1,31 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@canonical/router-core";
|
|
1
2
|
import { route } from "@canonical/router-core";
|
|
2
3
|
import GuidePage from "./GuidePage.js";
|
|
3
4
|
import HomePage from "./HomePage.js";
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Standard Schema v1 params validator — the same interface Zod, Valibot, and
|
|
8
|
+
* ArkType schemas implement, so any of them can be dropped in here directly.
|
|
9
|
+
* A slug that is not lowercase kebab-case makes the URL a non-match: the
|
|
10
|
+
* router falls through to the not-found route (404) instead of rendering.
|
|
11
|
+
*/
|
|
12
|
+
const guideParamsSchema: StandardSchemaV1<
|
|
13
|
+
{ readonly slug: string },
|
|
14
|
+
{ readonly slug: string }
|
|
15
|
+
> = {
|
|
16
|
+
"~standard": {
|
|
17
|
+
version: 1,
|
|
18
|
+
vendor: "boilerplate",
|
|
19
|
+
validate(value) {
|
|
20
|
+
const record = value as { slug?: string };
|
|
21
|
+
|
|
22
|
+
return record.slug && /^[a-z0-9]+(-[a-z0-9]+)*$/.test(record.slug)
|
|
23
|
+
? { value: { slug: record.slug } }
|
|
24
|
+
: { issues: [{ message: "slug must be lowercase kebab-case" }] };
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
5
29
|
const routes = {
|
|
6
30
|
home: route({
|
|
7
31
|
url: "/",
|
|
@@ -9,6 +33,7 @@ const routes = {
|
|
|
9
33
|
}),
|
|
10
34
|
guide: route({
|
|
11
35
|
url: "/guides/:slug",
|
|
36
|
+
params: guideParamsSchema,
|
|
12
37
|
content: GuidePage,
|
|
13
38
|
}),
|
|
14
39
|
} as const;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { MessageValue } from "@canonical/i18n-core";
|
|
2
|
+
import type { MessageKey } from "./en.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Arabic messages. Typed against the English key set, so the catalogs can
|
|
6
|
+
* never drift apart silently.
|
|
7
|
+
*
|
|
8
|
+
* Arabic is the app's right-to-left demonstration locale, and its plural
|
|
9
|
+
* system uses all six CLDR categories — `catalog.showing` spells them out,
|
|
10
|
+
* which `Intl.PluralRules("ar")` selects from at runtime.
|
|
11
|
+
*/
|
|
12
|
+
const ar: Record<MessageKey, MessageValue> = {
|
|
13
|
+
"nav.label": "رئيسي",
|
|
14
|
+
"nav.home": "الرئيسية",
|
|
15
|
+
"nav.guide": "الدليل",
|
|
16
|
+
"nav.catalog": "الكتالوج",
|
|
17
|
+
"nav.contact": "اتصل بنا",
|
|
18
|
+
"nav.signIn": "تسجيل دخول تجريبي",
|
|
19
|
+
"theme.label": "سمة الألوان",
|
|
20
|
+
"theme.system": "النظام",
|
|
21
|
+
"theme.light": "فاتح",
|
|
22
|
+
"theme.dark": "داكن",
|
|
23
|
+
"locale.label": "اللغة",
|
|
24
|
+
"notFound.heading": "الصفحة غير موجودة",
|
|
25
|
+
"notFound.body": "الصفحة التي تبحث عنها غير موجودة.",
|
|
26
|
+
"home.title": "الرئيسية — Boilerplate",
|
|
27
|
+
"home.heading": "الرئيسية",
|
|
28
|
+
"home.tagline": "مرحبًا بك في تطبيق pragma النموذجي.",
|
|
29
|
+
"home.exampleHeading": "مكوّن مثال",
|
|
30
|
+
"home.streamingHeading": "البث مع Suspense",
|
|
31
|
+
"home.streamFallback": "جارٍ تحميل المحتوى المتدفق…",
|
|
32
|
+
"guide.title": "{slug} — أدلة",
|
|
33
|
+
"guide.body": "محتوى الدليل عن {slug}.",
|
|
34
|
+
"account.title": "الحساب — Boilerplate",
|
|
35
|
+
"account.heading": "الحساب",
|
|
36
|
+
"account.body": "صفحة حساب محمية. أنت مسجّل الدخول.",
|
|
37
|
+
"login.title": "تسجيل الدخول — Boilerplate",
|
|
38
|
+
"login.heading": "تسجيل الدخول",
|
|
39
|
+
"login.hintBefore": "تسجيل دخول تجريبي. أضف",
|
|
40
|
+
"login.hintAfter": "إلى أي عنوان محمي لمحاكاة المصادقة.",
|
|
41
|
+
"login.redirect": "ستتم إعادة توجيهك إلى {from} بعد تسجيل الدخول.",
|
|
42
|
+
"contact.title": "اتصل بنا",
|
|
43
|
+
"contact.heading": "اتصل بنا",
|
|
44
|
+
"contact.name": "الاسم الكامل",
|
|
45
|
+
"contact.email": "البريد الإلكتروني",
|
|
46
|
+
"contact.emailRequired": "البريد الإلكتروني مطلوب",
|
|
47
|
+
"contact.subject": "الموضوع",
|
|
48
|
+
"contact.subjectGeneral": "استفسار عام",
|
|
49
|
+
"contact.subjectSupport": "الدعم",
|
|
50
|
+
"contact.subjectFeedback": "ملاحظات",
|
|
51
|
+
"contact.message": "الرسالة",
|
|
52
|
+
"contact.messageHint": "500 حرف كحد أقصى",
|
|
53
|
+
"contact.send": "إرسال الرسالة",
|
|
54
|
+
"catalog.title": "الكتالوج — Boilerplate",
|
|
55
|
+
"catalog.heading": "الكتالوج",
|
|
56
|
+
"catalog.loading": "جارٍ تحميل الكتالوج…",
|
|
57
|
+
"catalog.error": "تعذّر تحميل الكتالوج. أعد تحميل الصفحة للمحاولة مرة أخرى.",
|
|
58
|
+
"catalog.listLabel": "كتالوج المنتجات",
|
|
59
|
+
"catalog.signedInAs": "مسجّل الدخول باسم",
|
|
60
|
+
"catalog.showing": {
|
|
61
|
+
zero: "— لا توجد منتجات.",
|
|
62
|
+
one: "— عرض {shown} من منتج واحد.",
|
|
63
|
+
two: "— عرض {shown} من منتجين.",
|
|
64
|
+
few: "— عرض {shown} من {count} منتجات.",
|
|
65
|
+
many: "— عرض {shown} من {count} منتجًا.",
|
|
66
|
+
other: "— عرض {shown} من {count} منتج.",
|
|
67
|
+
},
|
|
68
|
+
"catalog.more": "تتوفر منتجات إضافية.",
|
|
69
|
+
"catalog.rating": "التقييم {rating} من 5",
|
|
70
|
+
"catalog.inStock": "متوفر",
|
|
71
|
+
"catalog.outOfStock": "غير متوفر",
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export default ar;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Messages } from "@canonical/i18n-core";
|
|
2
|
+
import ar from "./ar.js";
|
|
3
|
+
import type { AppLocale } from "./config.js";
|
|
4
|
+
import en from "./en.js";
|
|
5
|
+
import fr from "./fr.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Message catalogs keyed by locale tag, one entry per locale in
|
|
9
|
+
* `i18nConfig.locales` — `AppLocale` is derived from the config, so adding a
|
|
10
|
+
* locale there without adding its catalog here is a compile error. Passed to
|
|
11
|
+
* the `I18nProvider` on both the server and the client; `useTranslation`
|
|
12
|
+
* picks the active locale's catalog from it.
|
|
13
|
+
*/
|
|
14
|
+
export const catalogs = { en, fr, ar } satisfies Record<AppLocale, Messages>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { I18nConfig } from "@canonical/i18n-core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The app's locale configuration, consumed by `@canonical/i18n-core`
|
|
5
|
+
* negotiation on the server and by the `I18nProvider` on both sides.
|
|
6
|
+
*
|
|
7
|
+
* Locales are declared explicitly rather than discovered by convention
|
|
8
|
+
* (Constitution VI — no magic). `ar` is included to exercise the
|
|
9
|
+
* right-to-left path end to end: `rtlLocales` drives `directionOf` /
|
|
10
|
+
* `documentAttrs`, so `<html dir>` flips without any app-side branching.
|
|
11
|
+
*/
|
|
12
|
+
export const i18nConfig = {
|
|
13
|
+
locales: ["en", "fr", "ar"],
|
|
14
|
+
defaultLocale: "en",
|
|
15
|
+
rtlLocales: ["ar"],
|
|
16
|
+
} as const satisfies I18nConfig;
|
|
17
|
+
|
|
18
|
+
/** Union of the app's configured locale tags, derived from the config. */
|
|
19
|
+
export type AppLocale = (typeof i18nConfig.locales)[number];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Messages } from "@canonical/i18n-core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* English messages — the reference catalog. Its keys define the app's full
|
|
5
|
+
* message surface; the other locales are typed against them (see `fr.ts`),
|
|
6
|
+
* so adding a key here without translating it is a compile error.
|
|
7
|
+
*
|
|
8
|
+
* Keys are dotted namespaces per UI area. Values interpolate `{placeholder}`
|
|
9
|
+
* slots via `createTranslator`; plural entries select a branch from
|
|
10
|
+
* `vars.count` through `Intl.PluralRules`.
|
|
11
|
+
*/
|
|
12
|
+
const en = {
|
|
13
|
+
"nav.label": "Main",
|
|
14
|
+
"nav.home": "Home",
|
|
15
|
+
"nav.guide": "Guide",
|
|
16
|
+
"nav.catalog": "Catalog",
|
|
17
|
+
"nav.contact": "Contact",
|
|
18
|
+
"nav.signIn": "Demo sign-in",
|
|
19
|
+
"theme.label": "Color theme",
|
|
20
|
+
"theme.system": "System",
|
|
21
|
+
"theme.light": "Light",
|
|
22
|
+
"theme.dark": "Dark",
|
|
23
|
+
"locale.label": "Language",
|
|
24
|
+
"notFound.heading": "Page not found",
|
|
25
|
+
"notFound.body": "The page you are looking for does not exist.",
|
|
26
|
+
"home.title": "Home — Boilerplate",
|
|
27
|
+
"home.heading": "Home",
|
|
28
|
+
"home.tagline": "Welcome to the pragma router boilerplate.",
|
|
29
|
+
"home.exampleHeading": "Example component",
|
|
30
|
+
"home.streamingHeading": "Streaming with Suspense",
|
|
31
|
+
"home.streamFallback": "Loading streamed content…",
|
|
32
|
+
"guide.title": "{slug} — Guides",
|
|
33
|
+
"guide.body": "Guide content for {slug}.",
|
|
34
|
+
"account.title": "Account — Boilerplate",
|
|
35
|
+
"account.heading": "Account",
|
|
36
|
+
"account.body": "Protected account page. You are signed in.",
|
|
37
|
+
"login.title": "Login — Boilerplate",
|
|
38
|
+
"login.heading": "Login",
|
|
39
|
+
"login.hintBefore": "Demo login. Add",
|
|
40
|
+
"login.hintAfter": "to any protected URL to simulate authentication.",
|
|
41
|
+
"login.redirect": "You will be redirected to {from} after login.",
|
|
42
|
+
"contact.title": "Contact",
|
|
43
|
+
"contact.heading": "Contact",
|
|
44
|
+
"contact.name": "Full name",
|
|
45
|
+
"contact.email": "Email address",
|
|
46
|
+
"contact.emailRequired": "Email is required",
|
|
47
|
+
"contact.subject": "Subject",
|
|
48
|
+
"contact.subjectGeneral": "General enquiry",
|
|
49
|
+
"contact.subjectSupport": "Support",
|
|
50
|
+
"contact.subjectFeedback": "Feedback",
|
|
51
|
+
"contact.message": "Message",
|
|
52
|
+
"contact.messageHint": "Maximum 500 characters",
|
|
53
|
+
"contact.send": "Send message",
|
|
54
|
+
"catalog.title": "Catalog — Boilerplate",
|
|
55
|
+
"catalog.heading": "Catalog",
|
|
56
|
+
"catalog.loading": "Loading catalog…",
|
|
57
|
+
"catalog.error": "The catalog failed to load. Reload the page to try again.",
|
|
58
|
+
"catalog.listLabel": "Product catalog",
|
|
59
|
+
"catalog.signedInAs": "Signed in as",
|
|
60
|
+
"catalog.showing": {
|
|
61
|
+
one: "— showing {shown} of {count} product.",
|
|
62
|
+
other: "— showing {shown} of {count} products.",
|
|
63
|
+
},
|
|
64
|
+
"catalog.more": "More products are available.",
|
|
65
|
+
"catalog.rating": "rated {rating} / 5",
|
|
66
|
+
"catalog.inStock": "in stock",
|
|
67
|
+
"catalog.outOfStock": "out of stock",
|
|
68
|
+
} satisfies Messages;
|
|
69
|
+
|
|
70
|
+
/** Every message key the app can translate. */
|
|
71
|
+
export type MessageKey = keyof typeof en;
|
|
72
|
+
|
|
73
|
+
export default en;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { MessageValue } from "@canonical/i18n-core";
|
|
2
|
+
import type { MessageKey } from "./en.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* French messages. Typed against the English key set, so the catalogs can
|
|
6
|
+
* never drift apart silently.
|
|
7
|
+
*/
|
|
8
|
+
const fr: Record<MessageKey, MessageValue> = {
|
|
9
|
+
"nav.label": "Principale",
|
|
10
|
+
"nav.home": "Accueil",
|
|
11
|
+
"nav.guide": "Guide",
|
|
12
|
+
"nav.catalog": "Catalogue",
|
|
13
|
+
"nav.contact": "Contact",
|
|
14
|
+
"nav.signIn": "Connexion démo",
|
|
15
|
+
"theme.label": "Thème de couleur",
|
|
16
|
+
"theme.system": "Système",
|
|
17
|
+
"theme.light": "Clair",
|
|
18
|
+
"theme.dark": "Sombre",
|
|
19
|
+
"locale.label": "Langue",
|
|
20
|
+
"notFound.heading": "Page introuvable",
|
|
21
|
+
"notFound.body": "La page que vous recherchez n'existe pas.",
|
|
22
|
+
"home.title": "Accueil — Boilerplate",
|
|
23
|
+
"home.heading": "Accueil",
|
|
24
|
+
"home.tagline": "Bienvenue dans le boilerplate du routeur pragma.",
|
|
25
|
+
"home.exampleHeading": "Composant d'exemple",
|
|
26
|
+
"home.streamingHeading": "Streaming avec Suspense",
|
|
27
|
+
"home.streamFallback": "Chargement du contenu diffusé…",
|
|
28
|
+
"guide.title": "{slug} — Guides",
|
|
29
|
+
"guide.body": "Contenu du guide pour {slug}.",
|
|
30
|
+
"account.title": "Compte — Boilerplate",
|
|
31
|
+
"account.heading": "Compte",
|
|
32
|
+
"account.body": "Page de compte protégée. Vous êtes connecté.",
|
|
33
|
+
"login.title": "Connexion — Boilerplate",
|
|
34
|
+
"login.heading": "Connexion",
|
|
35
|
+
"login.hintBefore": "Connexion de démonstration. Ajoutez",
|
|
36
|
+
"login.hintAfter":
|
|
37
|
+
"à n'importe quelle URL protégée pour simuler l'authentification.",
|
|
38
|
+
"login.redirect": "Vous serez redirigé vers {from} après la connexion.",
|
|
39
|
+
"contact.title": "Contact",
|
|
40
|
+
"contact.heading": "Contact",
|
|
41
|
+
"contact.name": "Nom complet",
|
|
42
|
+
"contact.email": "Adresse e-mail",
|
|
43
|
+
"contact.emailRequired": "L'adresse e-mail est requise",
|
|
44
|
+
"contact.subject": "Objet",
|
|
45
|
+
"contact.subjectGeneral": "Demande générale",
|
|
46
|
+
"contact.subjectSupport": "Assistance",
|
|
47
|
+
"contact.subjectFeedback": "Retour d'expérience",
|
|
48
|
+
"contact.message": "Message",
|
|
49
|
+
"contact.messageHint": "500 caractères maximum",
|
|
50
|
+
"contact.send": "Envoyer le message",
|
|
51
|
+
"catalog.title": "Catalogue — Boilerplate",
|
|
52
|
+
"catalog.heading": "Catalogue",
|
|
53
|
+
"catalog.loading": "Chargement du catalogue…",
|
|
54
|
+
"catalog.error":
|
|
55
|
+
"Le chargement du catalogue a échoué. Rechargez la page pour réessayer.",
|
|
56
|
+
"catalog.listLabel": "Catalogue de produits",
|
|
57
|
+
"catalog.signedInAs": "Connecté en tant que",
|
|
58
|
+
// "affichage de" keeps the wording invariant while the plural agrees with
|
|
59
|
+
// the total ({count}), which is what drives Intl.PluralRules selection.
|
|
60
|
+
"catalog.showing": {
|
|
61
|
+
one: "— affichage de {shown} sur {count} produit.",
|
|
62
|
+
other: "— affichage de {shown} sur {count} produits.",
|
|
63
|
+
},
|
|
64
|
+
"catalog.more": "D'autres produits sont disponibles.",
|
|
65
|
+
"catalog.rating": "noté {rating} / 5",
|
|
66
|
+
"catalog.inStock": "en stock",
|
|
67
|
+
"catalog.outOfStock": "en rupture de stock",
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default fr;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side negotiation and catalog integrity, exercised through the
|
|
3
|
+
* `@canonical/i18n-core` APIs with this app's real configuration — the same
|
|
4
|
+
* calls the dev servers, the compiled renderer, and the client entry make.
|
|
5
|
+
* (Ported from the former app-local `src/lib/i18n` seam.)
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
createTranslator,
|
|
9
|
+
directionOf,
|
|
10
|
+
documentAttrs,
|
|
11
|
+
negotiateLocale,
|
|
12
|
+
} from "@canonical/i18n-core";
|
|
13
|
+
import { describe, expect, it } from "vitest";
|
|
14
|
+
import { catalogs } from "./catalogs.js";
|
|
15
|
+
import { i18nConfig } from "./config.js";
|
|
16
|
+
|
|
17
|
+
describe("locale negotiation with the app config", () => {
|
|
18
|
+
it("prefers a supported locale cookie over Accept-Language", () => {
|
|
19
|
+
expect(
|
|
20
|
+
negotiateLocale(i18nConfig, {
|
|
21
|
+
cookieHeader: "theme=dark; locale=fr",
|
|
22
|
+
acceptLanguage: "ar,en;q=0.8",
|
|
23
|
+
}),
|
|
24
|
+
).toBe("fr");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("ignores an unsupported cookie and negotiates the header", () => {
|
|
28
|
+
expect(
|
|
29
|
+
negotiateLocale(i18nConfig, {
|
|
30
|
+
cookieHeader: "locale=pt",
|
|
31
|
+
acceptLanguage: "fr-CA,fr;q=0.9",
|
|
32
|
+
}),
|
|
33
|
+
).toBe("fr");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("matches the base language when only a region tag is offered", () => {
|
|
37
|
+
expect(negotiateLocale(i18nConfig, { acceptLanguage: "ar-EG" })).toBe("ar");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("falls back to the default when nothing matches", () => {
|
|
41
|
+
expect(
|
|
42
|
+
negotiateLocale(i18nConfig, { acceptLanguage: "pt-BR,ja;q=0.9" }),
|
|
43
|
+
).toBe("en");
|
|
44
|
+
expect(negotiateLocale(i18nConfig, {})).toBe("en");
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("document attributes for the app locales", () => {
|
|
49
|
+
it("maps ar to rtl and the rest to ltr", () => {
|
|
50
|
+
expect(documentAttrs(i18nConfig, "ar")).toEqual({
|
|
51
|
+
lang: "ar",
|
|
52
|
+
dir: "rtl",
|
|
53
|
+
});
|
|
54
|
+
expect(directionOf(i18nConfig, "en")).toBe("ltr");
|
|
55
|
+
expect(directionOf(i18nConfig, "fr")).toBe("ltr");
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("message catalogs", () => {
|
|
60
|
+
it("provide the same key set for every configured locale", () => {
|
|
61
|
+
const referenceKeys = Object.keys(catalogs.en).sort();
|
|
62
|
+
for (const locale of i18nConfig.locales) {
|
|
63
|
+
expect(Object.keys(catalogs[locale] ?? {}).sort()).toEqual(referenceKeys);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("pluralizes the catalog count line per locale", () => {
|
|
68
|
+
const english = createTranslator("en", catalogs.en ?? {});
|
|
69
|
+
expect(english("catalog.showing", { shown: 1, count: 1 })).toBe(
|
|
70
|
+
"— showing 1 of 1 product.",
|
|
71
|
+
);
|
|
72
|
+
expect(english("catalog.showing", { shown: 2, count: 5 })).toBe(
|
|
73
|
+
"— showing 2 of 5 products.",
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Arabic exercises the richer CLDR categories: 2 → "two", 5 → "few".
|
|
77
|
+
const arabic = createTranslator("ar", catalogs.ar ?? {});
|
|
78
|
+
expect(arabic("catalog.showing", { shown: 2, count: 2 })).toContain(
|
|
79
|
+
"منتجين",
|
|
80
|
+
);
|
|
81
|
+
expect(arabic("catalog.showing", { shown: 4, count: 5 })).toContain(
|
|
82
|
+
"منتجات",
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("interpolates placeholders", () => {
|
|
87
|
+
const french = createTranslator("fr", catalogs.fr ?? {});
|
|
88
|
+
expect(french("guide.body", { slug: "router-core" })).toBe(
|
|
89
|
+
"Contenu du guide pour router-core.",
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { I18nProvider } from "@canonical/i18n-react";
|
|
2
|
+
import { fireEvent, render, screen, within } from "@testing-library/react";
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { catalogs, i18nConfig } from "#i18n/index.js";
|
|
5
|
+
import LocaleSelector from "./LocaleSelector.js";
|
|
6
|
+
|
|
7
|
+
function renderSelector() {
|
|
8
|
+
return render(
|
|
9
|
+
<I18nProvider config={i18nConfig} catalogs={catalogs}>
|
|
10
|
+
<LocaleSelector />
|
|
11
|
+
</I18nProvider>,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
// biome-ignore lint/suspicious/noDocumentCookie: test cleanup
|
|
17
|
+
document.cookie = "locale=; max-age=0; path=/";
|
|
18
|
+
document.documentElement.removeAttribute("lang");
|
|
19
|
+
document.documentElement.removeAttribute("dir");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("LocaleSelector component", () => {
|
|
23
|
+
it("lists every configured locale by its endonym, tagged with lang", () => {
|
|
24
|
+
renderSelector();
|
|
25
|
+
|
|
26
|
+
const select = screen.getByRole("combobox", { name: "Language" });
|
|
27
|
+
const options = within(select).getAllByRole(
|
|
28
|
+
"option",
|
|
29
|
+
) as HTMLOptionElement[];
|
|
30
|
+
|
|
31
|
+
expect(options.map((option) => option.value)).toEqual([
|
|
32
|
+
...i18nConfig.locales,
|
|
33
|
+
]);
|
|
34
|
+
// Endonyms come from Intl.DisplayNames — each language names itself.
|
|
35
|
+
expect(options.map((option) => option.textContent)).toEqual([
|
|
36
|
+
"English",
|
|
37
|
+
"français",
|
|
38
|
+
"العربية",
|
|
39
|
+
]);
|
|
40
|
+
// <option lang> lets assistive technology pronounce each endonym
|
|
41
|
+
// in its own language.
|
|
42
|
+
expect(options.map((option) => option.getAttribute("lang"))).toEqual([
|
|
43
|
+
...i18nConfig.locales,
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("persists the choice and reflects <html lang dir> on change", () => {
|
|
48
|
+
renderSelector();
|
|
49
|
+
|
|
50
|
+
fireEvent.change(screen.getByRole("combobox", { name: "Language" }), {
|
|
51
|
+
target: { value: "ar" },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(document.cookie).toContain("locale=ar");
|
|
55
|
+
expect(document.documentElement.lang).toBe("ar");
|
|
56
|
+
expect(document.documentElement.dir).toBe("rtl");
|
|
57
|
+
// Its own accessible name re-translates too.
|
|
58
|
+
expect(screen.getByRole("combobox", { name: "اللغة" })).toBeInTheDocument();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useLocale, useTranslation } from "@canonical/i18n-react";
|
|
2
|
+
import type { ChangeEvent, ReactElement } from "react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a locale tag to its endonym — the language's name in itself
|
|
6
|
+
* ("English", "français", "العربية") — so every reader can find their own
|
|
7
|
+
* language regardless of the page's current locale.
|
|
8
|
+
*/
|
|
9
|
+
function endonymOf(tag: string): string {
|
|
10
|
+
return new Intl.DisplayNames([tag], { type: "language" }).of(tag) ?? tag;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Language picker driving `useLocale` from `@canonical/i18n-react`. Changing
|
|
15
|
+
* the selection re-translates every subscribed component, persists the choice
|
|
16
|
+
* to the `locale` cookie (so the server renders the matching `<html lang>` on
|
|
17
|
+
* the next request), and flips `<html dir>` for right-to-left locales.
|
|
18
|
+
*
|
|
19
|
+
* Each `<option>` carries a `lang` attribute so assistive technology
|
|
20
|
+
* pronounces the endonym in its own language. Deliberately app-local: the
|
|
21
|
+
* design-system tier ships no visual locale switcher.
|
|
22
|
+
*/
|
|
23
|
+
export default function LocaleSelector(): ReactElement {
|
|
24
|
+
const { locale, locales, setLocale } = useLocale();
|
|
25
|
+
const { t } = useTranslation();
|
|
26
|
+
|
|
27
|
+
function handleChange(event: ChangeEvent<HTMLSelectElement>) {
|
|
28
|
+
setLocale(event.target.value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<select
|
|
33
|
+
aria-label={t("locale.label")}
|
|
34
|
+
onChange={handleChange}
|
|
35
|
+
value={locale}
|
|
36
|
+
>
|
|
37
|
+
{locales.map((tag) => (
|
|
38
|
+
<option key={tag} value={tag} lang={tag}>
|
|
39
|
+
{endonymOf(tag)}
|
|
40
|
+
</option>
|
|
41
|
+
))}
|
|
42
|
+
</select>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./LocaleSelector.js";
|
|
@@ -1,24 +1,58 @@
|
|
|
1
|
+
<% if (intl) { -%>
|
|
2
|
+
import { useTranslation } from "@canonical/i18n-react";
|
|
3
|
+
<% } -%>
|
|
1
4
|
import { Link } from "@canonical/router-react";
|
|
2
5
|
import type { ReactElement } from "react";
|
|
6
|
+
<% if (intl) { -%>
|
|
7
|
+
import LocaleSelector from "../LocaleSelector/index.js";
|
|
8
|
+
<% } -%>
|
|
3
9
|
import ThemeSelector from "../ThemeSelector/index.js";
|
|
4
10
|
|
|
5
11
|
export default function Navigation(): ReactElement {
|
|
12
|
+
<% if (intl) { -%>
|
|
13
|
+
const { t } = useTranslation();
|
|
14
|
+
|
|
15
|
+
<% } -%>
|
|
6
16
|
return (
|
|
17
|
+
<% if (intl) { -%>
|
|
18
|
+
<nav aria-label={t("nav.label")}>
|
|
19
|
+
<Link to="home">{t("nav.home")}</Link>
|
|
20
|
+
<% } else { -%>
|
|
7
21
|
<nav aria-label="Main">
|
|
8
22
|
<Link to="home">Home</Link>
|
|
23
|
+
<% } -%>
|
|
9
24
|
<Link params={{ slug: "router-core" }} to="guide">
|
|
25
|
+
<% if (intl) { -%>
|
|
26
|
+
{t("nav.guide")}
|
|
27
|
+
<% } else { -%>
|
|
10
28
|
Guide
|
|
29
|
+
<% } -%>
|
|
11
30
|
</Link>
|
|
12
31
|
<% if (relay) { -%>
|
|
32
|
+
<% if (intl) { -%>
|
|
33
|
+
<Link to="catalog">{t("nav.catalog")}</Link>
|
|
34
|
+
<% } else { -%>
|
|
13
35
|
<Link to="catalog">Catalog</Link>
|
|
14
36
|
<% } -%>
|
|
37
|
+
<% } -%>
|
|
15
38
|
<% if (forms) { -%>
|
|
39
|
+
<% if (intl) { -%>
|
|
40
|
+
<Link to="contact">{t("nav.contact")}</Link>
|
|
41
|
+
<% } else { -%>
|
|
16
42
|
<Link to="contact">Contact</Link>
|
|
43
|
+
<% } -%>
|
|
17
44
|
<% } -%>
|
|
18
45
|
<Link search={{ auth: "1" }} to="account">
|
|
46
|
+
<% if (intl) { -%>
|
|
47
|
+
{t("nav.signIn")}
|
|
48
|
+
<% } else { -%>
|
|
19
49
|
Demo sign-in
|
|
50
|
+
<% } -%>
|
|
20
51
|
</Link>
|
|
21
52
|
<ThemeSelector />
|
|
53
|
+
<% if (intl) { -%>
|
|
54
|
+
<LocaleSelector />
|
|
55
|
+
<% } -%>
|
|
22
56
|
</nav>
|
|
23
57
|
);
|
|
24
58
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
<% if (intl) { -%>
|
|
2
|
+
import { useTranslation } from "@canonical/i18n-react";
|
|
3
|
+
<% } -%>
|
|
1
4
|
import { usePreferredTheme } from "@canonical/react-hooks";
|
|
2
5
|
import type { ChangeEvent, ReactElement } from "react";
|
|
3
6
|
|
|
4
7
|
export default function ThemeSelector(): ReactElement {
|
|
5
8
|
const { value, source, set, reset } = usePreferredTheme();
|
|
9
|
+
<% if (intl) { -%>
|
|
10
|
+
const { t } = useTranslation();
|
|
11
|
+
<% } -%>
|
|
6
12
|
|
|
7
13
|
function handleChange(event: ChangeEvent<HTMLSelectElement>) {
|
|
8
14
|
const selected = event.target.value;
|
|
@@ -18,13 +24,23 @@ export default function ThemeSelector(): ReactElement {
|
|
|
18
24
|
|
|
19
25
|
return (
|
|
20
26
|
<select
|
|
27
|
+
<% if (intl) { -%>
|
|
28
|
+
aria-label={t("theme.label")}
|
|
29
|
+
<% } else { -%>
|
|
21
30
|
aria-label="Color theme"
|
|
31
|
+
<% } -%>
|
|
22
32
|
onChange={handleChange}
|
|
23
33
|
value={selectValue}
|
|
24
34
|
>
|
|
35
|
+
<% if (intl) { -%>
|
|
36
|
+
<option value="system">{t("theme.system")}</option>
|
|
37
|
+
<option value="light">{t("theme.light")}</option>
|
|
38
|
+
<option value="dark">{t("theme.dark")}</option>
|
|
39
|
+
<% } else { -%>
|
|
25
40
|
<option value="system">System</option>
|
|
26
41
|
<option value="light">Light</option>
|
|
27
42
|
<option value="dark">Dark</option>
|
|
43
|
+
<% } -%>
|
|
28
44
|
</select>
|
|
29
45
|
);
|
|
30
46
|
}
|
|
@@ -3,5 +3,8 @@ export { default as ClientOnly } from "./ClientOnly/index.js";
|
|
|
3
3
|
<% } -%>
|
|
4
4
|
export { ExampleComponent } from "./ExampleComponent/index.js";
|
|
5
5
|
export { default as LazyComponent } from "./LazyComponent/index.js";
|
|
6
|
+
<% if (intl) { -%>
|
|
7
|
+
export { default as LocaleSelector } from "./LocaleSelector/index.js";
|
|
8
|
+
<% } -%>
|
|
6
9
|
export { default as Navigation } from "./Navigation/index.js";
|
|
7
10
|
export { default as ThemeSelector } from "./ThemeSelector/index.js";
|