-
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
13
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 all commits
Commits
Show all changes
13 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 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,33 @@ | ||
| { | ||
| "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", | ||
| "src" | ||
| ], | ||
| "type": "module", | ||
| "main": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "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.
Show resolved
Hide resolved
|
||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "catalog:", | ||
| "@types/react": "catalog:", | ||
| "@types/react-dom": "catalog:", | ||
| "rimraf": "catalog:", | ||
| "typescript": "catalog:" | ||
| }, | ||
| "peerDependencies": { | ||
| "react": "^19.0.0", | ||
| "react-dom": "^19.0.0" | ||
| } | ||
| } | ||
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,29 @@ | ||
| /* | ||
| * 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 type Dictionary = Record<string, string>; | ||
| export type Dictionaries = Record<string, Dictionary>; | ||
|
|
||
| export function createI18n(dictionaries: Dictionaries, locale: string) { | ||
| function t(key: string): string { | ||
| return dictionaries[locale]?.[key] ?? key; | ||
| } | ||
|
|
||
| return { | ||
| t, | ||
| locale, | ||
| }; | ||
| } |
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,19 @@ | ||
| /* | ||
| * 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 * from "./react/I18nProvider"; | ||
| export * from "./core/createI18n"; | ||
| export * from "./utils/detectLocale"; | ||
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,46 @@ | ||
| /* | ||
| * 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, useMemo } from "react"; | ||
| import { createI18n, Dictionaries } from "../core/createI18n"; | ||
|
|
||
| type I18nContextType = ReturnType<typeof createI18n>; | ||
|
|
||
| const I18nContext = createContext<I18nContextType | null>(null); | ||
|
|
||
| export const I18nProvider = ({ | ||
| children, | ||
| locale, | ||
| dictionaries, | ||
| }: { | ||
| children: React.ReactNode; | ||
| locale: string; | ||
| dictionaries: Dictionaries; | ||
| }) => { | ||
| const i18n = useMemo(() => { | ||
| return createI18n(dictionaries, locale); | ||
| }, [locale, dictionaries]); | ||
|
|
||
| return <I18nContext.Provider value={i18n}>{children}</I18nContext.Provider>; | ||
| }; | ||
|
|
||
| export const useI18n = () => { | ||
| const ctx = useContext(I18nContext); | ||
| if (!ctx) { | ||
| throw new Error("useI18n must be used inside I18nProvider"); | ||
| } | ||
| return ctx; | ||
| }; |
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,36 @@ | ||
| /* | ||
| * 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 function detectLocale(supportedLocales: readonly string[], fallback: string = "en"): string { | ||
| if (typeof navigator === "undefined") { | ||
| return fallback; | ||
| } | ||
| const languages = | ||
| navigator.languages && navigator.languages.length > 0 | ||
| ? navigator.languages | ||
| : [navigator.language]; | ||
|
|
||
| const normalizedSupported = supportedLocales.map((l) => l.toLowerCase().trim()); | ||
| for (const lang of languages) { | ||
| if (!lang) continue; | ||
|
|
||
| const short = lang.split("-")[0]?.toLowerCase().trim(); | ||
| if (short && normalizedSupported.includes(short)) { | ||
| return short; | ||
| } | ||
| } | ||
| return fallback; | ||
| } |
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,14 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "baseUrl": ".", | ||
| "declaration": true, | ||
| "declarationMap": true, | ||
| "sourceMap": true, | ||
|
|
||
| "rootDirs": ["./src", "./tests"], | ||
| "outDir": "./dist" | ||
| }, | ||
| "include": ["src/**/*"], | ||
| "exclude": ["node_modules", "dist", "dist-storybook"] | ||
| } |
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
23 changes: 23 additions & 0 deletions
23
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,23 @@ | ||
| /* | ||
| * 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 const en = { | ||
| save: "Save", | ||
| delete: "Delete", | ||
| cancel: "Cancel", | ||
| } as const; | ||
|
|
||
| export type TranslationKeys = keyof typeof en; |
23 changes: 23 additions & 0 deletions
23
packages/serverless-workflow-diagram-editor/src/i18n/locales/fr.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,23 @@ | ||
| /* | ||
| * 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 { TranslationKeys } from "./en"; | ||
|
|
||
| export const fr: Record<TranslationKeys, string> = { | ||
| save: "Sauvegarder", | ||
| delete: "Supprimer", | ||
| cancel: "Annuler", | ||
| }; |
23 changes: 23 additions & 0 deletions
23
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,23 @@ | ||
| /* | ||
| * 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 { en } from "./en"; | ||
| import { fr } from "./fr"; | ||
|
|
||
| export const dictionaries = { | ||
| en, | ||
| fr, | ||
| }; |
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.