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
35 changes: 35 additions & 0 deletions packages/i18n/package.json
Copy link
Copy Markdown
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?

Copy link
Copy Markdown
Contributor

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,35 @@
{
"name": "@serverlessworkflow/i18n",
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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": {
"i18next": "catalog:",
"react-i18next": "catalog:"
},
"devDependencies": {
"@types/node": "catalog:",
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
"@types/react-i18next": "^8.1.0",
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

react-i18next ships its own TypeScript types; adding @types/react-i18next (especially an older major like ^8.1.0) can introduce conflicting/incorrect typings with the installed react-i18next version. Remove @types/react-i18next unless there’s a specific, verified need for it.

Suggested change
"@types/react-i18next": "^8.1.0",

Copilot uses AI. Check for mistakes.
"rimraf": "catalog:"
},
"peerDependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0"
}
}
51 changes: 51 additions & 0 deletions packages/i18n/src/TranslationProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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, { createContext, useContext, useEffect, useState } from "react";
import { I18nextProvider } from "react-i18next";
import i18n from "./i18n";

type LanguageContextType = {
language: string;
changeLanguage: (lng: string) => void;
};

const LanguageContext = createContext<LanguageContextType>({
language: "en",
changeLanguage: () => {},
});

export const useLanguage = () => useContext(LanguageContext);

export function TranslationProvider({ children }: { children: React.ReactNode }) {
const [language, setLanguage] = useState(i18n.language);

useEffect(() => {
const handler = (lng: string) => setLanguage(lng);
i18n.on("languageChanged", handler);
return () => i18n.off("languageChanged", handler);
}, []);

const changeLanguage = (lng: string) => {
i18n.changeLanguage(lng);
};

return (
<LanguageContext.Provider value={{ language, changeLanguage }}>
<I18nextProvider i18n={i18n}>{children}</I18nextProvider>
</LanguageContext.Provider>
);
}
40 changes: 40 additions & 0 deletions packages/i18n/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 { initReactI18next } from "react-i18next";

import en from "./locales/en/common.json";

if (!i18n.isInitialized) {
i18n.use(initReactI18next).init({
resources: {
en: { common: en },
},
lng: "en",
fallbackLng: "en",
ns: ["common"],
defaultNS: "common",
interpolation: {
escapeValue: false,
},
react: {
useSuspense: false,
},
});
}

export default i18n;
18 changes: 18 additions & 0 deletions packages/i18n/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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.
*/

export { TranslationProvider, useLanguage } from "./TranslationProvider";
export { default as i18n } from "./i18n";
6 changes: 6 additions & 0 deletions packages/i18n/src/locales/en/common.json
Copy link
Copy Markdown
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 ?

Copy link
Copy Markdown
Contributor

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"
}
11 changes: 11 additions & 0 deletions packages/i18n/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"types": ["node"],
"compilerOptions": {
Comment on lines +3 to +4
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

types is not a valid top-level tsconfig field; it must be inside compilerOptions. As written, this config can fail validation or be ignored, leading to inconsistent builds. Move types under compilerOptions.

Suggested change
"types": ["node"],
"compilerOptions": {
"compilerOptions": {
"types": ["node"],

Copilot uses AI. Check for mistakes.
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"emitDeclarationOnly": false
Copy link
Copy Markdown
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
Copy Markdown
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 @@ -14,7 +14,9 @@
* limitations under the License.
*/

import type { CSSProperties } from "react";
import { CSSProperties } from "react";
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

CSSProperties is a TypeScript type, not a runtime export from react. Importing it as a value can fail with certain TS/ESM settings (e.g., verbatimModuleSyntax) and may emit an invalid runtime import. Switch back to a type-only import (import type { CSSProperties } from \"react\";).

Suggested change
import { CSSProperties } from "react";
import type { CSSProperties } from "react";

Copilot uses AI. Check for mistakes.
import { useTranslation } from "react-i18next";
import { TranslationProvider } from "@serverlessworkflow/i18n";

const clickmeBtnStyle: CSSProperties = {
border: "2px solid blue",
Expand All @@ -31,16 +33,20 @@ export type DiagramEditorProps = {
};

export const DiagramEditor = (props: DiagramEditorProps) => {
//TODO: Implement the actual component this is just a placeholder

const { t } = useTranslation();
return (
<>
<TranslationProvider>
Comment on lines +36 to +38
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

useTranslation() is called before the component is wrapped by <TranslationProvider>, so it won’t read the provider context during that render. Move <TranslationProvider> above DiagramEditor (app/root level), or move useTranslation() into a child component that is rendered inside the provider.

Copilot uses AI. Check for mistakes.
<h1>Hello from DiagramEditor component!</h1>
<p>Read-only: {props.isReadOnly ? "true" : "false"}</p>
<p>Content: {props.content}</p>

<button style={clickmeBtnStyle} onClick={() => alert("Hello from Diagram!")}>
Click me!
</button>
Comment on lines 43 to 45
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.
</TranslationProvider>
);
};
Loading