-
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
Open
kumaradityaraj
wants to merge
19
commits into
serverlessworkflow:main
Choose a base branch
from
kumaradityaraj:i18nSetup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
625ad89
Implemented i18n basic setup
kumaradityaraj a3ebcb6
Resolved copilots suggestions
kumaradityaraj 6f76d97
Resolved dependency issue
kumaradityaraj 001c00e
Resolved copilot reviews
kumaradityaraj 4cfa4b9
i18n setup provider
kumaradityaraj a7ed3aa
i18n setup provider error resolve
kumaradityaraj bebe436
Changed the approach and implemented i18n similar to kie-tools
kumaradityaraj 89fe327
adding license
kumaradityaraj 6a69e43
Syncing
kumaradityaraj 5b65d94
fixed ts.config
kumaradityaraj 44ff6f3
copilot suggestions
kumaradityaraj 539e69e
Syncing the changes
kumaradityaraj 95ba43b
new implementation
kumaradityaraj 891f88f
tests and readme added
kumaradityaraj f34c637
package.json correction
kumaradityaraj 9862751
package.json correction
kumaradityaraj aef5608
resolving merge conflicts
kumaradityaraj 08f7b31
copilot suggestion
kumaradityaraj ec6951e
uncommented imperative part
kumaradityaraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "name": "@serverlessworkflow/i18n", | ||
kumaradityaraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "version": "1.0.0", | ||
kumaradityaraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "type": "module", | ||
| "main": "dist/index.js", | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/index.js", | ||
| "types": "./dist/index.d.ts" | ||
| } | ||
| }, | ||
| "scripts": { | ||
kumaradityaraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "clean": "rimraf ./dist", | ||
| "build": "pnpm clean && tsc -p tsconfig.json", | ||
| "build:prod": "pnpm run build" | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| "dependencies": { | ||
| "i18next": "catalog:", | ||
| "react-i18next": "catalog:" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "catalog:", | ||
| "@types/react": "catalog:", | ||
| "@types/react-dom": "catalog:", | ||
| "@types/react-i18next": "^8.1.0", | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "rimraf": "catalog:" | ||
| }, | ||
| "peerDependencies": { | ||
| "react": "^19.0.0", | ||
| "react-dom": "^19.0.0" | ||
| } | ||
| } | ||
kumaradityaraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "types": ["node"], | ||
| "compilerOptions": { | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "outDir": "dist", | ||
| "rootDir": "src", | ||
| "declaration": true, | ||
| "emitDeclarationOnly": false | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| "include": ["src"] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/serverless-workflow-diagram-editor/src/i18n/SwdEditorI18n.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { ReferenceDictionary } from "@serverlessworkflow/i18n/dist/core"; | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| interface SwdEditorDictionary extends ReferenceDictionary<{}> {} | ||
|
|
||
| export interface SwdEditorI18n extends SwdEditorDictionary {} | ||
|
|
||
| export interface SwdEditorI18n { | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| hello: string; | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
packages/serverless-workflow-diagram-editor/src/i18n/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 * from "./SwdEditorI18n"; | ||
| export * from "./setup"; |
21 changes: 21 additions & 0 deletions
21
packages/serverless-workflow-diagram-editor/src/i18n/locales/en.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { SwdEditorI18n } from "../SwdEditorI18n"; | ||
|
|
||
| export const en: SwdEditorI18n = { | ||
| hello: "Welcome to the editor", | ||
| }; |
17 changes: 17 additions & 0 deletions
17
packages/serverless-workflow-diagram-editor/src/i18n/locales/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* | ||
| * 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 { en } from "./en"; |
35 changes: 35 additions & 0 deletions
35
packages/serverless-workflow-diagram-editor/src/i18n/setup.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * 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 * as React from "react"; | ||
| import { useContext } from "react"; | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import { en } from "./locales"; | ||
| import { I18nContextType } from "@serverlessworkflow/i18n/dist/react-components"; | ||
| import { SwdEditorI18n } from "./SwdEditorI18n"; | ||
| import { I18nDefaults, I18nDictionaries } from "@serverlessworkflow/i18n/dist/core"; | ||
|
|
||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export const swdEditorI18nDefaults: I18nDefaults<SwdEditorI18n> = { | ||
| locale: "en", | ||
| dictionary: en, | ||
| }; | ||
| export const swdEditorDictionaries: I18nDictionaries<SwdEditorI18n> = new Map([["en", en]]); | ||
| export const SwdEditorI18nContext = React.createContext<I18nContextType<SwdEditorI18n>>( | ||
| {} as never, | ||
| ); | ||
|
|
||
| export function useSwdEditorI18n(): I18nContextType<SwdEditorI18n> { | ||
| return useContext(SwdEditorI18nContext); | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
kumaradityaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.