Skip to content

feat: add Translate text button backed by translator microservice#40

Merged
OmerGursoy04 merged 2 commits intomainfrom
translation-feature
Mar 27, 2026
Merged

feat: add Translate text button backed by translator microservice#40
OmerGursoy04 merged 2 commits intomainfrom
translation-feature

Conversation

@anthony-tom1
Copy link
Copy Markdown

@anthony-tom1 anthony-tom1 commented Mar 27, 2026

Context

This PR adds a new “Translate text” action under each topic post so users can request English translation on demand. It introduces end-to-end wiring from the post UI to a new NodeBB API endpoint, and from that endpoint to the external translator microservice with safe fallback behavior.

Summary

  • Added “Translate text” button and translation result panel under each post’s content in Harmony post templates
  • Added frontend click handling on topic posts to:
    • call GET /api/v3/posts/:pid/translate
    • show loading/detected-language/translated text states
    • gracefully handle failures
  • Added new backend API endpoint GET /api/v3/posts/:pid/translate
  • Integrated server-side translation call to external microservice:
    • GET ${TRANSLATOR_URL}/?content=<urlencoded text>
    • configurable timeout via LLM_TRANSLATE_TIMEOUT_MS (default 5000)
    • fallback to original text when service is unavailable
  • Added i18n labels/messages for translation UI (en-US, en-GB, en-x-pirate)

Files Changed

  • vendor/nodebb-theme-harmony-main/templates/partials/topic/post.tpl: add translate button + translation container
  • vendor/nodebb-theme-harmony-2.1.35/templates/partials/topic/post.tpl: add translate button + translation container
  • public/src/client/topic/postTools.js: add post translate click handler and UI update logic
  • src/routes/write/posts.js: add GET /:pid/translate route
  • src/controllers/write/posts.js: add Posts.getTranslation controller
  • src/api/posts.js: implement postsAPI.getTranslation with microservice call + timeout + fallback
  • public/language/en-US/search.json: add translation UI strings
  • public/language/en-GB/search.json: add translation UI strings
  • public/language/en-x-pirate/search.json: add translation UI strings

Testing

  • Lint check on changed backend/frontend files: no linter errors reported
  • Manual code-path verification:
    • button markup exists in both Harmony post templates
    • frontend event handler exists for [component="post/translate"]
    • route/controller/api wiring exists for /:pid/translate
  • Note: full runtime manual test requires local Redis + NodeBB startup

Manual Verification Steps

  1. Set translator service URL (if not default): TRANSLATOR_URL=http://localhost:5001
  2. Start Redis and NodeBB, then open a topic page
  3. Click Translate text under a post
  4. Confirm:
    • loading message appears
    • detected language label appears
    • translated English text (or fallback original text on service failure)

…microservice

Adds a translate action under each topic post and a new GET /api/v3/posts/:pid/translate backend route that calls the external translator service (TRANSLATOR_URL) with timeout and safe fallback to original text when unavailable.
Adds missing write API schema entry and path file for GET /api/v3/posts/{pid}/translate so route-to-schema parity tests pass in CI.
@OmerGursoy04 OmerGursoy04 merged commit 98d3358 into main Mar 27, 2026
1 check passed
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