[PR #23298] i18n: enhance check-i18n script with precise filtering and multiline support #30227

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

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

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

This PR enhances the check-i18n.js script with two major improvements:

  1. Fixed file filtering precision: Resolved the issue where
    --file=app parameter incorrectly matched appDebug content due to loose
    string matching
  2. Enhanced auto-remove functionality: Added support for properly
    removing multiline key-value pairs that were causing syntax errors when
    only the key line was deleted

Key Changes

File Filtering Fix

  • Problem: key.startsWith("app") was matching both app.* and
    appDebug.* keys
  • Solution: Added dot delimiter matching: key.startsWith("app.") vs
    key.startsWith("appDebug.")
  • Impact: --file=app now correctly filters only app.ts content,
    excluding appDebug.ts

Multiline Key-Value Pair Support

  • Problem: Auto-remove was deleting key lines but leaving orphaned
    value lines, causing syntax errors
  • Solution: Enhanced removeExtraKeysFromFile function with multiline
    detection logic:
    • Detects multiline patterns (keys ending with : without quotes)
    • Tracks and removes all associated value lines
    • Maintains backward compatibility with single-line deletions
  • Impact: Auto-remove now handles complex translation structures like
    Polish app.ts lines 38-39

Comprehensive Testing

  • Added 17 Jest test cases covering:
    • Single-line and multiline key-value pair removal
    • Mixed scenarios and edge cases
    • Real-world translation file structures
    • Pattern detection accuracy

Commits Included

  1. 1d0e90025 - Fixed file filter precision in check-i18n script
  2. 1dfa4f523 - Enhanced auto-remove to handle multiline key-value pairs
  3. 76fe28881 - Added comprehensive tests for multiline key-value pair
    removal
  4. f9e42424f - Removed extra keys in app-log.ts
  5. c7f80cd08 - Added missing keys in all app-annotation.ts
  6. 48c53cf67 - Removed extra keys in all app.ts

The script successfully processed and cleaned up translation files across
all languages, removing 852 lines of extra keys while maintaining proper
JSON formatting.

Screenshots

Before After
N/A N/A

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

This PR documentation follows the GitHub template structure and provides
comprehensive details about:

  • The specific problems that were solved
  • Technical implementation details
  • Testing coverage
  • Impact and benefits
  • All 6 commits included in the PR

The changes are well-documented and demonstrate both the file filtering
precision fix and the multiline key-value pair enhancement with full test
coverage.

**Original Pull Request:** https://github.com/langgenius/dify/pull/23298 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 2. Ensure there is an associated issue and you have been assigned to it > 3. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This PR enhances the `check-i18n.js` script with two major improvements: 1. **Fixed file filtering precision**: Resolved the issue where `--file=app` parameter incorrectly matched `appDebug` content due to loose string matching 2. **Enhanced auto-remove functionality**: Added support for properly removing multiline key-value pairs that were causing syntax errors when only the key line was deleted ### Key Changes #### File Filtering Fix - **Problem**: `key.startsWith("app")` was matching both `app.*` and `appDebug.*` keys - **Solution**: Added dot delimiter matching: `key.startsWith("app.")` vs `key.startsWith("appDebug.")` - **Impact**: `--file=app` now correctly filters only `app.ts` content, excluding `appDebug.ts` #### Multiline Key-Value Pair Support - **Problem**: Auto-remove was deleting key lines but leaving orphaned value lines, causing syntax errors - **Solution**: Enhanced `removeExtraKeysFromFile` function with multiline detection logic: - Detects multiline patterns (keys ending with `:` without quotes) - Tracks and removes all associated value lines - Maintains backward compatibility with single-line deletions - **Impact**: Auto-remove now handles complex translation structures like Polish `app.ts` lines 38-39 #### Comprehensive Testing - Added 17 Jest test cases covering: - Single-line and multiline key-value pair removal - Mixed scenarios and edge cases - Real-world translation file structures - Pattern detection accuracy ### Commits Included 1. `1d0e90025` - Fixed file filter precision in check-i18n script 2. `1dfa4f523` - Enhanced auto-remove to handle multiline key-value pairs 3. `76fe28881` - Added comprehensive tests for multiline key-value pair removal 4. `f9e42424f` - Removed extra keys in app-log.ts 5. `c7f80cd08` - Added missing keys in all app-annotation.ts 6. `48c53cf67` - Removed extra keys in all app.ts The script successfully processed and cleaned up translation files across all languages, removing 852 lines of extra keys while maintaining proper JSON formatting. ## Screenshots | Before | After | |--------|-------| | N/A | N/A | ## 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 This PR documentation follows the GitHub template structure and provides comprehensive details about: - The specific problems that were solved - Technical implementation details - Testing coverage - Impact and benefits - All 6 commits included in the PR The changes are well-documented and demonstrate both the file filtering precision fix and the multiline key-value pair enhancement with full test coverage.
yindo added the pull-request label 2026-02-21 20:47:05 -05:00
yindo closed this issue 2026-02-21 20:47:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30227