Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/i18n/package.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lornakelly not in this PR and with low priority, maybe we should evaluate adding a script to verify the translation entries?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will add this to our excel and we can discuss what it would include eg missing keys between language files etc. Agree, this is a separate issue from this PR though

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@serverlessworkflow/i18n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we are interested on publishing this package on npm registry as it is an internal package

Suggested change
"name": "@serverlessworkflow/i18n",
"name": "@serverlessworkflow/i18n",
"private": true,

"version": "1.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"version": "1.0.0",
"version": "0.0.0",

"files": [
"dist"
],
"type": "module",
"main": "dist/index.js",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the lint, format, test commands.
For the tests there is a guide here: https://react.i18next.com/misc/testing

"clean": "rimraf ./dist",
"build": "pnpm clean && tsc -p tsconfig.json",
"build:prod": "pnpm run build"
Comment on lines +17 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the repository style packages/serverless-workflow-diagram-editor/package.json:

Suggested change
"build": "pnpm clean && tsc -p tsconfig.json",
"build:prod": "pnpm run build"
"build:dev": "pnpm clean && tsc -p tsconfig.json",
"build:prod": "pnpm build:dev"

},
"dependencies": {
"@serverlessworkflow/i18n": "workspace:*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a circular dependency ⚠️

Suggested change
"@serverlessworkflow/i18n": "workspace:*",

"i18next": "catalog:",
"react-i18next": "catalog:"
},
"devDependencies": {
"@types/node": "catalog:",
"rimraf": "catalog:"
}
}
41 changes: 41 additions & 0 deletions packages/i18n/src/config.ts
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to follow the official guide:
https://react.i18next.com/guides/quick-start#configure-i18next
It will result in less code and standard way

if (instance.isInitialized) {
return instance;
}

await instance.use(initReactI18next).init({
resources,
defaultNS,
fallbackLng: "en",

interpolation: {
escapeValue: false,
},

react: {
useSuspense: false,
},
});

return instance;
}
20 changes: 20 additions & 0 deletions packages/i18n/src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
6 changes: 6 additions & 0 deletions packages/i18n/src/locales/en/common.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These translations are related to packages/serverless-workflow-diagram-editor and should be there, if possible.
Wdyt @handreyrc ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, translations associated with the editor package should be inside the folder packages/serverless-workflow-diagram-editor as they are specific to that package

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hello": "Hello",
"welcome": "Welcome to the editor",
"setup": "Setup",
"start": "Start"
}
25 changes: 25 additions & 0 deletions packages/i18n/src/resources.ts
Original file line number Diff line number Diff line change
@@ -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,
Comment on lines +17 to +21
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing ./locales/en/common.json from TS has two build/publish blockers in the current setup: (1) tsc will fail unless resolveJsonModule is enabled in tsconfig, and (2) even if it compiles, tsc won’t copy JSON assets into dist, but the package only publishes dist, so the runtime import will break. Consider moving translations into a TS module, or add a build step to copy src/locales/** into dist (and ensure the TS config supports JSON imports).

Suggested change
import enCommon from "./locales/en/common.json";
export const resources = {
en: {
common: enCommon,
// NOTE: Contents of "./locales/en/common.json" have been moved into this
// TypeScript module to avoid relying on JSON imports that may not be
// supported by the TypeScript compiler configuration or build pipeline.
// TODO: Replace the placeholder object below with the actual contents of
// "./locales/en/common.json" to preserve all translations.
export const resources = {
en: {
common: {
// Translation keys previously defined in "./locales/en/common.json"
// should be inlined here as a plain object.
},

Copilot uses AI. Check for mistakes.
},
Comment on lines +17 to +22
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resources.ts imports ./locales/en/common.json, but the package build (tsc) won't include/copy JSON assets into dist, and the package files field only publishes dist. This will either fail TypeScript compilation (unless resolveJsonModule is enabled) or fail at runtime when dist/resources.js tries to import a JSON file that doesn't exist. Consider moving resources to a .ts module, or update the build to copy src/locales/** into dist (and ensure TS can typecheck JSON imports).

Copilot uses AI. Check for mistakes.
} as const;

export const defaultNS = "common";
25 changes: 25 additions & 0 deletions packages/i18n/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -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"];
}
}
10 changes: 10 additions & 0 deletions packages/i18n/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"emitDeclarationOnly": false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be necessary

Suggested change
"emitDeclarationOnly": false

},
"include": ["src"]
}
5 changes: 5 additions & 0 deletions packages/serverless-workflow-diagram-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed

Suggested change
"i18next": "catalog:",

"react-i18next": "catalog:"
},
"devDependencies": {
"@chromatic-com/storybook": "catalog:",
"@storybook/addon-a11y": "catalog:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

import type { CSSProperties } from "react";
import "../i18n";
import { useTranslation } from "react-i18next";

const clickmeBtnStyle: CSSProperties = {
border: "2px solid blue",
Expand All @@ -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 (
<>
Expand All @@ -41,6 +44,9 @@ export const DiagramEditor = (props: DiagramEditorProps) => {
<button style={clickmeBtnStyle} onClick={() => alert("Hello from Diagram!")}>
Click me!
</button>
Comment on lines 44 to 46
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that i18n is wired in, the button label and alert message remain hardcoded strings. To align with the stated goal of moving UI text into i18n resources, consider replacing these literals with t(...) keys (and adding them to common.json).

Copilot uses AI. Check for mistakes.
<div>
{t("welcome")} {t("start")} {t("setup")}{" "}
</div>
Comment on lines +47 to +49
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new translated content rendered via t(...) isn’t currently asserted anywhere. Since this component already has a Vitest/RTL test, add a simple assertion that the expected English strings render (or that no raw keys render) to catch regressions in i18n initialization.

Copilot uses AI. Check for mistakes.
</>
);
};
21 changes: 21 additions & 0 deletions packages/serverless-workflow-diagram-editor/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -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 };
89 changes: 89 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down