-
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
625ad89
a3ebcb6
6f76d97
001c00e
4cfa4b9
a7ed3aa
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,35 @@ | ||||||||||
| { | ||||||||||
| "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": { | ||||||||||
| "i18next": "catalog:", | ||||||||||
| "react-i18next": "catalog:" | ||||||||||
| }, | ||||||||||
| "devDependencies": { | ||||||||||
| "@types/node": "catalog:", | ||||||||||
| "@types/react": "catalog:", | ||||||||||
| "@types/react-dom": "catalog:", | ||||||||||
| "@types/react-i18next": "^8.1.0", | ||||||||||
|
||||||||||
| "@types/react-i18next": "^8.1.0", |
kumaradityaraj marked this conversation as resolved.
Show resolved
Hide resolved
| 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> | ||
| ); | ||
| } |
| 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; |
| 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. | ||
| */ | ||
|
|
||
kumaradityaraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export { TranslationProvider, useLanguage } from "./TranslationProvider"; | ||
| export { default as i18n } from "./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. These translations are related to
Contributor
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
Contributor
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 like the Idea of having an external package so we do not need to set up i18n from scratch for just any new package we create. WDYT? |
| 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,11 @@ | ||||||||||
| { | ||||||||||
| "extends": "../../tsconfig.base.json", | ||||||||||
| "types": ["node"], | ||||||||||
| "compilerOptions": { | ||||||||||
|
Comment on lines
+3
to
+4
|
||||||||||
| "types": ["node"], | |
| "compilerOptions": { | |
| "compilerOptions": { | |
| "types": ["node"], |
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.
This should not be necessary
| "emitDeclarationOnly": false |
| 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,7 +14,9 @@ | |||||
| * limitations under the License. | ||||||
| */ | ||||||
|
|
||||||
| import type { CSSProperties } from "react"; | ||||||
| import { CSSProperties } from "react"; | ||||||
|
||||||
| import { CSSProperties } from "react"; | |
| import type { CSSProperties } from "react"; |
Copilot
AI
Mar 27, 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.
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
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.
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
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.
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.
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