stream-chat-react-native-core 5.33.2-beta.2 → 5.34.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/Message/hooks/useMessageActions.js +4 -7
- package/lib/commonjs/components/Message/hooks/useMessageActions.js.map +1 -1
- package/lib/commonjs/icons/Pin.js +3 -3
- package/lib/commonjs/icons/Pin.js.map +1 -1
- package/lib/commonjs/icons/Resend.js +19 -0
- package/lib/commonjs/icons/Resend.js.map +1 -0
- package/lib/commonjs/icons/index.js +11 -0
- package/lib/commonjs/icons/index.js.map +1 -1
- package/lib/commonjs/utils/i18n/Streami18n.js +10 -9
- package/lib/commonjs/utils/i18n/Streami18n.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Message/hooks/useMessageActions.js +4 -7
- package/lib/module/components/Message/hooks/useMessageActions.js.map +1 -1
- package/lib/module/icons/Pin.js +3 -3
- package/lib/module/icons/Pin.js.map +1 -1
- package/lib/module/icons/Resend.js +19 -0
- package/lib/module/icons/Resend.js.map +1 -0
- package/lib/module/icons/index.js +11 -0
- package/lib/module/icons/index.js.map +1 -1
- package/lib/module/utils/i18n/Streami18n.js +10 -9
- package/lib/module/utils/i18n/Streami18n.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/contexts/translationContext/TranslationContext.d.ts +1 -1
- package/lib/typescript/contexts/translationContext/TranslationContext.d.ts.map +1 -1
- package/lib/typescript/icons/Pin.d.ts +5 -1
- package/lib/typescript/icons/Pin.d.ts.map +1 -1
- package/lib/typescript/icons/Resend.d.ts +4 -0
- package/lib/typescript/icons/Resend.d.ts.map +1 -0
- package/lib/typescript/icons/index.d.ts +1 -0
- package/lib/typescript/icons/index.d.ts.map +1 -1
- package/lib/typescript/utils/i18n/Streami18n.d.ts +9 -3
- package/lib/typescript/utils/i18n/Streami18n.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/Message/hooks/useMessageActions.tsx +5 -5
- package/src/contexts/translationContext/TranslationContext.tsx +1 -1
- package/src/icons/Pin.tsx +8 -4
- package/src/icons/Resend.tsx +12 -0
- package/src/icons/index.ts +1 -0
- package/src/utils/__tests__/Streami18n.test.js +53 -17
- package/src/utils/i18n/Streami18n.ts +33 -16
- package/src/version.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { default as Dayjs } from 'dayjs';
|
|
2
2
|
import 'dayjs/locale/nl';
|
|
3
3
|
import localeData from 'dayjs/plugin/localeData';
|
|
4
|
+
import moment from 'moment-timezone';
|
|
4
5
|
|
|
5
6
|
import frTranslations from '../../i18n/fr.json';
|
|
6
7
|
import nlTranslations from '../../i18n/nl.json';
|
|
@@ -18,6 +19,12 @@ const customDayjsLocaleConfig = {
|
|
|
18
19
|
weekdaysShort: 'sun_mán_týs_mik_hós_frí_ley'.split('_'),
|
|
19
20
|
};
|
|
20
21
|
|
|
22
|
+
describe('Jest Timezone', () => {
|
|
23
|
+
it('global config should set the timezone to UTC', () => {
|
|
24
|
+
expect(new Date().getTimezoneOffset()).toBe(0);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
21
28
|
describe('Streami18n instance - default', () => {
|
|
22
29
|
const streami18nOptions = { logger: () => {} };
|
|
23
30
|
const streami18n = new Streami18n(streami18nOptions);
|
|
@@ -184,24 +191,53 @@ describe('setLanguage - switch to french', () => {
|
|
|
184
191
|
});
|
|
185
192
|
});
|
|
186
193
|
|
|
187
|
-
describe('
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
formatters: { timestampFormatter: () => () => 'custom' },
|
|
194
|
-
translationsForLanguage: { abc: '{{ value | timestampFormatter }}' },
|
|
194
|
+
describe('Streami18n timezone', () => {
|
|
195
|
+
describe.each([['moment', moment]])('%s', (moduleName, module) => {
|
|
196
|
+
it('is by default the local timezone', () => {
|
|
197
|
+
const streamI18n = new Streami18n({ DateTimeParser: module });
|
|
198
|
+
const date = new Date();
|
|
199
|
+
expect(streamI18n.tDateTimeParser(date).format('H')).toBe(date.getHours().toString());
|
|
195
200
|
});
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
|
|
202
|
+
it('can be set to different timezone on init', () => {
|
|
203
|
+
const streamI18n = new Streami18n({ DateTimeParser: module, timezone: 'Europe/Prague' });
|
|
204
|
+
const date = new Date();
|
|
205
|
+
expect(streamI18n.tDateTimeParser(date).format('H')).not.toBe(date.getHours().toString());
|
|
206
|
+
expect(streamI18n.tDateTimeParser(date).format('H')).not.toBe(
|
|
207
|
+
(date.getUTCHours() - 2).toString(),
|
|
208
|
+
);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('is ignored if datetime parser does not support timezones', () => {
|
|
212
|
+
const tz = module.tz;
|
|
213
|
+
delete module.tz;
|
|
214
|
+
|
|
215
|
+
const streamI18n = new Streami18n({ DateTimeParser: module, timezone: 'Europe/Prague' });
|
|
216
|
+
const date = new Date();
|
|
217
|
+
expect(streamI18n.tDateTimeParser(date).format('H')).toBe(date.getHours().toString());
|
|
218
|
+
|
|
219
|
+
module.tz = tz;
|
|
220
|
+
});
|
|
221
|
+
describe('formatters property', () => {
|
|
222
|
+
it('contains the default timestampFormatter', () => {
|
|
223
|
+
expect(new Streami18n().formatters.timestampFormatter).toBeDefined();
|
|
224
|
+
});
|
|
225
|
+
it('allows to override the default timestampFormatter', async () => {
|
|
226
|
+
const i18n = new Streami18n({
|
|
227
|
+
formatters: { timestampFormatter: () => () => 'custom' },
|
|
228
|
+
translationsForLanguage: { abc: '{{ value | timestampFormatter }}' },
|
|
229
|
+
});
|
|
230
|
+
await i18n.init();
|
|
231
|
+
expect(i18n.t('abc')).toBe('custom');
|
|
232
|
+
});
|
|
233
|
+
it('allows to add new custom formatter', async () => {
|
|
234
|
+
const i18n = new Streami18n({
|
|
235
|
+
formatters: { customFormatter: () => () => 'custom' },
|
|
236
|
+
translationsForLanguage: { abc: '{{ value | customFormatter }}' },
|
|
237
|
+
});
|
|
238
|
+
await i18n.init();
|
|
239
|
+
expect(i18n.t('abc')).toBe('custom');
|
|
240
|
+
});
|
|
203
241
|
});
|
|
204
|
-
await i18n.init();
|
|
205
|
-
expect(i18n.t('abc')).toBe('custom');
|
|
206
242
|
});
|
|
207
243
|
});
|
|
@@ -4,9 +4,10 @@ import localeData from 'dayjs/plugin/localeData';
|
|
|
4
4
|
import LocalizedFormat from 'dayjs/plugin/localizedFormat';
|
|
5
5
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
6
6
|
import updateLocale from 'dayjs/plugin/updateLocale';
|
|
7
|
+
import utc from 'dayjs/plugin/utc';
|
|
7
8
|
import i18n, { FallbackLng, TFunction } from 'i18next';
|
|
8
9
|
|
|
9
|
-
import type
|
|
10
|
+
import type momentTimezone from 'moment-timezone';
|
|
10
11
|
|
|
11
12
|
import { calendarFormats } from './calendarFormats';
|
|
12
13
|
import {
|
|
@@ -54,6 +55,7 @@ const defaultNS = 'translation';
|
|
|
54
55
|
const defaultLng = 'en';
|
|
55
56
|
|
|
56
57
|
Dayjs.extend(updateLocale);
|
|
58
|
+
Dayjs.extend(utc);
|
|
57
59
|
|
|
58
60
|
Dayjs.updateLocale('en', {
|
|
59
61
|
calendar: calendarFormats.en,
|
|
@@ -147,18 +149,28 @@ const en_locale = {
|
|
|
147
149
|
weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
|
148
150
|
};
|
|
149
151
|
|
|
152
|
+
type DateTimeParserModule = typeof Dayjs | typeof momentTimezone;
|
|
153
|
+
|
|
150
154
|
// Type guards to check DayJs
|
|
151
|
-
const isDayJs = (dateTimeParser:
|
|
155
|
+
const isDayJs = (dateTimeParser: DateTimeParserModule): dateTimeParser is typeof Dayjs =>
|
|
152
156
|
(dateTimeParser as typeof Dayjs).extend !== undefined;
|
|
153
157
|
|
|
158
|
+
type TimezoneParser = {
|
|
159
|
+
tz: momentTimezone.MomentTimezone | Dayjs.Dayjs;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const supportsTz = (dateTimeParser: unknown): dateTimeParser is TimezoneParser =>
|
|
163
|
+
(dateTimeParser as TimezoneParser).tz !== undefined;
|
|
164
|
+
|
|
154
165
|
type Streami18nOptions = {
|
|
155
|
-
DateTimeParser?:
|
|
166
|
+
DateTimeParser?: DateTimeParserModule;
|
|
156
167
|
dayjsLocaleConfigForLanguage?: Partial<ILocale>;
|
|
157
168
|
debug?: boolean;
|
|
158
169
|
disableDateTimeTranslations?: boolean;
|
|
159
170
|
formatters?: Partial<PredefinedFormatters> & CustomFormatters;
|
|
160
171
|
language?: string;
|
|
161
172
|
logger?: (msg?: string) => void;
|
|
173
|
+
timezone?: string;
|
|
162
174
|
translationsForLanguage?: Partial<typeof enTranslations>;
|
|
163
175
|
};
|
|
164
176
|
|
|
@@ -385,10 +397,14 @@ export class Streami18n {
|
|
|
385
397
|
*/
|
|
386
398
|
logger: (msg?: string) => void;
|
|
387
399
|
currentLanguage: string;
|
|
388
|
-
DateTimeParser:
|
|
400
|
+
DateTimeParser: DateTimeParserModule;
|
|
389
401
|
formatters: PredefinedFormatters & CustomFormatters = predefinedFormatters;
|
|
390
402
|
isCustomDateTimeParser: boolean;
|
|
391
403
|
i18nextConfig: I18NextConfig;
|
|
404
|
+
/**
|
|
405
|
+
* A valid TZ identifier string (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
|
406
|
+
*/
|
|
407
|
+
timezone?: string;
|
|
392
408
|
|
|
393
409
|
/**
|
|
394
410
|
* Constructor accepts following options:
|
|
@@ -427,6 +443,7 @@ export class Streami18n {
|
|
|
427
443
|
|
|
428
444
|
this.currentLanguage = finalOptions.language;
|
|
429
445
|
this.DateTimeParser = finalOptions.DateTimeParser;
|
|
446
|
+
this.timezone = finalOptions.timezone;
|
|
430
447
|
this.formatters = { ...predefinedFormatters, ...options?.formatters };
|
|
431
448
|
|
|
432
449
|
try {
|
|
@@ -504,19 +521,19 @@ export class Streami18n {
|
|
|
504
521
|
}
|
|
505
522
|
|
|
506
523
|
this.tDateTimeParser = (timestamp) => {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
return this.DateTimeParser
|
|
524
|
+
const language =
|
|
525
|
+
finalOptions.disableDateTimeTranslations || !this.localeExists(this.currentLanguage)
|
|
526
|
+
? defaultLng
|
|
527
|
+
: this.currentLanguage;
|
|
528
|
+
|
|
529
|
+
// If the DateTimeParser is not a Dayjs instance, we assume it is a Moment instance.
|
|
530
|
+
if (!isDayJs(this.DateTimeParser)) {
|
|
531
|
+
return supportsTz(this.DateTimeParser) && this.timezone
|
|
532
|
+
? this.DateTimeParser(timestamp).tz(this.timezone).locale(language)
|
|
533
|
+
: this.DateTimeParser(timestamp).locale(language);
|
|
515
534
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
return this.DateTimeParser(timestamp).locale(this.currentLanguage);
|
|
535
|
+
|
|
536
|
+
return this.DateTimeParser(timestamp).locale(language);
|
|
520
537
|
};
|
|
521
538
|
}
|
|
522
539
|
|
package/src/version.json
CHANGED