@@ -12,6 +12,10 @@ import type { TFunction } from 'i18next';
1212import type momentTimezone from 'moment-timezone' ;
1313import type { TranslationLanguages } from 'stream-chat' ;
1414
15+ import {
16+ NotificationTranslationBuilder ,
17+ TranslationsBuilderManager ,
18+ } from './TranslationBuilder' ;
1519import type { UnknownType } from '../types/types' ;
1620import type { CustomFormatters , PredefinedFormatters , TDateTimeParser } from './types' ;
1721
@@ -90,7 +94,7 @@ Dayjs.updateLocale('fr', {
9094 lastWeek : 'dddd [dernier à] LT' ,
9195 nextDay : '[Demain à] LT' ,
9296 nextWeek : 'dddd [à] LT' ,
93- sameDay : ' [Aujourd’ hui à] LT' ,
97+ sameDay : " [Aujourd' hui à] LT" ,
9498 sameElse : 'L' ,
9599 } ,
96100} ) ;
@@ -258,15 +262,16 @@ export type Streami18nOptions = {
258262 formatters ?: Partial < PredefinedFormatters > & CustomFormatters ;
259263 language ?: TranslationLanguages ;
260264 logger ?: ( message ?: string ) => void ;
265+ postProcess ?: string [ ] ;
261266 parseMissingKeyHandler ?: ( key : string , defaultValue ?: string ) => string ;
262267 timezone ?: string ;
263268 translationsForLanguage ?: Partial < typeof enTranslations > ;
264269} ;
265270
266271/**
267- * Wrapper around [i18next](https://www.i18next.com/) class for Stream related translations .
268- * Instance of this class should be provided to Chat component to handle translations .
269- * Stream provides following list of in-built translations :
272+ * Wrapper around [i18next](https://www.i18next.com/) class for Stream related i18n .
273+ * Instance of this class should be provided to Chat component to handle i18n .
274+ * Stream provides following list of in-built i18n :
270275 * 1. English (en)
271276 * 2. Dutch (nl)
272277 * 3. Russian (ru)
@@ -330,7 +335,7 @@ export type Streami18nOptions = {
330335 * </Chat>
331336 * ```
332337 *
333- * ## Datetime translations
338+ * ## Datetime i18n
334339 *
335340 * Stream react chat components uses [dayjs](https://day.js.org/en/) internally by default to format datetime stamp.
336341 * e.g., in ChannelPreview, MessageContent components.
@@ -422,10 +427,12 @@ const defaultStreami18nOptions = {
422427 disableDateTimeTranslations : false ,
423428 language : 'en' as TranslationLanguages ,
424429 logger : ( message ?: string ) => console . warn ( message ) ,
430+ postProcess : [ 'notification' ] ,
425431} ;
426432
427433export class Streami18n {
428434 i18nInstance = i18n . createInstance ( ) ;
435+ translationsBuilderManager : TranslationsBuilderManager ;
429436 Dayjs = null ;
430437 setLanguageCallback : ( t : TFunction ) => void = ( ) => null ;
431438 initialized = false ;
@@ -477,6 +484,7 @@ export class Streami18n {
477484 lng : string ;
478485 nsSeparator : false ;
479486 parseMissingKeyHandler ?: ( key : string , defaultValue ?: string ) => string ;
487+ postProcess : string [ ] ;
480488 } ;
481489 /**
482490 * A valid TZ identifier string (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
@@ -519,6 +527,7 @@ export class Streami18n {
519527 this . DateTimeParser = finalOptions . DateTimeParser ;
520528 this . timezone = finalOptions . timezone ;
521529 this . formatters = { ...predefinedFormatters , ...options ?. formatters } ;
530+ this . translationsBuilderManager = new TranslationsBuilderManager ( this . i18nInstance ) ;
522531
523532 try {
524533 if ( this . DateTimeParser && isDayJs ( this . DateTimeParser ) ) {
@@ -563,6 +572,7 @@ export class Streami18n {
563572 keySeparator : false ,
564573 lng : this . currentLanguage ,
565574 nsSeparator : false ,
575+ postProcess : finalOptions . postProcess ,
566576 } ;
567577
568578 if ( finalOptions . parseMissingKeyHandler ) {
@@ -624,6 +634,11 @@ export class Streami18n {
624634 this . i18nInstance . services . formatter ?. add ( name , formatterFactory ( this ) ) ;
625635 } ) ;
626636 }
637+ // Register post-processors after initialization
638+ this . translationsBuilderManager . register (
639+ 'notification' ,
640+ NotificationTranslationBuilder ,
641+ ) ;
627642 } catch ( error ) {
628643 this . logger ( `Something went wrong with init: ${ JSON . stringify ( error ) } ` ) ;
629644 }
0 commit comments