Skip to content

fix(translation): force block translation for Reddit post text body#1180

Merged
mengxi-ream merged 1 commit intomainfrom
fix/reddit-force-block-post-text-body
Mar 21, 2026
Merged

fix(translation): force block translation for Reddit post text body#1180
mengxi-ream merged 1 commit intomainfrom
fix/reddit-force-block-post-text-body

Conversation

@mengxi-ream
Copy link
Copy Markdown
Owner

Type of Changes

  • 🐛 Bug fix (fix)

Description

  • Add a Reddit-specific custom force-block translation rule for shreddit-post-text-body
  • Keep Reddit post body translations rendering as block paragraphs instead of being squeezed into a single inline translation area
  • Add a unit test covering the Reddit selector match

Related Issue

Closes #1177

How Has This Been Tested?

  • Added unit tests
  • Verified through manual testing

Additional local verification:

  • pnpm vitest run src/utils/host/dom/__tests__/custom-force-block.test.ts
  • pre-push checks passed: lint, type-check, vitest run

Screenshots

N/A

Checklist

  • I have tested these changes locally
  • I have updated the documentation accordingly if necessary
  • My code follows the code style of this project
  • My changes do not break existing functionality
  • If my code was generated by AI, I have proofread and improved it as necessary.

Additional Information

  • Includes a patch changeset for @read-frog/extension

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 21, 2026

🦋 Changeset detected

Latest commit: cd7a1ee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@read-frog/extension Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 21, 2026
@github-actions github-actions bot added the fix label Mar 21, 2026
@mengxi-ream mengxi-ream merged commit c430e6e into main Mar 21, 2026
3 checks passed
@mengxi-ream mengxi-ream deleted the fix/reddit-force-block-post-text-body branch March 21, 2026 05:42
@dosubot dosubot bot added the app: browser extension Related to browser extension label Mar 21, 2026
@dosubot
Copy link
Copy Markdown

dosubot bot commented Mar 21, 2026

Documentation Updates

2 document(s) were updated by changes in this PR:

Auto Translation Features
View Changes
@@ -362,6 +362,7 @@
 **Examples:**
 - On `github.com`, the selector `.react-directory-row-commit-cell *` ensures that commit messages are always translated as blocks below the original text.
 - On `engoo.com`, the selector `#windowexercise-2 > div > div > div.css-ep7xq6 > div > div > div.css-19m2fbm *` forces block translation for article paragraphs in the exercise-2 section, ensuring translations are rendered as separate blocks for better readability.
+- On `www.reddit.com`, the selector `shreddit-post-text-body` forces block translation for Reddit post text bodies, ensuring they render as proper block paragraphs instead of being squeezed into inline translation areas.
 - On `www.youtube.com`, the selector `yt-attributed-string > span` forces block translation for YouTube comments, ensuring comment text is translated as blocks for better readability.
 
 **Configuration:**
@@ -375,6 +376,9 @@
     'engoo.com': [
       '#windowexercise-2 > div > div > div.css-ep7xq6 > div > div > div.css-19m2fbm *',
     ],
+    'www.reddit.com': [
+      'shreddit-post-text-body',
+    ],
     'www.youtube.com': [
       'yt-attributed-string > span',
     ],
@@ -443,6 +447,7 @@
 **Site-Specific Block Translation Selector Reference:**
 - `github.com`: `.react-directory-row-commit-cell *`
 - `engoo.com`: `#windowexercise-2 > div > div > div.css-ep7xq6 > div > div > div.css-19m2fbm *`
+- `www.reddit.com`: `shreddit-post-text-body`
 - `www.youtube.com`: `yt-attributed-string > span`
 
 These selectors ensure translations are rendered as blocks for improved readability and layout integrity on supported sites.
Translation Toggle Logic and Content Detection
View Changes
@@ -39,6 +39,14 @@
 - `table.diff-table` - PR review diff tables (to prevent code diffs in review comments from being translated)
 
 These site-specific exclusions ensure that UI elements, navigation, metadata, and code snippets are not translated, preventing visual misalignment and maintaining the intended user experience on each platform.
+
+**Site-Specific Block Translation Rules:**
+In addition to exclusions, certain sites have custom rules that force specific elements to be translated as block-level paragraphs rather than inline text. This ensures proper translation presentation and prevents visual rendering issues.
+
+For www.reddit.com, the following element is forced to block translation:
+- `shreddit-post-text-body` - Post text body content (to ensure post bodies are translated as block paragraphs rather than being squeezed into a single inline translation area)
+
+These force-block rules use the `CUSTOM_FORCE_BLOCK_TRANSLATION_SELECTOR_MAP` and ensure that content is rendered with appropriate spacing and formatting, improving readability and maintaining the intended layout of translated content.
 
 **Exclusion of Structural Elements in Main Content Mode:**
 In main content mode (when `config.translate.page.range` is not set to `'all'`), top-level structural elements such as `<header>`, `<footer>`, `<nav>`, and `<aside>` are excluded from translation to avoid translating site-wide navigation and structural elements. However, when these same elements appear inside content containers like `<article>` or `<main>`, they are included in translation, as they are likely to be content-specific (such as article titles within a `<header>` inside an `<article>`).
@@ -122,6 +130,9 @@
 **Site-Specific Exclusion Tests:**
 Unit tests verify that site-specific elements in the `CUSTOM_DONT_WALK_INTO_ELEMENT_SELECTOR_MAP` are correctly excluded. For www.reddit.com, tests confirm that `shreddit-post-flair` elements are identified by `isCustomDontWalkIntoElement` and excluded by `isDontWalkIntoAndDontTranslateAsChildElement`, preventing flair tag misalignment during Reddit translations. For github.com, tests confirm that `table.diff-table` elements are correctly identified and excluded, ensuring that PR review code snippets are not translated and maintaining the integrity of code diffs displayed in review comments.
 
+**Site-Specific Block Translation Tests:**
+Unit tests verify that site-specific force-block translation rules in the `CUSTOM_FORCE_BLOCK_TRANSLATION_SELECTOR_MAP` work correctly. For www.reddit.com, tests confirm that `shreddit-post-text-body` elements are identified by `isCustomForceBlockTranslation`, ensuring that Reddit post text bodies are translated as block paragraphs rather than inline text, preventing visual rendering issues where post content would be squeezed into a single inline translation area.
+
 **Content Container Context Tests:**
 Unit tests verify that structural elements like `<header>`, `<footer>`, and `<nav>` are correctly excluded or included based on their context. The tests confirm that:
 - Top-level `<header>` elements are skipped in main content mode

How did I do? Any feedback?  Join Discord

@dosubot
Copy link
Copy Markdown

dosubot bot commented Mar 21, 2026

Related Documentation

4 document(s) may need updating based on files changed in this PR:

Read Frog - Open Source Immersive Translate

Auto Translation Features
View Suggested Changes
@@ -362,6 +362,7 @@
 **Examples:**
 - On `github.com`, the selector `.react-directory-row-commit-cell *` ensures that commit messages are always translated as blocks below the original text.
 - On `engoo.com`, the selector `#windowexercise-2 > div > div > div.css-ep7xq6 > div > div > div.css-19m2fbm *` forces block translation for article paragraphs in the exercise-2 section, ensuring translations are rendered as separate blocks for better readability.
+- On `www.reddit.com`, the selector `shreddit-post-text-body` forces block translation for Reddit post body content, ensuring post text is translated as block paragraphs instead of being squeezed into a single inline translation area.
 - On `www.youtube.com`, the selector `yt-attributed-string > span` forces block translation for YouTube comments, ensuring comment text is translated as blocks for better readability.
 
 **Configuration:**
@@ -375,6 +376,9 @@
     'engoo.com': [
       '#windowexercise-2 > div > div > div.css-ep7xq6 > div > div > div.css-19m2fbm *',
     ],
+    'www.reddit.com': [
+      'shreddit-post-text-body',
+    ],
     'www.youtube.com': [
       'yt-attributed-string > span',
     ],
