Skip to content

Conversation

@dkrizan
Copy link
Contributor

@dkrizan dkrizan commented Dec 2, 2025

#3330

Summary by CodeRabbit

  • Refactor

    • Updated internal tag attribute handling in translation processing.
  • Tests

    • Added test coverage for XML tag stripping in translation utilities.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Walkthrough

Updates Tolgee XML tag handling in plural translation utilities by replacing the id attribute with tolgee-id and updating the regex pattern from dynamically constructed to an explicit pattern for matching tags.

Changes

Cohort / File(s) Summary
Plural Translation Utility Updates
backend/data/src/main/kotlin/io/tolgee/service/machineTranslation/PluralTranslationUtil.kt
Updated TOLGEE_TAG_OPEN constant to use tolgee-id attribute instead of id. Replaced dynamic regex construction with explicit pattern <x tolgee-id="[^\">]*?\">.*?</x> for TOLGEE_TAG_REGEX.
Plural Translation Unit Tests
backend/data/src/test/kotlin/io/tolgee/unit/util/PluralTranslationUtilTest.kt
Updated test expectations to reflect tolgee-id attribute naming. Added new test method strips translated x tags() to validate TOLGEE_TAG_REGEX stripping behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Straightforward attribute naming migration across utility and tests
  • Explicit regex pattern is clearly defined and testable
  • New test method coverage validates the regex change

Suggested reviewers

  • JanCizmar

Poem

🐰 Tags transform from id to tolgee-id,
A regex shift, precise and tidy!
With x-tags dancing in their new attire,
Plural translations climb ever higher. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: updating the Tolgee tag regex pattern from using id to tolgee-id attributes for number placeholders in PluralTranslationUtil.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch danielkrizan/non-translatable-plural-translation-placeholder

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@dkrizan dkrizan requested a review from Anty0 December 2, 2025 12:09
Copy link
Contributor

@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 (2)
backend/data/src/main/kotlin/io/tolgee/service/machineTranslation/PluralTranslationUtil.kt (1)

69-69: Minor optimization: Non-greedy quantifier is redundant.

The non-greedy quantifier *? in [^\">]*? is redundant since it's immediately followed by the fixed delimiter ">. The greedy * would have the same behavior and potentially perform slightly better. However, this is a very minor optimization and the current code is correct and readable.

If you'd like to apply the micro-optimization:

-    val TOLGEE_TAG_REGEX = "<x tolgee-id=\"[^\">]*?\">.*?</x>".toRegex()
+    val TOLGEE_TAG_REGEX = "<x tolgee-id=\"[^\">]*\">.*?</x>".toRegex()

Note: The .*? should remain non-greedy to avoid matching multiple tags in one match.

backend/data/src/test/kotlin/io/tolgee/unit/util/PluralTranslationUtilTest.kt (1)

32-36: LGTM! Good test coverage for the regex replacement.

This test effectively validates that the regex correctly strips x-tags from translated text, and using a different attribute value (numero-tolleranza) is excellent for verifying the regex flexibility.

Consider adding test cases for edge cases if you want more comprehensive coverage:

@Test
fun `strips x tags with various content`() {
  // Empty content
  "<x tolgee-id=\"test\"></x> text".replace(PluralTranslationUtil.TOLGEE_TAG_REGEX, "#")
    .assert.isEqualTo("# text")
  
  // Whitespace in content
  "<x tolgee-id=\"test\"> 5 </x> items".replace(PluralTranslationUtil.TOLGEE_TAG_REGEX, "#")
    .assert.isEqualTo("# items")
  
  // Multiple tags
  "<x tolgee-id=\"a\">1</x> and <x tolgee-id=\"b\">2</x>".replace(PluralTranslationUtil.TOLGEE_TAG_REGEX, "#")
    .assert.isEqualTo("# and #")
}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd8a6ab and e12fe3a.

📒 Files selected for processing (2)
  • backend/data/src/main/kotlin/io/tolgee/service/machineTranslation/PluralTranslationUtil.kt (1 hunks)
  • backend/data/src/test/kotlin/io/tolgee/unit/util/PluralTranslationUtilTest.kt (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
backend/**/*.kt

📄 CodeRabbit inference engine (AGENTS.md)

backend/**/*.kt: After modifying JPA entities, run ./gradlew diffChangeLog to generate Liquibase changelog entries (add --no-daemon flag if docker command not found)
Run ./gradlew ktlintFormat before committing code

Files:

  • backend/data/src/test/kotlin/io/tolgee/unit/util/PluralTranslationUtilTest.kt
  • backend/data/src/main/kotlin/io/tolgee/service/machineTranslation/PluralTranslationUtil.kt
backend/**/*Test.kt

📄 CodeRabbit inference engine (AGENTS.md)

backend/**/*Test.kt: Use TestData classes for test setup with TestDataService for saving and cleaning test data in unit tests
Use .andAssertThatJson for testing API JSON responses in tests

Files:

  • backend/data/src/test/kotlin/io/tolgee/unit/util/PluralTranslationUtilTest.kt
**/*.{ts,tsx,js,jsx,kt,kts}

⚙️ CodeRabbit configuration file

As part of review, please check if the file follows 'The Stepdown Rule': The most important, high-level concepts should be at the top (like a newspaper headline and opening paragraph). Details should increase as you read downward. Functions should be ordered so that a caller appears before the functions it calls. When working with JavaScript components, we allow the main component to live at the bottom of the file as an exception to the rule.

Files:

  • backend/data/src/test/kotlin/io/tolgee/unit/util/PluralTranslationUtilTest.kt
  • backend/data/src/main/kotlin/io/tolgee/service/machineTranslation/PluralTranslationUtil.kt
🧠 Learnings (1)
📓 Common learnings
Learnt from: stepan662
Repo: tolgee/tolgee-platform PR: 3182
File: webapp/src/component/layout/TopBanner/useAnnouncement.tsx:124-130
Timestamp: 2025-07-28T12:08:29.462Z
Learning: In the Tolgee platform project, JSON translation files are not manually edited. Translations are stored in the Tolgee platform itself and availability is checked at build time. The JSON files are generated artifacts, not the source of truth.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Frontend static check 🪲
  • GitHub Check: Build backend 🏗️
  • GitHub Check: Build frontend 🏗️
🔇 Additional comments (2)
backend/data/src/test/kotlin/io/tolgee/unit/util/PluralTranslationUtilTest.kt (1)

21-27: LGTM! Test assertions correctly reflect the implementation changes.

The updated test expectations consistently use the new tolgee-id attribute across all plural forms, properly validating the behavior of getPreparedSourceStrings.

backend/data/src/main/kotlin/io/tolgee/service/machineTranslation/PluralTranslationUtil.kt (1)

67-69: LGTM! The attribute name change from id to tolgee-id is safe and no old pattern references remain in the codebase.

The change from a dynamically constructed regex to an explicit pattern improves code clarity and maintainability. The attribute rename makes it more specific and avoids potential conflicts with standard HTML id attributes. Verification confirms that no other code references the old id="tolgee-number" pattern in Kotlin files or test resources.

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.

3 participants