Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langgenius Dify Analyze I18n Diff

From Leeroopedia
Knowledge Sources
Domains Frontend, Build_Tools
Last Updated 2026-02-12 07:00 GMT

Overview

TypeScript script that compares i18n translation keys between the current branch (flat JSON format) and the main branch (nested TypeScript format) to detect missing, changed, and newly added keys.

Description

analyze-i18n-diff.ts is a migration-validation tool designed for use during the transition from nested TypeScript translation files to flat JSON translation files. It performs the following checks:

  1. Namespace file consistency -- Verifies that every .ts namespace from the main branch has a corresponding .json file on the current branch, and that no unconverted .ts files remain.
  2. Missing keys -- Identifies keys present in the main-branch TypeScript files that are absent from the current-branch JSON files.
  3. Changed values -- Detects keys whose values differ between branches, supporting both string and array values.
  4. New keys -- Lists keys that exist only on the current branch.

The script reads main-branch content via git show and git ls-tree, parses the nested TypeScript objects using a Function constructor evaluator, flattens them to dot-separated keys, and compares against the current flat JSON files. It produces a console summary and writes a detailed JSON report to i18n-analysis-report.json.

Usage

Run this script during i18n format migration or before merging a branch that modifies translation files, to ensure no keys are lost or inadvertently changed.

Code Reference

Source Location

Signature

function flattenObject(obj: NestedTranslation, prefix?: string): FlatTranslation
function valuesEqual(a: TranslationValue, b: TranslationValue): boolean
function formatValue(value: TranslationValue): string
function parseTsContent(content: string): NestedTranslation
function getMainBranchFile(filePath: string): string | null
function getTranslationFiles(): string[]
function getMainBranchNamespaces(): string[]
function checkNamespaceFiles(): NamespaceCheckResult
function analyzeFile(baseName: string): AnalysisResult
function main(): void

Import

// CLI script - run directly
npx tsx web/scripts/analyze-i18n-diff.ts

I/O Contract

Inputs

Name Type Required Description
(none -- no CLI arguments) -- -- The script reads from the filesystem and git history automatically
i18n/en-US/*.json JSON files Yes Current-branch flat JSON translation files in the en-US locale directory
git main branch git ref Yes The main branch must be available locally for git show and git ls-tree commands

Outputs

Name Type Description
stdout string Console summary with namespace check results, missing keys, changed values, and new keys
i18n-analysis-report.json JSON file Detailed analysis report written to the web directory containing summary counts, namespace check results, and per-file details
exit code 0 number All namespace files and keys from main exist in the current branch
exit code 1 number Namespace file issues or missing keys detected

Usage Examples

Run the i18n diff analysis

cd web
npx tsx scripts/analyze-i18n-diff.ts

Check the generated report

cat web/i18n-analysis-report.json | jq '.summary'

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment