Skip to content

Fix translated chat text links losing URL entities#11

Merged
Rocket-Space merged 1 commit intomasterfrom
codex/conserve-links-during-translation
Feb 24, 2026
Merged

Fix translated chat text links losing URL entities#11
Rocket-Space merged 1 commit intomasterfrom
codex/conserve-links-during-translation

Conversation

@Rocket-Space
Copy link
Owner

Motivation

  • Translating whole messages could modify or move visible link text and cause text_link/URL entities to be lost because the original token-based masking did not survive reordering by the translator.
  • The change aims to preserve link identity and original URLs even when the translator alters the visible text or its position.

Description

  • Updated TranslationHelper.maskLinks to emit tagged placeholders that include an ID and the original visible text using the format [[ENT_START_n]]...[[ENT_END_n]] instead of a plain token. (TMessagesProj/src/main/java/org/spacegram/translator/TranslationHelper.java).
  • Added an id field to LinkPlaceholder and store original url and textUrl flags to map translated fragments back to their original entities. (LinkPlaceholder).
  • Implemented restoreTaggedEntities(...) which parses the [[ENT_START_n]]...[[ENT_END_n]] blocks from translated output, inserts the translated visible text into the result, and reconstructs TL_messageEntityTextUrl / TL_messageEntityUrl entities with correct offsets and original URLs. (restoreTaggedEntities + fallback to legacy restoration).
  • Kept a backward-compatible fallback that still handles the legacy token-style placeholders if the translation provider does not return the new tags.

Testing

  • Attempted to compile the module with ./gradlew :TMessagesProj:compileDebugJavaWithJavac -x lint, but the build failed due to the local Java/Gradle environment mismatch (Unsupported class file major version 69), so no successful compilation artifacts were produced on the runner.

Codex Task

@Rocket-Space Rocket-Space merged commit d623bac into master Feb 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant