UNPKG

stream-chat-react

Version:

React components to create chat conversations or livestream style chat

397 lines (396 loc) 18 kB
import Dayjs from 'dayjs'; import { TranslationBuilder } from './TranslationBuilder'; import type { TFunction } from 'i18next'; import type momentTimezone from 'moment-timezone'; import type { TranslationLanguages } from 'stream-chat'; import type { TranslationTopicConstructor } from './TranslationBuilder'; import type { UnknownType } from '../types/types'; import type { CustomFormatters, PredefinedFormatters, TDateTimeParser } from './types'; import { enTranslations } from './translations'; import 'dayjs/locale/de'; import 'dayjs/locale/es'; import 'dayjs/locale/fr'; import 'dayjs/locale/hi'; import 'dayjs/locale/it'; import 'dayjs/locale/ja'; import 'dayjs/locale/ko'; import 'dayjs/locale/nl'; import 'dayjs/locale/pt'; import 'dayjs/locale/ru'; import 'dayjs/locale/tr'; import 'dayjs/locale/en'; type CalendarLocaleConfig = { lastDay: string; lastWeek: string; nextDay: string; nextWeek: string; sameDay: string; sameElse: string; }; type DateTimeParserModule = typeof Dayjs | typeof momentTimezone; export type Streami18nOptions = { DateTimeParser?: DateTimeParserModule; dayjsLocaleConfigForLanguage?: Partial<ILocale> & { calendar?: CalendarLocaleConfig; }; debug?: boolean; disableDateTimeTranslations?: boolean; formatters?: Partial<PredefinedFormatters> & CustomFormatters; language?: TranslationLanguages; logger?: (message?: string) => void; translationBuilderTopics?: Record<string, TranslationTopicConstructor>; parseMissingKeyHandler?: (key: string, defaultValue?: string) => string; timezone?: string; translationsForLanguage?: Partial<typeof enTranslations>; }; export declare class Streami18n { i18nInstance: import("i18next").i18n; translationBuilder: TranslationBuilder; private translationBuilderTopics; Dayjs: null; setLanguageCallback: (t: TFunction) => void; initialized: boolean; t: TFunction; tDateTimeParser: TDateTimeParser; translations: { [key: string]: { [key: string]: typeof enTranslations | UnknownType; }; }; /** * dayjs.defineLanguage('nl') also changes the global locale. We don't want to do that * when user calls registerTranslation() function. So instead we will store the locale configs * given to registerTranslation() function in `dayjsLocales` object, and register the required locale * with moment, when setLanguage is called. * */ dayjsLocales: { [key: string]: Partial<ILocale>; }; /** * Initialize properties used in constructor */ logger: (msg?: string) => void; currentLanguage: TranslationLanguages; DateTimeParser: DateTimeParserModule; formatters: PredefinedFormatters & CustomFormatters; isCustomDateTimeParser: boolean; i18nextConfig: { debug: boolean; fallbackLng: false; interpolation: { escapeValue: boolean; formatSeparator: string; }; keySeparator: false; lng: string; nsSeparator: false; parseMissingKeyHandler?: (key: string, defaultValue?: string) => string; postProcess?: string[]; }; /** * A valid TZ identifier string (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) */ timezone?: string; /** * Constructor accepts following options: * - language (String) default: 'en' * Language code e.g., en, tr * * - translationsForLanguage (object) * Translations object. Please check src/i18n/en.json for example. * * - disableDateTimeTranslations (boolean) default: false * Disable translations for date-times * * - debug (boolean) default: false * Enable debug mode in internal i18n class * * - logger (function) default: () => {} * Logger function to log warnings/errors from this class * * - dayjsLocaleConfigForLanguage (object) default: 'enConfig' * [Config object](https://momentjs.com/docs/#/i18n/changing-locale/) for internal moment object, * corresponding to language (param) * * - DateTimeParser (function) Moment or Dayjs instance/function. * Make sure to load all the required locales in this Moment or Dayjs instance that you will be provide to Streami18n * * @param {*} options */ constructor(options?: Streami18nOptions); /** * Initializes the i18next instance with configuration (which enables natural language as default keys) */ init(): Promise<{ t: TFunction<"translation", undefined>; tDateTimeParser: TDateTimeParser; }>; localeExists: (language: TranslationLanguages) => boolean; validateCurrentLanguage: () => void; /** Returns an instance of i18next used within this class instance */ geti18Instance: () => import("i18next").i18n; /** Returns list of available languages. */ getAvailableLanguages: () => string[]; /** Returns all the translation dictionary for all inbuilt-languages */ getTranslations: () => { [key: string]: { [key: string]: { "Add a comment": string; "Add an option": string; "All results loaded": string; "Allow access to camera": string; "Allow access to microphone": string; "Allow comments": string; "Allow option suggestion": string; "Also send as a direct message": string; "Also send in channel": string; "An error has occurred during recording": string; "An error has occurred during the recording processing": string; Anonymous: string; "Anonymous poll": string; Archive: string; "Ask a question": string; Attach: string; "Attach files": string; "Attachment upload blocked due to {{reason}}": string; "Attachment upload failed due to {{reason}}": string; Cancel: string; "Cannot seek in the recording": string; "Channel Missing": string; Close: string; "Close emoji picker": string; "Commands matching": string; "Connection failure, reconnecting now...": string; Create: string; "Create poll": string; "Current location": string; Delete: string; Delivered: string; "Download attachment {{ name }}": string; "Drag your files here": string; "Drag your files here to add to your post": string; "Due since {{ dueSince }}": string; "Due {{ timeLeft }}": string; "Edit Message": string; "Edit message request failed": string; Edited: string; "Emoji matching": string; "Empty message...": string; End: string; "End vote": string; "Error adding flag": string; "Error connecting to chat, refresh the page to try again.": string; "Error deleting message": string; "Error fetching reactions": string; "Error marking message unread. Cannot mark unread messages older than the newest 100 channel messages.": string; "Error muting a user ...": string; "Error pinning message": string; "Error removing message pin": string; "Error reproducing the recording": string; "Error starting recording": string; "Error unmuting a user ...": string; "Error uploading attachment": string; "Error uploading file": string; "Error uploading image": string; "Error \u00B7 Unsent": string; "Error: {{ errorMessage }}": string; "Failed to create the poll": string; "Failed to create the poll due to {{reason}}": string; "Failed to jump to the first unread message": string; "Failed to mark channel as read": string; "Failed to play the recording": string; "Failed to retrieve location": string; "Failed to share location": string; File: string; "File is too large: {{ size }}, maximum upload size is {{ limit }}": string; Flag: string; "Generating...": string; "Latest Messages": string; "Live for {{duration}}": string; "Live location": string; "Live until {{ timestamp }}": string; "Load more": string; Location: string; "Location sharing ended": string; "Mark as unread": string; "Maximum number of votes (from 2 to 10)": string; Menu: string; "Message Failed \u00B7 Click to try again": string; "Message Failed \u00B7 Unauthorized": string; "Message deleted": string; "Message has been successfully flagged": string; "Message pinned": string; "Message was blocked by moderation policies": string; "Messages have been marked unread.": string; "Missing permissions to upload the attachment": string; "Multiple answers": string; Mute: string; New: string; "New Messages!": string; "No chats here yet\u2026": string; "No results found": string; "Nobody will be able to vote in this poll anymore.": string; "Nothing yet...": string; Ok: string; "Only numbers are allowed": string; "Open emoji picker": string; "Option already exists": string; Options: string; "People matching": string; Pin: string; "Pinned by": string; Poll: string; "Poll comments": string; "Poll options": string; "Poll results": string; Question: string; Quote: string; "Reached the vote limit. Remove an existing vote first.": string; "Recording format is not supported and cannot be reproduced": string; "Remind Me": string; "Remove reminder": string; Reply: string; "Reply to Message": string; "Save for later": string; "Saved for later": string; Search: string; "Searching...": string; "See all options ({{count}})_one": string; "See all options ({{count}})_other": string; "Select one": string; "Select one or more": string; "Select up to {{count}}_one": string; "Select up to {{count}}_other": string; Send: string; "Send Anyway": string; "Send message request failed": string; "Sending...": string; Share: string; "Share Location": string; "Share live location for": string; "Shared live location": string; "Show all": string; Shuffle: string; "Slow Mode ON": string; "Some of the files will not be accepted": string; "Start typing to search": string; "Stop sharing": string; Submit: string; "Suggest an option": string; "Thinking...": string; "This field cannot be empty or contain only spaces": string; "This message did not meet our content guidelines": string; "This message was deleted...": string; Thread: string; "Thread has not been found": string; "Thread reply": string; "To start recording, allow the camera access in your browser": string; "To start recording, allow the microphone access in your browser": string; "Type a number from 2 to 10": string; "Type your message": string; Unarchive: string; Unmute: string; Unpin: string; "Unread messages": string; "Unsupported attachment": string; "Update your comment": string; "Upload type: \"{{ type }}\" is not allowed": string; "User uploaded content": string; "View results": string; "View {{count}} comments_one": string; "View {{count}} comments_other": string; "Voice message": string; "Vote ended": string; "Wait until all attachments have uploaded": string; You: string; "You have no channels currently": string; "You've reached the maximum number of files": string; "aria/Attachment": string; "aria/Cancel Reply": string; "aria/Cancel upload": string; "aria/Channel list": string; "aria/Channel search results": string; "aria/Close thread": string; "aria/Download attachment": string; "aria/Emoji picker": string; "aria/File input": string; "aria/File upload": string; "aria/Image input": string; "aria/Load More Channels": string; "aria/Menu": string; "aria/Message Options": string; "aria/Open Attachment Selector": string; "aria/Open Menu": string; "aria/Open Message Actions Menu": string; "aria/Open Reaction Selector": string; "aria/Open Thread": string; "aria/Reaction list": string; "aria/Remind Me Options": string; "aria/Remove attachment": string; "aria/Remove location attachment": string; "aria/Retry upload": string; "aria/Search results": string; "aria/Search results header filter button": string; "aria/Send": string; "aria/Stop AI Generation": string; "duration/Message reminder": string; "duration/Remind Me": string; "duration/Share Location": string; live: string; "network error": string; replyCount_one: string; replyCount_other: string; "search-results-header-filter-source-button-label--channels": string; "search-results-header-filter-source-button-label--messages": string; "search-results-header-filter-source-button-label--users": string; searchResultsCount_one: string; searchResultsCount_other: string; "size limit": string; "this content could not be displayed": string; "timestamp/DateSeparator": string; "timestamp/LiveLocation": string; "timestamp/MessageTimestamp": string; "timestamp/PollVote": string; "timestamp/PollVoteTooltip": string; "timestamp/ReminderNotification": string; "timestamp/SystemMessage": string; "translationBuilderTopic/notification": string; "unknown error": string; unreadMessagesSeparatorText_one: string; unreadMessagesSeparatorText_other: string; "unsupported file type": string; "{{ commaSeparatedUsers }} and {{ moreCount }} more": string; "{{ commaSeparatedUsers }}, and {{ lastUser }}": string; "{{ firstUser }} and {{ secondUser }}": string; "{{ imageCount }} more": string; "{{ memberCount }} members": string; "{{ user }} has been muted": string; "{{ user }} has been unmuted": string; "{{ user }} is typing...": string; "{{ users }} and more are typing...": string; "{{ users }} and {{ user }} are typing...": string; "{{ watcherCount }} online": string; "{{count}} unread_one": string; "{{count}} unread_other": string; "{{count}} votes_one": string; "{{count}} votes_other": string; "\uD83C\uDFD9 Attachment...": string; "\uD83D\uDCCA {{createdBy}} created: {{ pollName}}": string; "\uD83D\uDCCA {{votedBy}} voted: {{pollOptionText}}": string; "\uD83D\uDCCDShared location": string; } | UnknownType; }; }; /** * Returns current version translator function. */ getTranslators(): Promise<{ t: TFunction<"translation", undefined>; tDateTimeParser: TDateTimeParser; }>; registerTranslation(language: TranslationLanguages, translation: typeof enTranslations, customDayjsLocale?: Partial<ILocale>): void; addOrUpdateLocale(key: TranslationLanguages, config: Partial<ILocale>): void; setLanguage(language: TranslationLanguages): Promise<TFunction<"translation", undefined> | undefined>; registerSetLanguageCallback(callback: (t: TFunction) => void): void; } export {};