Repository navigation
feat(Poll): render poll translations in the reader's language - #3341
Open
NikolaGoranNaumovski wants to merge 1 commit into
Open
NikolaGoranNaumovski wants to merge 1 commit into
NikolaGoranNaumovski wants to merge 1 commit into
Conversation
With automatic translation enabled, the API returns a poll's question, options and answers translated, in name_i18n, text_i18n and answer_text_i18n. The default poll components now render the entry for client.user.language and fall back to the original text. - The question and options are translated in the message, the results and the full option list, and answers in the answers dialog. So is the question in the channel list preview and a quoted poll, and so is the option text in the channel list's vote preview. - A poll message starts in the translated view. MessageTranslationIndicator shows on it when the question or an option is translated, and "View original" switches the whole poll back along with any message text. - The indicator reads the live poll from client.polls, so translations that arrive after the first render show it without a reload. - New export: usePollTextTranslation(), for custom poll components that should follow the same translation view.
NikolaGoranNaumovski
requested review from
MartinCupela and
oliverlaz
as code owners
October 22, 2026 10:25
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
Contributor
|
Size Change: +2.78 kB (+0.25%) Total Size: 1.13 MB 📦 View Changed
ℹ️ View Unchanged
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Goal
The v14 counterpart of (
master), for the stable 14.x line.The Chat API now translates polls automatically (question, options and free-form
answers) on the shards where it's deployed, and
stream-chat9.54.0 exposes thetranslated fields (GetStream/stream-chat-js#1878). Until now the React SDK always
showed the original text. With this change, readers see a poll in their own
language, the same way auto-translated message text already works, with "View
original" covering the poll too.
Ticket:
🛠 Implementation details
The same behaviour as the v15 PR, adapted to v14's conventions.
Data.
name_i18n, an option'stext_i18nand an answer'sanswer_text_i18nare v9's
TranslatedField, the same shape asmessage.i18n:<language>_textentries plus
language, the source language. The reader's language isclient.user.language. Anything without a translation falls back to theoriginal.
Translated UI.
PollHeader(title) andPollOptionSelector(options in the message)PollResults,PollOptionWithVotesHeaderandPollOptionsFullList(thequestion and options in the dialogs)
PollAnswerList(answers in the comments dialog)QuotedMessagePreview(a quoted poll's question)Shared logic.
Poll/utils/translations.ts(internal, not exported) is the only code thatknows the key format. It has
getPollTextTranslation,pollHasTranslation(question and options only; answers are only visible inside the comments dialog)
and
getPollSourceLanguage. The lookup casts the key the same way v14'sgetTranslatedMessageTextdoes.usePollTextTranslation()(new public export, throughPoll/hooks) returnstranslate(original, i18n). It follows the message's translation view. It readsuseMessageContext(), which in v14 returns an empty value outside a message, sothe poll parts gain no new requirement.
Translation view and indicator.
Messagestarts a poll message (poll_id) in the translated view. That's safebecause a text without a translation shows the original. The decision doesn't
use
message.poll, which is a snapshot that poll events never update.MessageTranslationIndicatornow shows on poll messages, including messagesthat are only a poll. It subscribes to the live poll (
client.pollsviauseChatContext,useStateStore), so translations that arrive later throughpoll.updatedshow it without a reload. "View original" switches the whole pollback along with any message text. v14's
language/<code>name lookup isunchanged.
i18n. No new
t()strings, so the translation catalog is unchanged.Dependency note. An edited question, or a language added later with
translateMessage, needs the stream-chat-js v9 fix in . Until that patch is required, the question keeps its old translation untila reload (option translations already update live). A follow-up will raise the
stream-chatminimum from^9.54.0once that patch is published.Testing
Poll/__tests__/PollTranslation.test.tsx(header, options and everydialog, translated, original view and fallback, with
axe),Poll/utils/__tests__/translations.test.tsandMessage/__tests__/MessageTranslationIndicator.test.tsx(poll-only message,toggle, no translation,
poll.updatedafter the first render; v14 had noindicator test).
Message.test.tsx(default view),QuotedMessage.test.tsx(quotedpoll) and
ChannelListItem/__tests__/utils.test.ts(created and voted previews).examples/viteagainst a test app with auto-translation on, with users and channels in en, es, de and it, running with the fixed stream-chat-js v9 build. Checklist - [x]yarn lintpassed (includesvalidate-translations) - [x]yarn testpassed (3086 tests)yarn typespassedyarn buildpassedusePollTextTranslation)