UNPKG

stream-chat-react

Version:

React components to create chat conversations or livestream style chat

30 lines (29 loc) 1.47 kB
import { attachmentUploadBlockedNotificationTranslator, attachmentUploadFailedNotificationTranslator, } from './attachmentUpload'; import { TranslationTopic } from '../../TranslationBuilder'; import { pollCreationFailedNotificationTranslator } from './pollComposition'; import { pollVoteCountTrespass } from './pollVoteCountTrespass'; export const defaultNotificationTranslators = { 'api:attachment:upload:failed': attachmentUploadFailedNotificationTranslator, 'api:poll:create:failed': pollCreationFailedNotificationTranslator, 'validation:attachment:upload:blocked': attachmentUploadBlockedNotificationTranslator, 'validation:poll:castVote:limit': pollVoteCountTrespass, }; export class NotificationTranslationTopic extends TranslationTopic { constructor({ i18next, translators }) { super({ i18next, translators: defaultNotificationTranslators }); this.translate = (value, key, options) => { const { notification } = options; if (!notification) return value; const translator = notification.type && this.translators.get(notification.type); if (!translator) return value; return translator({ key, options, t: this.i18next.t, value }) || value; }; if (translators) { Object.entries(translators).forEach(([name, translator]) => { this.setTranslator(name, translator); }); } } }