-
Notifications
You must be signed in to change notification settings - Fork 10
feat: full i18n #1739
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
elibosley
wants to merge
19
commits into
main
Choose a base branch
from
feat/i18n
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
feat: full i18n #1739
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
28debe6
feat(i18n): implement internationalization support with extraction sc…
elibosley 67e424c
chore(extract-translations): remove unnecessary newline at the beginn…
elibosley 3cfae32
feat(i18n): enhance internationalization support across API and UI co…
elibosley 57c2dea
fix(extract-translations): add missing newline for improved readability
elibosley fb2856d
feat(i18n): enhance translation management with sorting script
elibosley 2357031
feat(i18n): enhance localization in ConnectSettings and logging compo…
elibosley f74549d
feat(i18n): enhance localization in LogViewer and SingleLogViewer com…
elibosley eea5d4e
fix(i18n): update translation file paths and add new dependencies
elibosley 7583331
feat/i18n (#1738)
elibosley 2f7e64b
New Crowdin updates (#1740)
elibosley f48c85c
refactor(i18n): remove translations.php file and update related refer…
elibosley d81b5f5
feat(i18n): add i18n support for JSON schema and update OIDC configur…
elibosley 1b27226
fix(i18n): refine i18n integration in JSON schema and OIDC configuration
elibosley c1bd053
fix(tests): correct mock function signature for window locale retrieval
elibosley 0ee0da7
fix(i18n): simplify i18n key assignment in form-utils
elibosley dc8f720
feat(i18n): enhance i18n integration across components and locales
elibosley f25a468
feat(i18n): enhance i18n integration in test components
elibosley 57bef96
New Crowdin updates (#1741)
elibosley e61ee74
refactor(tests): clean up unused imports in test files
elibosley 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "4.22.2", | ||
"version": "4.25.2", | ||
"extraOrigins": [], | ||
"sandbox": true, | ||
"ssoSubIds": [], | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
#!/usr/bin/env node | ||
|
||
import { readFile, writeFile } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { glob } from 'glob'; | ||
import ts from 'typescript'; | ||
|
||
const projectRoot = process.cwd(); | ||
const sourcePatterns = 'src/**/*.{ts,js}'; | ||
const ignorePatterns = [ | ||
'**/__tests__/**', | ||
'**/__test__/**', | ||
'**/*.spec.ts', | ||
'**/*.spec.js', | ||
'**/*.test.ts', | ||
'**/*.test.js', | ||
]; | ||
|
||
const englishLocaleFile = path.resolve(projectRoot, 'src/i18n/en.json'); | ||
|
||
const identifierTargets = new Set(['t', 'translate']); | ||
const propertyTargets = new Set([ | ||
'i18n.t', | ||
'i18n.translate', | ||
'ctx.t', | ||
'this.translate', | ||
'this.i18n.translate', | ||
'this.i18n.t', | ||
]); | ||
|
||
function getPropertyChain(node) { | ||
if (ts.isIdentifier(node)) { | ||
return node.text; | ||
} | ||
if (ts.isPropertyAccessExpression(node)) { | ||
const left = getPropertyChain(node.expression); | ||
if (!left) return undefined; | ||
return `${left}.${node.name.text}`; | ||
} | ||
return undefined; | ||
} | ||
|
||
function extractLiteral(node) { | ||
if (ts.isStringLiteralLike(node)) { | ||
return node.text; | ||
} | ||
if (ts.isNoSubstitutionTemplateLiteral(node)) { | ||
return node.text; | ||
} | ||
return undefined; | ||
} | ||
|
||
function collectKeysFromSource(sourceFile) { | ||
const keys = new Set(); | ||
|
||
function visit(node) { | ||
if (ts.isCallExpression(node)) { | ||
const expr = node.expression; | ||
let matches = false; | ||
|
||
if (ts.isIdentifier(expr) && identifierTargets.has(expr.text)) { | ||
matches = true; | ||
} else if (ts.isPropertyAccessExpression(expr)) { | ||
const chain = getPropertyChain(expr); | ||
if (chain && propertyTargets.has(chain)) { | ||
matches = true; | ||
} | ||
} | ||
|
||
if (matches) { | ||
const [firstArg] = node.arguments; | ||
if (firstArg) { | ||
const literal = extractLiteral(firstArg); | ||
if (literal) { | ||
keys.add(literal); | ||
} | ||
} | ||
} | ||
} | ||
|
||
ts.forEachChild(node, visit); | ||
} | ||
|
||
visit(sourceFile); | ||
return keys; | ||
} | ||
|
||
async function loadEnglishCatalog() { | ||
try { | ||
const raw = await readFile(englishLocaleFile, 'utf8'); | ||
const parsed = raw.trim() ? JSON.parse(raw) : {}; | ||
if (typeof parsed !== 'object' || Array.isArray(parsed)) { | ||
throw new Error('English locale file must contain a JSON object.'); | ||
} | ||
return parsed; | ||
} catch (error) { | ||
if (error && error.code === 'ENOENT') { | ||
return {}; | ||
} | ||
throw error; | ||
} | ||
} | ||
|
||
async function ensureEnglishCatalog(keys) { | ||
const existingCatalog = await loadEnglishCatalog(); | ||
const existingKeys = new Set(Object.keys(existingCatalog)); | ||
|
||
let added = 0; | ||
const combinedKeys = new Set([...existingKeys, ...keys]); | ||
const sortedKeys = Array.from(combinedKeys).sort((a, b) => a.localeCompare(b)); | ||
const nextCatalog = {}; | ||
|
||
for (const key of sortedKeys) { | ||
if (Object.prototype.hasOwnProperty.call(existingCatalog, key)) { | ||
nextCatalog[key] = existingCatalog[key]; | ||
} else { | ||
nextCatalog[key] = key; | ||
added += 1; | ||
} | ||
} | ||
|
||
const nextJson = `${JSON.stringify(nextCatalog, null, 2)}\n`; | ||
const existingJson = JSON.stringify(existingCatalog, null, 2) + '\n'; | ||
|
||
if (nextJson !== existingJson) { | ||
await writeFile(englishLocaleFile, nextJson, 'utf8'); | ||
} | ||
|
||
return added; | ||
} | ||
|
||
async function main() { | ||
const files = await glob(sourcePatterns, { | ||
cwd: projectRoot, | ||
ignore: ignorePatterns, | ||
absolute: true, | ||
}); | ||
|
||
const collectedKeys = new Set(); | ||
|
||
await Promise.all( | ||
files.map(async (file) => { | ||
const content = await readFile(file, 'utf8'); | ||
const sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true); | ||
const keys = collectKeysFromSource(sourceFile); | ||
keys.forEach((key) => collectedKeys.add(key)); | ||
}), | ||
); | ||
|
||
const added = await ensureEnglishCatalog(collectedKeys); | ||
|
||
if (added === 0) { | ||
console.log('[i18n] No new backend translation keys detected.'); | ||
} else { | ||
console.log(`[i18n] Added ${added} key(s) to src/i18n/en.json.`); | ||
} | ||
} | ||
|
||
main().catch((error) => { | ||
console.error('[i18n] Failed to extract backend translations.', error); | ||
process.exitCode = 1; | ||
}); |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
{} |
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 @@ | ||
import '@jsonforms/core/lib/models/jsonSchema4'; | ||
import '@jsonforms/core/lib/models/jsonSchema7'; | ||
import '@jsonforms/core/src/models/jsonSchema4'; | ||
import '@jsonforms/core/src/models/jsonSchema7'; | ||
|
||
declare module '@jsonforms/core/lib/models/jsonSchema4' { | ||
interface JsonSchema4 { | ||
i18n?: string; | ||
} | ||
} | ||
|
||
declare module '@jsonforms/core/lib/models/jsonSchema7' { | ||
interface JsonSchema7 { | ||
i18n?: string; | ||
} | ||
} | ||
|
||
declare module '@jsonforms/core/src/models/jsonSchema4' { | ||
interface JsonSchema4 { | ||
i18n?: string; | ||
} | ||
} | ||
|
||
declare module '@jsonforms/core/src/models/jsonSchema7' { | ||
interface JsonSchema7 { | ||
i18n?: string; | ||
} | ||
} | ||
|
||
declare module '@jsonforms/core/lib/models/jsonSchema4.js' { | ||
interface JsonSchema4 { | ||
i18n?: string; | ||
} | ||
} | ||
|
||
declare module '@jsonforms/core/lib/models/jsonSchema7.js' { | ||
interface JsonSchema7 { | ||
i18n?: string; | ||
} | ||
} |
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.
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.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Verify necessity of side-effect imports for module augmentation.
In TypeScript declaration files, module augmentation via
declare module
typically does not require explicit side-effect imports. These imports may be redundant.Additionally, per the coding guidelines, TypeScript imports should use
.js
extensions for ESM compatibility. If these imports are necessary, consider:However, if these imports serve no purpose beyond TypeScript module resolution, they can likely be removed entirely.
As per coding guidelines.
Run the following script to check @jsonforms/core package structure and determine which module paths are actually exported:
🏁 Script executed:
Length of output: 119
🏁 Script executed:
Length of output: 61
Consolidate JSONForms module augmentations to
.js
ESM pathsdeclare module
blocks for@jsonforms/core/src/models/*
(these source‐path modules aren’t published).declare module
specifiers to use.js
extensions, e.g.:@jsonforms/core/lib/models/jsonSchema4.js
@jsonforms/core/lib/models/jsonSchema7.js
🤖 Prompt for AI Agents