Skip to content

fix: Fix i18n bug#229

Merged
hexqi merged 123 commits intoopentiny:developfrom
lu-yg:github/develop
May 27, 2025
Merged

fix: Fix i18n bug#229
hexqi merged 123 commits intoopentiny:developfrom
lu-yg:github/develop

Conversation

@lu-yg
Copy link
Collaborator

@lu-yg lu-yg commented May 27, 2025

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Added the ability to filter and retrieve internationalization (i18n) entries by application context using optional parameters.
  • Bug Fixes
    • Improved handling of language detection in file imports for i18n entries.
    • Enhanced file import logic to correctly accumulate all parsed entries.
  • Documentation
    • Updated API documentation to reflect the new filtering capabilities for i18n entry retrieval.

lu-yg and others added 30 commits December 26, 2024 00:15
@coderabbitai
Copy link

coderabbitai bot commented May 27, 2025

Walkthrough

The changes introduce a new API endpoint in the internationalization entry controller to fetch i18n entries filtered by application-specific parameters (host and host_type). Supporting service interface and implementation methods are added. Additional logic improvements are made for parsing zip files and determining language from file names in the service implementation.

Changes

File(s) Change Summary
.../controller/I18nEntryController.java Refactored existing method to accept host and host_type params; renamed to getI18nEntriesByApp; updated docs.
.../service/app/I18nEntryService.java Added findI18nEntryByApp(Integer host, String hostType) method to interface.
.../service/app/impl/I18nEntryServiceImpl.java Implemented findI18nEntryByApp; improved parseZipFileStream to accumulate results; updated language detection logic.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller as I18nEntryController
    participant Service as I18nEntryService
    participant Impl as I18nEntryServiceImpl
    participant Mapper

    Client->>Controller: GET /i18n-entries?host=&host_type=
    Controller->>Service: findI18nEntryByApp(host, hostType)
    Service->>Impl: findI18nEntryByApp(host, hostType)
    Impl->>Impl: getHostLangs(host, hostType)
    alt Host languages found
        Impl->>Mapper: findI18nEntriesByHostandHostType(host, hostType)
        Mapper-->>Impl: List<I18nEntry>
        Impl->>Impl: Format entries and language list
        Impl-->>Service: I18nEntryListResult
    else No host languages
        Impl-->>Service: Empty I18nEntryListResult
    end
    Service-->>Controller: I18nEntryListResult
    Controller-->>Client: Result<I18nEntryListResult>
Loading

Poem

In the warren of code, a new path appears,
Filtered by host, i18n now cheers!
Languages sorted, entries refined,
Rabbits and devs, their efforts combined.
With zips unzipped and logic improved,
The code hops forward—features approved!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
base/src/main/java/com/tinyengine/it/service/app/impl/I18nEntryServiceImpl.java (1)

562-566: Improved language detection logic.

The change from exact string matching to substring containment (name.contains(Enums.I18nFileName.EN_US.getValue())) makes language detection more flexible for various filename patterns (e.g., "messages_en_us.json", "labels_en_us.json").

Consider adding a comment to explain the language detection logic:

+        // Check if filename contains English locale identifier (en_us)
         if (name.contains(Enums.I18nFileName.EN_US.getValue())) {
             entriesItem.setLang(2);
         } else {
+            // Default to Chinese locale
             entriesItem.setLang(1);
         }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81b4ef0 and 00e7de8.

📒 Files selected for processing (3)
  • base/src/main/java/com/tinyengine/it/controller/I18nEntryController.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/app/I18nEntryService.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/app/impl/I18nEntryServiceImpl.java (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
base/src/main/java/com/tinyengine/it/service/app/impl/I18nEntryServiceImpl.java (1)
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1)
  • Enums (20-911)
🔇 Additional comments (4)
base/src/main/java/com/tinyengine/it/service/app/I18nEntryService.java (1)

128-133: LGTM! Clean interface addition.

The new method signature is well-defined and follows the existing code patterns. The documentation is consistent with the rest of the interface.

base/src/main/java/com/tinyengine/it/controller/I18nEntryController.java (1)

73-88:

Details

❓ Verification inconclusive

Good API enhancement for app-specific filtering.

The method refactoring properly supports filtering i18n entries by application context. The optional parameters and updated documentation are well-implemented.

Verify that the mapper method findI18nEntriesByHostandHostType exists and handles null parameters correctly:


🏁 Script executed:

#!/bin/bash
# Search for the mapper method implementation
ast-grep --pattern 'findI18nEntriesByHostandHostType($$$)'

Length of output: 60


#!/bin/bash
set -e

echo "1. Locating service method declaration:"
rg -n "findI18nEntryByApp" 

echo -e "\n2. Showing surrounding context in the implementation:"
rg -n "findI18nEntryByApp" -B5 -A10

echo -e "\n3. Finding the mapper interface for I18nEntry:"
rg -n "interface.*I18nEntryMapper" 

echo -e "\n4. Listing methods in I18nEntryMapper related to host/hostType filtering:"
rg -n "I18nEntryMapper" -A20 | rg -E "find.*Host"

#!/bin/bash
set -e

echo "1. Locate the service method implementation in I18nEntryService:"
rg -n "findI18nEntryByApp" --pretty

echo -e "\n2. Locate the I18nEntryMapper interface and show its first 50 lines:"
rg -n "interface I18nEntryMapper" -A50 --pretty

echo -e "\n3. Search for mapper methods that include 'host' or 'hostType' in their signatures:"
rg -n -E "find.*host" --pretty

echo -e "\n4. If the above fails, list all methods in I18nEntryMapper:"
rg -n "I18nEntryMapper" -A20 --pretty

Confirm service and mapper implementation

Please verify that the new filtering layer is fully wired through:

  • Ensure I18nEntryService.findI18nEntryByApp(Integer host, String hostType) is declared and implemented.
  • Confirm this service method correctly handles null values for both parameters (i.e., no unintended filtering when parameters are absent).
  • Verify the underlying I18nEntryMapper interface defines a matching method (e.g., a mapper SQL query) that accepts both host and hostType.
base/src/main/java/com/tinyengine/it/service/app/impl/I18nEntryServiceImpl.java (2)

481-481: Excellent bug fix for ZIP file processing.

Changed from entriesItems = parseZip(fileInfo) to entriesItems.addAll(parseZip(fileInfo)) to properly accumulate entries from multiple files instead of replacing them. This ensures all i18n entries from a ZIP archive are processed correctly.


378-405:

Details

✅ Verification successful

Well-implemented app-specific filtering method.

The implementation correctly follows the existing pattern from findAllI18nEntry() while adding the necessary filtering by host and hostType parameters. The code reuses existing formatting logic which maintains consistency.

Verify the mapper method exists:


🏁 Script executed:

#!/bin/bash
# Search for the mapper method definition
ast-grep --pattern 'findI18nEntriesByHostandHostType($$$)'
rg -A 5 "findI18nEntriesByHostandHostType"

Length of output: 8018


Approve findI18nEntryByApp Implementation

The mapper method findI18nEntriesByHostandHostType is defined in I18nEntryMapper.java and its XML mapping, so the service method can be approved as-is.

@hexqi hexqi merged commit 1cd40f2 into opentiny:develop May 27, 2025
2 checks passed
lu-yg added a commit that referenced this pull request May 27, 2025
@lu-yg lu-yg deleted the github/develop branch May 27, 2025 08:04
lu-yg added a commit to lu-yg/tiny-engine-backend-java that referenced this pull request Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants