-
Notifications
You must be signed in to change notification settings - Fork 7
Add localization (i18n) support #15 #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||
| { | ||||||||||
| "name": "@serverlessworkflow/i18n", | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||
| "version": "1.0.0", | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| "files": [ | ||||||||||
| "dist" | ||||||||||
| ], | ||||||||||
| "type": "module", | ||||||||||
| "main": "dist/index.js", | ||||||||||
| "exports": { | ||||||||||
| ".": { | ||||||||||
| "import": "./dist/index.js", | ||||||||||
| "types": "./dist/index.d.ts" | ||||||||||
| } | ||||||||||
| }, | ||||||||||
| "scripts": { | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the lint, format, test commands. |
||||||||||
| "clean": "rimraf ./dist", | ||||||||||
| "build": "pnpm clean && tsc -p tsconfig.json", | ||||||||||
| "build:prod": "pnpm run build" | ||||||||||
|
Comment on lines
+17
to
+18
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow the repository style
Suggested change
|
||||||||||
| }, | ||||||||||
| "dependencies": { | ||||||||||
| "@serverlessworkflow/i18n": "workspace:*", | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a circular dependency
Suggested change
|
||||||||||
| "i18next": "catalog:", | ||||||||||
| "react-i18next": "catalog:" | ||||||||||
| }, | ||||||||||
| "devDependencies": { | ||||||||||
| "@types/node": "catalog:", | ||||||||||
| "rimraf": "catalog:" | ||||||||||
kumaradityaraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| } | ||||||||||
| } | ||||||||||
| 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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to follow the official guide: |
||
| if (instance.isInitialized) { | ||
| return instance; | ||
| } | ||
|
|
||
| await instance.use(initReactI18next).init({ | ||
| resources, | ||
| defaultNS, | ||
| fallbackLng: "en", | ||
|
|
||
| interpolation: { | ||
| escapeValue: false, | ||
| }, | ||
|
|
||
| react: { | ||
| useSuspense: false, | ||
| }, | ||
| }); | ||
|
|
||
| return instance; | ||
| } | ||
| 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. | ||
| */ | ||
|
|
||
kumaradityaraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import type {} from "./types"; | ||
|
|
||
| export * from "./config"; | ||
| export * from "./resources"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These translations are related to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
| 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" | ||
| } |
| 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
|
||||||||||||||||||||||||||||||||||||
| 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
AI
Mar 25, 2026
There was a problem hiding this comment.
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).
| 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"]; | ||
| } | ||
| } |
| 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 | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be necessary
Suggested change
|
||||
| }, | ||||
| "include": ["src"] | ||||
| } | ||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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:", | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is needed
Suggested change
|
||||
| "react-i18next": "catalog:" | ||||
| }, | ||||
| "devDependencies": { | ||||
| "@chromatic-com/storybook": "catalog:", | ||||
| "@storybook/addon-a11y": "catalog:", | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) => { | |
| <button style={clickmeBtnStyle} onClick={() => alert("Hello from Diagram!")}> | ||
| Click me! | ||
| </button> | ||
|
Comment on lines
44
to
46
|
||
| <div> | ||
| {t("welcome")} {t("start")} {t("setup")}{" "} | ||
| </div> | ||
|
Comment on lines
+47
to
+49
|
||
| </> | ||
| ); | ||
| }; | ||
| 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 }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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