@@ -443,6 +447,7 @@
 **Site-Specific Block Translation Selector Reference:**
 - `github.com`: `.react-directory-row-commit-cell *`
 - `engoo.com`: `#windowexercise-2 > div > div > div.css-ep7xq6 > div > div > div.css-19m2fbm *`
+- `www.reddit.com`: `shreddit-post-text-body`
 - `www.youtube.com`: `yt-attributed-string > span`
 
 These selectors ensure translations are rendered as blocks for improved readability and layout integrity on supported sites.

[Accept] [Decline]

Auto Translation Features — ✅ Accepted
Translation Toggle Logic and Content Detection
View Suggested Changes
@@ -39,6 +39,10 @@
 - `table.diff-table` - PR review diff tables (to prevent code diffs in review comments from being translated)
 
 These site-specific exclusions ensure that UI elements, navigation, metadata, and code snippets are not translated, preventing visual misalignment and maintaining the intended user experience on each platform.
+
+**Site-Specific Force-Block Translation:**
+In addition to exclusion rules, certain elements on specific sites require force-block translation to maintain proper layout and readability. For www.reddit.com, the following elements use force-block translation rules via `CUSTOM_FORCE_BLOCK_TRANSLATION_SELECTOR_MAP`:
+- `shreddit-post-text-body` - Reddit post text bodies are translated and rendered as block paragraphs rather than inline, ensuring translations are properly formatted and preventing layout issues where content would otherwise be squeezed into a single inline translation area.
 
 **Exclusion of Structural Elements in Main Content Mode:**
 In main content mode (when `config.translate.page.range` is not set to `'all'`), top-level structural elements such as `<header>`, `<footer>`, `<nav>`, and `<aside>` are excluded from translation to avoid translating site-wide navigation and structural elements. However, when these same elements appear inside content containers like `<article>` or `<main>`, they are included in translation, as they are likely to be content-specific (such as article titles within a `<header>` inside an `<article>`).
@@ -122,6 +126,9 @@
 **Site-Specific Exclusion Tests:**
 Unit tests verify that site-specific elements in the `CUSTOM_DONT_WALK_INTO_ELEMENT_SELECTOR_MAP` are correctly excluded. For www.reddit.com, tests confirm that `shreddit-post-flair` elements are identified by `isCustomDontWalkIntoElement` and excluded by `isDontWalkIntoAndDontTranslateAsChildElement`, preventing flair tag misalignment during Reddit translations. For github.com, tests confirm that `table.diff-table` elements are correctly identified and excluded, ensuring that PR review code snippets are not translated and maintaining the integrity of code diffs displayed in review comments.
 
+**Site-Specific Force-Block Translation Tests:**
+Unit tests verify that site-specific force-block translation rules work as expected. For www.reddit.com, tests confirm that `shreddit-post-text-body` elements are correctly identified by `isCustomForceBlockTranslation`, ensuring that Reddit post text bodies are translated and rendered as block paragraphs to maintain proper layout and readability.
+
 **Content Container Context Tests:**
 Unit tests verify that structural elements like `<header>`, `<footer>`, and `<nav>` are correctly excluded or included based on their context. The tests confirm that:
 - Top-level `<header>` elements are skipped in main content mode

[Accept] [Decline]

Translation Toggle Logic and Content Detection — ✅ Accepted

Note: You must be authenticated to accept/decline updates.

How did I do? Any feedback?  Join Discord

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cd7a1ee248

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +164 to +165
"www.reddit.com": [
"shreddit-post-text-body",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Match Reddit's inner text container instead of the host element

On Reddit's current post-body markup, shreddit-post-text-body is just a wrapper around nested block <div>/<p> nodes. In walkAndLabelElement/translateWalkedElement, those inner block descendants become the translation targets, so the new shreddit-post-text-body selector is never the node passed to isCustomForceBlockTranslation(). I verified this with a jsdom case matching the live nesting: the bilingual wrappers were still inserted under the inner paragraphs, not under the custom element. That means this change does not actually fix the “single inline translation area” layout for real Reddit posts; the selector needs to hit the inner content container(s), or the force-block state needs to propagate upward.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: browser extension Related to browser extension fix size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[style]reddit 翻译样式问题

1 participant