[PR #25152] feat: add TypeScript type safety for i18next with automated maintenance #30950

Closed
opened 2026-02-21 20:48:32 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/25152

State: closed
Merged: Yes


Fixes #25145

Summary

This PR implements comprehensive TypeScript type safety for the i18next internationalization system with automated maintenance capabilities.

Key Features

  • Complete Type Safety: All translation keys are now type-checked at compile time, preventing runtime errors from missing translation keys
  • Automated Type Generation: Types are automatically generated from the NAMESPACES array in i18next-config.ts
  • CI Integration: Automated type generation and validation integrated into existing workflows
  • Zero Maintenance: Types stay synchronized automatically with no manual intervention required

Implementation Details

  1. Type System:

    • Auto-generated types/i18n.d.ts with complete type definitions for all 27 namespaces
    • Extends both react-i18next and i18next modules for full type coverage
    • Provides flattened key types for dot notation access (e.g., app.createApp)
  2. Automation Scripts:

    • pnpm run gen:i18n-types - Generate type definitions from config
    • pnpm run check:i18n-types - Validate type synchronization
    • Both scripts support CI/CD integration with proper exit codes
  3. CI Integration:

    • Enhanced translate-i18n-base-on-english.yml to auto-generate types when translations change
    • Added type validation to web-tests.yml to ensure synchronization
    • PR creation includes type definition updates automatically

Developer Benefits

  • IDE Support: Full autocomplete and IntelliSense for translation keys
  • Compile-time Safety: TypeScript errors for invalid translation keys
  • Refactoring Safety: Rename/move translation keys with confidence
  • Documentation: Self-documenting translation API through types

Testing

  • Verified type checking works correctly with valid/invalid keys
  • Tested automation scripts handle namespace additions/removals
  • Confirmed CI integration works with existing workflows

Screenshots

Before After
No type checking for translation keys Full TypeScript validation with IDE support

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/25152 **State:** closed **Merged:** Yes --- Fixes #25145 ## Summary This PR implements comprehensive TypeScript type safety for the i18next internationalization system with automated maintenance capabilities. ### Key Features - **Complete Type Safety**: All translation keys are now type-checked at compile time, preventing runtime errors from missing translation keys - **Automated Type Generation**: Types are automatically generated from the NAMESPACES array in i18next-config.ts - **CI Integration**: Automated type generation and validation integrated into existing workflows - **Zero Maintenance**: Types stay synchronized automatically with no manual intervention required ### Implementation Details 1. **Type System**: - Auto-generated types/i18n.d.ts with complete type definitions for all 27 namespaces - Extends both react-i18next and i18next modules for full type coverage - Provides flattened key types for dot notation access (e.g., app.createApp) 2. **Automation Scripts**: - `pnpm run gen:i18n-types` - Generate type definitions from config - `pnpm run check:i18n-types` - Validate type synchronization - Both scripts support CI/CD integration with proper exit codes 3. **CI Integration**: - Enhanced translate-i18n-base-on-english.yml to auto-generate types when translations change - Added type validation to web-tests.yml to ensure synchronization - PR creation includes type definition updates automatically ### Developer Benefits - **IDE Support**: Full autocomplete and IntelliSense for translation keys - **Compile-time Safety**: TypeScript errors for invalid translation keys - **Refactoring Safety**: Rename/move translation keys with confidence - **Documentation**: Self-documenting translation API through types ### Testing - Verified type checking works correctly with valid/invalid keys - Tested automation scripts handle namespace additions/removals - Confirmed CI integration works with existing workflows ## Screenshots | Before | After | |--------|-------| | No type checking for translation keys | Full TypeScript validation with IDE support | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:48:32 -05:00
yindo closed this issue 2026-02-21 20:48:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30950