diff --git a/web/package.json b/web/package.json index 7c025e9..41b9f52 100644 --- a/web/package.json +++ b/web/package.json @@ -18,10 +18,12 @@ "@fontsource-variable/geist": "^5.2.9", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", + "i18next": "^26.3.0", "lucide-react": "^1.17.0", "openapi-fetch": "^0.17.0", "react": "^19.1.0", "react-dom": "^19.1.0", + "react-i18next": "^17.0.8", "tailwind-merge": "^3.6.0", "tw-animate-css": "^1.4.0" }, diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml index 1b0ad01..13ac4da 100644 --- a/web/pnpm-lock.yaml +++ b/web/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: clsx: specifier: ^2.1.1 version: 2.1.1 + i18next: + specifier: ^26.3.0 + version: 26.3.0(typescript@5.8.3) lucide-react: specifier: ^1.17.0 version: 1.17.0(react@19.2.7) @@ -32,6 +35,9 @@ importers: react-dom: specifier: ^19.1.0 version: 19.2.7(react@19.2.7) + react-i18next: + specifier: ^17.0.8 + version: 17.0.8(i18next@26.3.0(typescript@5.8.3))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(typescript@5.8.3) tailwind-merge: specifier: ^3.6.0 version: 3.6.0 @@ -1760,6 +1766,9 @@ packages: resolution: {integrity: sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==} engines: {node: '>=18'} + html-parse-stringify@3.0.1: + resolution: {integrity: sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg==} + http-errors@2.0.1: resolution: {integrity: sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==} engines: {node: '>= 0.8'} @@ -1780,6 +1789,14 @@ packages: resolution: {integrity: sha512-eKCa6bwnJhvxj14kZk5NCPc6Hb6BdsU9DZcOnmQKSnO1VKrfV0zCvtttPZUsBvjmNDn8rpcJfpwSYnHBjc95MQ==} engines: {node: '>=18.18.0'} + i18next@26.3.0: + resolution: {integrity: sha512-gHSgGpUXVmuqE2El1W61DmxeyeTlFfZgdJRWMo9jScAn5pu7TuTuiccb1zh3E2J9hEBVGJ23+96x0ieBhfuIHA==} + peerDependencies: + typescript: ^5 || ^6 + peerDependenciesMeta: + typescript: + optional: true + iconv-lite@0.6.3: resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} engines: {node: '>=0.10.0'} @@ -2389,6 +2406,22 @@ packages: peerDependencies: react: ^19.2.7 + react-i18next@17.0.8: + resolution: {integrity: sha512-0ooKbGLU8JXhe1zwpQUWIeXSgLPOfwJmgheWRIUpcoA0CpyabpGhayjdG+/eA5esC1AQ8h2jWpXjJfzQzeDOCw==} + peerDependencies: + i18next: '>= 26.2.0' + react: '>= 16.8.0' + react-dom: '*' + react-native: '*' + typescript: ^5 || ^6 + peerDependenciesMeta: + react-dom: + optional: true + react-native: + optional: true + typescript: + optional: true + react-is@17.0.2: resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==} @@ -2837,6 +2870,10 @@ packages: jsdom: optional: true + void-elements@3.1.0: + resolution: {integrity: sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==} + engines: {node: '>=0.10.0'} + w3c-xmlserializer@5.0.0: resolution: {integrity: sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==} engines: {node: '>=18'} @@ -4572,6 +4609,10 @@ snapshots: dependencies: whatwg-encoding: 3.1.1 + html-parse-stringify@3.0.1: + dependencies: + void-elements: 3.1.0 + http-errors@2.0.1: dependencies: depd: 2.0.0 @@ -4598,6 +4639,10 @@ snapshots: human-signals@8.0.1: {} + i18next@26.3.0(typescript@5.8.3): + optionalDependencies: + typescript: 5.8.3 + iconv-lite@0.6.3: dependencies: safer-buffer: 2.1.2 @@ -5114,6 +5159,17 @@ snapshots: react: 19.2.7 scheduler: 0.27.0 + react-i18next@17.0.8(i18next@26.3.0(typescript@5.8.3))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(typescript@5.8.3): + dependencies: + '@babel/runtime': 7.29.7 + html-parse-stringify: 3.0.1 + i18next: 26.3.0(typescript@5.8.3) + react: 19.2.7 + use-sync-external-store: 1.6.0(react@19.2.7) + optionalDependencies: + react-dom: 19.2.7(react@19.2.7) + typescript: 5.8.3 + react-is@17.0.2: {} react-refresh@0.17.0: {} @@ -5595,6 +5651,8 @@ snapshots: - tsx - yaml + void-elements@3.1.0: {} + w3c-xmlserializer@5.0.0: dependencies: xml-name-validator: 5.0.0 diff --git a/web/src/i18n/en.json b/web/src/i18n/en.json new file mode 100644 index 0000000..7b36382 --- /dev/null +++ b/web/src/i18n/en.json @@ -0,0 +1,8 @@ +{ + "app": { "name": "Collection" }, + "nav": { "objects": "Objects", "vocabularies": "Vocabularies", "authorities": "Authorities", "fields": "Fields", "search": "Search", "soon": "Coming soon" }, + "auth": { "email": "Email", "password": "Password", "signIn": "Sign in", "signOut": "Sign out", "invalid": "Invalid email or password", "networkError": "Could not reach the server" }, + "objects": { "title": "Objects", "empty": "No objects yet", "loadError": "Could not load objects", "selectPrompt": "Select an object to view its details", "notFound": "Object not found", "prev": "Previous", "next": "Next", "of": "of" }, + "fieldsLabels": { "objectNumber": "Object number", "objectName": "Name", "count": "Number of objects", "briefDescription": "Brief description", "currentLocation": "Current location", "currentOwner": "Current owner", "recorder": "Recorder", "recordingDate": "Recording date", "visibility": "Visibility", "flexible": "Catalogue fields" }, + "visibility": { "draft": "Draft", "internal": "Internal", "public": "Public" } +} diff --git a/web/src/i18n/i18n.test.tsx b/web/src/i18n/i18n.test.tsx new file mode 100644 index 0000000..f58bffd --- /dev/null +++ b/web/src/i18n/i18n.test.tsx @@ -0,0 +1,29 @@ +import { expect, test, beforeEach } from "vitest"; +import { render, screen, act } from "@testing-library/react"; +import { useTranslation } from "react-i18next"; +import i18n from "./index"; +import { useLocale } from "./use-locale"; + +beforeEach(async () => { + await i18n.changeLanguage("en"); +}); + +function Probe() { + const { t } = useTranslation(); + const { setLocale } = useLocale(); + return ( +