diff --git a/packages/i18n/package.json b/packages/i18n/package.json new file mode 100644 index 0000000..a953284 --- /dev/null +++ b/packages/i18n/package.json @@ -0,0 +1,29 @@ +{ + "name": "@serverlessworkflow/i18n", + "version": "1.0.0", + "files": [ + "dist" + ], + "type": "module", + "main": "dist/index.js", + "exports": { + ".": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } + }, + "scripts": { + "clean": "rimraf ./dist", + "build": "pnpm clean && tsc -p tsconfig.json", + "build:prod": "pnpm run build" + }, + "dependencies": { + "@serverlessworkflow/i18n": "workspace:*", + "i18next": "catalog:", + "react-i18next": "catalog:" + }, + "devDependencies": { + "@types/node": "catalog:", + "rimraf": "catalog:" + } +} diff --git a/packages/i18n/src/config.ts b/packages/i18n/src/config.ts new file mode 100644 index 0000000..82baefb --- /dev/null +++ b/packages/i18n/src/config.ts @@ -0,0 +1,41 @@ +/* + * Copyright 2021-Present The Serverless Workflow Specification Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { i18n } from "i18next"; +import { initReactI18next } from "react-i18next"; +import { resources, defaultNS } from "./resources"; + +export async function setupI18n(instance: i18n) { + if (instance.isInitialized) { + return instance; + } + + await instance.use(initReactI18next).init({ + resources, + defaultNS, + fallbackLng: "en", + + interpolation: { + escapeValue: false, + }, + + react: { + useSuspense: false, + }, + }); + + return instance; +} diff --git a/packages/i18n/src/index.ts b/packages/i18n/src/index.ts new file mode 100644 index 0000000..88ff33e --- /dev/null +++ b/packages/i18n/src/index.ts @@ -0,0 +1,20 @@ +/* + * Copyright 2021-Present The Serverless Workflow Specification Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type {} from "./types"; + +export * from "./config"; +export * from "./resources"; diff --git a/packages/i18n/src/locales/en/common.json b/packages/i18n/src/locales/en/common.json new file mode 100644 index 0000000..7f9d457 --- /dev/null +++ b/packages/i18n/src/locales/en/common.json @@ -0,0 +1,6 @@ +{ + "hello": "Hello", + "welcome": "Welcome to the editor", + "setup": "Setup", + "start": "Start" +} diff --git a/packages/i18n/src/resources.ts b/packages/i18n/src/resources.ts new file mode 100644 index 0000000..0cdf52a --- /dev/null +++ b/packages/i18n/src/resources.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2021-Present The Serverless Workflow Specification Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import enCommon from "./locales/en/common.json"; + +export const resources = { + en: { + common: enCommon, + }, +} as const; + +export const defaultNS = "common"; diff --git a/packages/i18n/src/types.d.ts b/packages/i18n/src/types.d.ts new file mode 100644 index 0000000..7ef1530 --- /dev/null +++ b/packages/i18n/src/types.d.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2021-Present The Serverless Workflow Specification Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import "react-i18next"; +import { resources, defaultNS } from "./resources"; + +declare module "react-i18next" { + interface CustomTypeOptions { + defaultNS: typeof defaultNS; + resources: (typeof resources)["en"]; + } +} diff --git a/packages/i18n/tsconfig.json b/packages/i18n/tsconfig.json new file mode 100644 index 0000000..4444bef --- /dev/null +++ b/packages/i18n/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "declaration": true, + "emitDeclarationOnly": false + }, + "include": ["src"] +} diff --git a/packages/serverless-workflow-diagram-editor/package.json b/packages/serverless-workflow-diagram-editor/package.json index de855e0..fbe5a2f 100644 --- a/packages/serverless-workflow-diagram-editor/package.json +++ b/packages/serverless-workflow-diagram-editor/package.json @@ -37,6 +37,11 @@ "start": "storybook dev -p 6006 --no-open", "build:storybook": "pnpm clean:storybook && storybook build --output-dir ./dist-storybook" }, + "dependencies": { + "@serverlessworkflow/i18n": "workspace:*", + "i18next": "catalog:", + "react-i18next": "catalog:" + }, "devDependencies": { "@chromatic-com/storybook": "catalog:", "@storybook/addon-a11y": "catalog:", diff --git a/packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx b/packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx index a896f45..f497154 100644 --- a/packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx +++ b/packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx @@ -15,6 +15,8 @@ */ import type { CSSProperties } from "react"; +import "../i18n"; +import { useTranslation } from "react-i18next"; const clickmeBtnStyle: CSSProperties = { border: "2px solid blue", @@ -32,6 +34,7 @@ export type DiagramEditorProps = { export const DiagramEditor = (props: DiagramEditorProps) => { //TODO: Implement the actual component this is just a placeholder + const { t } = useTranslation(); return ( <> @@ -41,6 +44,9 @@ export const DiagramEditor = (props: DiagramEditorProps) => { +
+ {t("welcome")} {t("start")} {t("setup")}{" "} +
); }; diff --git a/packages/serverless-workflow-diagram-editor/src/i18n.ts b/packages/serverless-workflow-diagram-editor/src/i18n.ts new file mode 100644 index 0000000..18bc5e5 --- /dev/null +++ b/packages/serverless-workflow-diagram-editor/src/i18n.ts @@ -0,0 +1,21 @@ +/* + * Copyright 2021-Present The Serverless Workflow Specification Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import i18n from "i18next"; +import { setupI18n } from "@serverlessworkflow/i18n"; + +const i18nReady = setupI18n(i18n); +export { i18nReady }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5eefd81..29da452 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,6 +51,9 @@ catalogs: husky: specifier: ^9.1.7 version: 9.1.7 + i18next: + specifier: ^25.10.4 + version: 25.10.9 jsdom: specifier: ^25.0.0 version: 25.0.1 @@ -69,6 +72,9 @@ catalogs: react-dom: specifier: ^19.2.4 version: 19.2.4 + react-i18next: + specifier: ^16.6.1 + version: 16.6.6 rimraf: specifier: ^6.1.3 version: 6.1.3 @@ -111,7 +117,36 @@ importers: specifier: 'catalog:' version: 5.9.3 + packages/i18n: + dependencies: + '@serverlessworkflow/i18n': + specifier: workspace:* + version: 'link:' + i18next: + specifier: 'catalog:' + version: 25.10.9(typescript@5.9.3) + react-i18next: + specifier: 'catalog:' + version: 16.6.6(i18next@25.10.9(typescript@5.9.3))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(typescript@5.9.3) + devDependencies: + '@types/node': + specifier: 'catalog:' + version: 25.5.0 + rimraf: + specifier: 'catalog:' + version: 6.1.3 + packages/serverless-workflow-diagram-editor: + dependencies: + '@serverlessworkflow/i18n': + specifier: workspace:* + version: link:../i18n + i18next: + specifier: 'catalog:' + version: 25.10.9(typescript@5.9.3) + react-i18next: + specifier: 'catalog:' + version: 16.6.6(i18next@25.10.9(typescript@5.9.3))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(typescript@5.9.3) devDependencies: '@chromatic-com/storybook': specifier: 'catalog:' @@ -1611,6 +1646,9 @@ packages: html-escaper@2.0.2: resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} + html-parse-stringify@3.0.1: + resolution: {integrity: sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg==} + http-proxy-agent@7.0.2: resolution: {integrity: sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==} engines: {node: '>= 14'} @@ -1624,6 +1662,14 @@ packages: engines: {node: '>=18'} hasBin: true + i18next@25.10.9: + resolution: {integrity: sha512-hQY9/bFoQKGlSKMlaCuLR8w1h5JjieqrsnZvEmj1Ja6Ec7fbyc4cTrCsY9mb9Sd8YQ/swsrKz1S9M8AcvVI70w==} + 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'} @@ -1865,6 +1911,22 @@ packages: peerDependencies: react: ^19.2.4 + react-i18next@16.6.6: + resolution: {integrity: sha512-ZgL2HUoW34UKUkOV7uSQFE1CDnRPD+tCR3ywSuWH7u2iapnz86U8Bi3Vrs620qNDzCf1F47NxglCEkchCTDOHw==} + peerDependencies: + i18next: '>= 25.10.9' + 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==} @@ -2234,6 +2296,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'} @@ -3438,6 +3504,10 @@ snapshots: html-escaper@2.0.2: {} + html-parse-stringify@3.0.1: + dependencies: + void-elements: 3.1.0 + http-proxy-agent@7.0.2: dependencies: agent-base: 7.1.4 @@ -3454,6 +3524,12 @@ snapshots: husky@9.1.7: {} + i18next@25.10.9(typescript@5.9.3): + dependencies: + '@babel/runtime': 7.29.2 + optionalDependencies: + typescript: 5.9.3 + iconv-lite@0.6.3: dependencies: safer-buffer: 2.1.2 @@ -3735,6 +3811,17 @@ snapshots: react: 19.2.4 scheduler: 0.27.0 + react-i18next@16.6.6(i18next@25.10.9(typescript@5.9.3))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(typescript@5.9.3): + dependencies: + '@babel/runtime': 7.29.2 + html-parse-stringify: 3.0.1 + i18next: 25.10.9(typescript@5.9.3) + react: 19.2.4 + use-sync-external-store: 1.6.0(react@19.2.4) + optionalDependencies: + react-dom: 19.2.4(react@19.2.4) + typescript: 5.9.3 + react-is@17.0.2: {} react@19.2.4: {} @@ -4060,6 +4147,8 @@ snapshots: transitivePeerDependencies: - msw + void-elements@3.1.0: {} + w3c-xmlserializer@5.0.0: dependencies: xml-name-validator: 5.0.0 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 7994462..0a0d1ca 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -29,6 +29,8 @@ catalog: vite: ^6.0.0 vite-tsconfig-paths: ^6.1.1 vitest: ^4.1.0 + i18next: ^25.10.4 + react-i18next: ^16.6.1 cleanupUnusedCatalogs: true onlyBuiltDependencies: - "@swc/core"