@cometchat/chat-uikit-react-native 5.5.0 → 5.5.1
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/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +20 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +9 -1
- package/ios/RichTextEditorView.swift +43 -0
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/RichTextEditorViewManager.swift +8 -0
- package/package.json +5 -2
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +38 -9
- package/src/CometChatConversations/CometChatConversations.tsx +8 -1
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +2 -2
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +15 -3
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +10 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +5 -2
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +478 -0
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +613 -0
- package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +313 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +7 -8
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +43 -19
- package/src/CometChatRichTextEditor/index.tsx +4 -0
- package/src/CometChatRichTextEditor/types.ts +2 -0
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +251 -14
- package/src/CometChatSearch/CometChatSearch.tsx +29 -6
- package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +76 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +2 -1
- package/src/shared/CometChatUiKit/checkAuthSettings-review.md +211 -0
- package/src/shared/constants/UIKitConstants.ts +3 -17
- package/src/shared/constants/textPatterns.ts +27 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +25 -259
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +31 -19
- package/src/shared/formatters/CometChatTextFormatter.ts +22 -0
- package/src/shared/formatters/applyRawFormatters.ts +31 -0
- package/src/shared/framework/MessageDataSource.tsx +14 -8
- package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +15 -30
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +138 -19
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +0 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +54 -1
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +11 -0
- package/src/shared/utils/MarkdownUtils.ts +34 -4
- package/src/shared/utils/PinnedMessagesHelper.ts +65 -0
- package/src/shared/utils/SavedMessagesHelper.ts +42 -6
- package/src/shared/utils/__testUtils__/messagesRequestBuilderMock.ts +37 -0
- package/src/shared/utils/cloneRequestBuilder.ts +25 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +15 -4
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +5 -0
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +4 -1
- package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +8 -1
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +5 -0
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +5 -0
- package/src/shared/views/CometChatList/Header.tsx +8 -2
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +5 -0
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +5 -0
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/src/CometChatMessageList/MANUAL_TEST_CASES.md +0 -154
|
@@ -4,6 +4,7 @@ import { Text, TextStyle, ViewStyle, Platform, Linking, View } from "react-nativ
|
|
|
4
4
|
import { CometChatTextFormatter } from "../CometChatTextFormatter";
|
|
5
5
|
import { COLOR_OPEN_TAG, HEX_COLOR_REGEX, findColorTag, stripColorTags } from "../richTextWireFormat";
|
|
6
6
|
import { isTextElement, isViewElement } from "../../utils/elementType";
|
|
7
|
+
import { urlPattern, emailPattern } from "../../constants/textPatterns";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Style configuration for rich text formatting
|
|
@@ -36,6 +37,12 @@ const QUOTE_BULLET_REGEX = /^- (.*)$/;
|
|
|
36
37
|
const QUOTE_ORDERED_REGEX = /^(\s*)(\d+)\.\s(.*)$/;
|
|
37
38
|
// Mention pattern — used to exclude mention UIDs from markdown marker detection
|
|
38
39
|
const MENTION_PATTERN_REGEX = /<@(?:uid|all):[^>]*>/g;
|
|
40
|
+
// URL pattern — used to exclude URLs from markdown marker detection (ENG-38182)
|
|
41
|
+
const URL_PATTERN_REGEX = new RegExp(urlPattern, "gi");
|
|
42
|
+
// Emails are stashed BEFORE urls: the url pattern matches only the DOMAIN of an address, so
|
|
43
|
+
// `my_name@corp.co.uk` had its local part left exposed and two such addresses in one message
|
|
44
|
+
// paired their underscores into italics — `my_name@` and `my_alt@` rendered as `myname@`/`myalt@`.
|
|
45
|
+
const EMAIL_PATTERN_REGEX = new RegExp(emailPattern, "gi");
|
|
39
46
|
|
|
40
47
|
// Pre-allocated style objects — avoids creating new objects on every render
|
|
41
48
|
const LIST_ROW_STYLE = { flexDirection: 'row' as const, flexShrink: 1 as const };
|
|
@@ -563,29 +570,34 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
563
570
|
return text;
|
|
564
571
|
}
|
|
565
572
|
|
|
566
|
-
// Replace mention patterns with null-byte placeholders before parsing so
|
|
567
|
-
// findItalic/findNextFormat never see underscores
|
|
568
|
-
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
mentionSlots.push(match);
|
|
573
|
+
// Replace mention patterns and URLs with null-byte placeholders before parsing so
|
|
574
|
+
// findItalic/findNextFormat never see underscores inside UIDs or URLs.
|
|
575
|
+
const protectedSlots: string[] = [];
|
|
576
|
+
const stash = (match: string) => {
|
|
577
|
+
const idx = protectedSlots.length;
|
|
578
|
+
protectedSlots.push(match);
|
|
573
579
|
return `\x00M${idx}\x00`;
|
|
574
|
-
}
|
|
580
|
+
};
|
|
581
|
+
let sanitized = text.replace(MENTION_PATTERN_REGEX, stash);
|
|
582
|
+
try {
|
|
583
|
+
sanitized = sanitized.replace(EMAIL_PATTERN_REGEX, stash);
|
|
584
|
+
sanitized = sanitized.replace(URL_PATTERN_REGEX, stash);
|
|
585
|
+
} catch {
|
|
586
|
+
}
|
|
575
587
|
|
|
576
|
-
// Restore mention placeholders in a string or JSX tree
|
|
577
|
-
const
|
|
588
|
+
// Restore mention/URL placeholders in a string or JSX tree
|
|
589
|
+
const restoreProtected = (node: JSX.Element | string): JSX.Element | string => {
|
|
578
590
|
if (typeof node === 'string') {
|
|
579
|
-
if (
|
|
580
|
-
return node.replace(/\x00M(\d+)\x00/g, (_, idx) =>
|
|
591
|
+
if (protectedSlots.length === 0 || node.indexOf('\x00') < 0) return node;
|
|
592
|
+
return node.replace(/\x00M(\d+)\x00/g, (_, idx) => protectedSlots[Number(idx)] ?? _);
|
|
581
593
|
}
|
|
582
594
|
if (!React.isValidElement(node)) return node;
|
|
583
595
|
const el = node as React.ReactElement<any>;
|
|
584
596
|
const children = el.props.children;
|
|
585
597
|
if (!children) return node;
|
|
586
598
|
const restored = React.Children.map(children, (child: any) => {
|
|
587
|
-
if (typeof child === 'string') return
|
|
588
|
-
if (React.isValidElement(child)) return
|
|
599
|
+
if (typeof child === 'string') return restoreProtected(child);
|
|
600
|
+
if (React.isValidElement(child)) return restoreProtected(child as JSX.Element);
|
|
589
601
|
return child;
|
|
590
602
|
});
|
|
591
603
|
return React.cloneElement(el, {}, ...(restored || []));
|
|
@@ -602,16 +614,16 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
602
614
|
const match = this.findNextFormat(remaining);
|
|
603
615
|
if (match) {
|
|
604
616
|
if (match.startIndex > 0) {
|
|
605
|
-
elements.push(
|
|
617
|
+
elements.push(restoreProtected(remaining.substring(0, match.startIndex)) as string);
|
|
606
618
|
}
|
|
607
|
-
// Restore mentions in matched content before recursive parsing
|
|
619
|
+
// Restore mentions/URLs in matched content before recursive parsing
|
|
608
620
|
const restoredContent = (typeof match.content === 'string' && match.content.indexOf('\x00') >= 0)
|
|
609
|
-
?
|
|
621
|
+
? restoreProtected(match.content) as string
|
|
610
622
|
: match.content;
|
|
611
623
|
if (match.type === "link" && match.url) {
|
|
612
624
|
// Render link as tappable blue underlined text (same as CometChatUrlsFormatter)
|
|
613
625
|
const innerContent = this.parseInlineFormats(restoredContent);
|
|
614
|
-
const linkUrl = match.url;
|
|
626
|
+
const linkUrl = restoreProtected(match.url) as string;
|
|
615
627
|
elements.push(
|
|
616
628
|
<Text
|
|
617
629
|
key={`fmt-${keyCounter++}`}
|
|
@@ -675,7 +687,7 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
675
687
|
}
|
|
676
688
|
remaining = remaining.substring(match.endIndex);
|
|
677
689
|
} else {
|
|
678
|
-
elements.push(
|
|
690
|
+
elements.push(restoreProtected(remaining) as string);
|
|
679
691
|
remaining = "";
|
|
680
692
|
}
|
|
681
693
|
}
|
|
@@ -214,6 +214,28 @@ export abstract class CometChatTextFormatter {
|
|
|
214
214
|
return inputText;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Rewrites the message's stored text before the UI Kit parses any of it.
|
|
219
|
+
*
|
|
220
|
+
* Runs on every surface a message appears on — bubble, conversation row, reply/edit preview,
|
|
221
|
+
* search result, media caption, message information — and on the text loaded back into the
|
|
222
|
+
* composer for editing, always BEFORE the built-in markdown, mention and link handling.
|
|
223
|
+
*
|
|
224
|
+
* This is where a formatter maps its own wire token onto markup the UI Kit already draws,
|
|
225
|
+
* e.g. `(#e5484d)red()` to `<color=#e5484d>red</color>`. `getFormattedText` cannot do that
|
|
226
|
+
* job: by then markdown has already turned the text into elements, so a pattern that spans
|
|
227
|
+
* any of that markup no longer matches.
|
|
228
|
+
*
|
|
229
|
+
* Returns the text untouched by default, so a formatter that does not override it behaves
|
|
230
|
+
* exactly as it did before this hook existed.
|
|
231
|
+
*
|
|
232
|
+
* @param text - The message text as stored on the server.
|
|
233
|
+
* @returns The text to render, written in the UI Kit's own grammar.
|
|
234
|
+
*/
|
|
235
|
+
formatRawText(text: string): string {
|
|
236
|
+
return text;
|
|
237
|
+
}
|
|
238
|
+
|
|
217
239
|
/**
|
|
218
240
|
* Handles the message before sending it.
|
|
219
241
|
* @param message - The message to handle.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CometChatTextFormatter } from "./CometChatTextFormatter";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runs every formatter's `formatRawText` over a message's stored text, in the order the
|
|
5
|
+
* consumer supplied them, before any built-in parsing sees it.
|
|
6
|
+
*
|
|
7
|
+
* Every surface that displays message text calls this first, so a consumer's own wire token
|
|
8
|
+
* renders the same way in a bubble, a conversation row, a preview, a search result and a
|
|
9
|
+
* caption — the guarantee the web and Android kits already give.
|
|
10
|
+
*
|
|
11
|
+
* A formatter that throws is skipped instead of taking the surface down with it: a bad regex
|
|
12
|
+
* in a consumer's formatter must never blank a conversation row.
|
|
13
|
+
*/
|
|
14
|
+
export function applyRawFormatters(
|
|
15
|
+
text: string,
|
|
16
|
+
formatters?: Array<CometChatTextFormatter>
|
|
17
|
+
): string {
|
|
18
|
+
if (!text || !formatters?.length) return text;
|
|
19
|
+
|
|
20
|
+
let formatted = text;
|
|
21
|
+
for (const formatter of formatters) {
|
|
22
|
+
try {
|
|
23
|
+
const next = formatter.formatRawText?.(formatted);
|
|
24
|
+
// A consumer writing JS can return anything; only a string is usable here.
|
|
25
|
+
if (typeof next === "string") formatted = next;
|
|
26
|
+
} catch {
|
|
27
|
+
// Keep the text as it was and let the remaining formatters run.
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return formatted;
|
|
31
|
+
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
CometChatUrlsFormatter,
|
|
8
8
|
CometChatRichTextFormatter,
|
|
9
9
|
} from "../..";
|
|
10
|
+
import { applyRawFormatters } from "../formatters/applyRawFormatters";
|
|
10
11
|
import { CometChatTheme } from "../../theme/type";
|
|
11
12
|
import {
|
|
12
13
|
AdditionalAttachmentOptionsParams,
|
|
@@ -189,7 +190,7 @@ export class MessageDataSource implements DataSource {
|
|
|
189
190
|
return <CometChatStreamMessageBubble key={message.getId() + message.getType()} message={message} theme={theme} />;
|
|
190
191
|
}
|
|
191
192
|
|
|
192
|
-
handleCopy = (message: CometChat.BaseMessage) => {
|
|
193
|
+
handleCopy = (message: CometChat.BaseMessage, textFormatters?: Array<CometChatTextFormatter>) => {
|
|
193
194
|
try {
|
|
194
195
|
let textToCopy = "";
|
|
195
196
|
|
|
@@ -206,7 +207,7 @@ export class MessageDataSource implements DataSource {
|
|
|
206
207
|
// Clean plain text for every other app; colour preserved in a private representation
|
|
207
208
|
// that only our own composer reads back on paste.
|
|
208
209
|
if (textToCopy?.trim()) {
|
|
209
|
-
ClipboardPasteHandler.copyMessageText(textToCopy);
|
|
210
|
+
ClipboardPasteHandler.copyMessageText(textToCopy, textFormatters);
|
|
210
211
|
}
|
|
211
212
|
} catch (err) {
|
|
212
213
|
console.error(err);
|
|
@@ -235,7 +236,7 @@ export class MessageDataSource implements DataSource {
|
|
|
235
236
|
options: undefined,
|
|
236
237
|
|
|
237
238
|
FooterView: (message: CometChat.BaseMessage) => (
|
|
238
|
-
<TouchableOpacity onPress={() => this.handleCopy(message as CometChat.AIAssistantMessage)}>
|
|
239
|
+
<TouchableOpacity onPress={() => this.handleCopy(message as CometChat.AIAssistantMessage, additionalParams?.textFormatters)}>
|
|
239
240
|
<Icon name="ai-copy-option" width={24} height={24} containerStyle={styles.aiCopyIcon} color={theme.color.textSecondary} />
|
|
240
241
|
</TouchableOpacity>
|
|
241
242
|
),
|
|
@@ -1531,6 +1532,7 @@ export class MessageDataSource implements DataSource {
|
|
|
1531
1532
|
<CometChatMessagePreview
|
|
1532
1533
|
message={hasQuotedMessage}
|
|
1533
1534
|
theme={replyTheme}
|
|
1535
|
+
textFormatters={additionalParams?.textFormatters}
|
|
1534
1536
|
style={{
|
|
1535
1537
|
backgroundColor: isOutgoingMessage ? theme.color.extendedPrimary800 : theme.color.neutral400,
|
|
1536
1538
|
borderRadius: 8,
|
|
@@ -1611,6 +1613,10 @@ export class MessageDataSource implements DataSource {
|
|
|
1611
1613
|
let loggedInUser = CometChatUIKit.loggedInUser;
|
|
1612
1614
|
let mentionedUsers = message.getMentionedUsers();
|
|
1613
1615
|
let textFormatters = [...(additionalParams?.textFormatters || [])];
|
|
1616
|
+
// A consumer's own wire token becomes UI Kit markup here, before markdown, mentions or
|
|
1617
|
+
// links parse the text — once the rich-text formatter has built elements out of it, a
|
|
1618
|
+
// pattern that spans any of that markup can no longer be matched.
|
|
1619
|
+
messageText = applyRawFormatters(messageText, textFormatters);
|
|
1614
1620
|
const isMessageSentByLoggedInUser = message.getSender()?.getUid() === loggedInUser?.getUid();
|
|
1615
1621
|
const _style: Partial<CometChatTheme["textBubbleStyles"]> = isMessageSentByLoggedInUser
|
|
1616
1622
|
? (theme.messageListStyles.outgoingMessageBubbleStyles
|
|
@@ -1932,12 +1938,12 @@ export class MessageDataSource implements DataSource {
|
|
|
1932
1938
|
const audioType = (message.getMetadata?.() as Record<string, any> | undefined)?.audioType;
|
|
1933
1939
|
if (audioType !== "voice_note") {
|
|
1934
1940
|
// shared/picked audio file(s) → headphone + filename cards
|
|
1935
|
-
return <CometChatAudiosBubble message={message} theme={theme} />;
|
|
1941
|
+
return <CometChatAudiosBubble message={message} theme={theme} additionalParams={additionalParams} />;
|
|
1936
1942
|
}
|
|
1937
1943
|
// DD §8.1a — recorded voice note → waveform: a STACK (2+) uses CometChatVoiceNoteBubble; a SINGLE
|
|
1938
1944
|
// recording (the usual case — voice notes are recorded one at a time) uses the single-audio bubble.
|
|
1939
1945
|
if (isGalleryMessage(message)) {
|
|
1940
|
-
return <CometChatVoiceNoteBubble message={message} theme={theme} />;
|
|
1946
|
+
return <CometChatVoiceNoteBubble message={message} theme={theme} additionalParams={additionalParams} />;
|
|
1941
1947
|
}
|
|
1942
1948
|
const attachment = message.getAttachment();
|
|
1943
1949
|
return ChatConfigurator.dataSource.getAudioMessageBubble(
|
|
@@ -1964,7 +1970,7 @@ export class MessageDataSource implements DataSource {
|
|
|
1964
1970
|
// A VIDEO message ALWAYS renders the video grid — no fallback to a file list. Any attachment that
|
|
1965
1971
|
// isn't a video (image / audio / file) shows a "no preview" placeholder cell inside the grid, and
|
|
1966
1972
|
// a "No preview available" fullscreen on tap (see CometChatVideosBubble + CometChatMediaViewer).
|
|
1967
|
-
return <CometChatVideosBubble message={message} theme={theme} />;
|
|
1973
|
+
return <CometChatVideosBubble message={message} theme={theme} additionalParams={additionalParams} />;
|
|
1968
1974
|
}
|
|
1969
1975
|
getImageMessageContentView(
|
|
1970
1976
|
message: CometChat.MediaMessage,
|
|
@@ -1983,7 +1989,7 @@ export class MessageDataSource implements DataSource {
|
|
|
1983
1989
|
// An IMAGE message ALWAYS renders the image grid — no fallback to a file list. Any attachment that
|
|
1984
1990
|
// can't be previewed (unsupported format / load error) shows a "no preview" placeholder cell inside
|
|
1985
1991
|
// the grid instead (see CometChatImagesBubble's ImageCell).
|
|
1986
|
-
return <CometChatImagesBubble message={message} theme={theme} />;
|
|
1992
|
+
return <CometChatImagesBubble message={message} theme={theme} additionalParams={additionalParams} />;
|
|
1987
1993
|
}
|
|
1988
1994
|
getFileMessageContentView(
|
|
1989
1995
|
message: CometChat.MediaMessage,
|
|
@@ -1999,7 +2005,7 @@ export class MessageDataSource implements DataSource {
|
|
|
1999
2005
|
);
|
|
2000
2006
|
}
|
|
2001
2007
|
// DD §9 (flag=true, default): the new FilesBubble renders 1..N — including a single file.
|
|
2002
|
-
return <CometChatFilesBubble message={message} theme={theme} />;
|
|
2008
|
+
return <CometChatFilesBubble message={message} theme={theme} additionalParams={additionalParams} />;
|
|
2003
2009
|
}
|
|
2004
2010
|
|
|
2005
2011
|
getTextMessageTemplate(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode, useState, useEffect, useMemo, useCallback } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveDeviceLanguage, resolveLanguage, translate } from "./CometChatLocalizationHelper";
|
|
3
3
|
import { CometChatLocalizeContext } from "./CometChatLocalizeContext";
|
|
4
4
|
import { setGlobalLanguage } from './LocalizationManager';
|
|
5
5
|
import * as RNLocalize from 'react-native-localize';
|
|
@@ -17,13 +17,11 @@ interface CometChatI18nProviderProps {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const getDeviceLanguage = (): Language => {
|
|
20
|
+
const getDeviceLanguage = (customLanguages: string[] = []): Language => {
|
|
21
21
|
try {
|
|
22
22
|
const locales = RNLocalize.getLocales();
|
|
23
23
|
if (Array.isArray(locales) && locales.length > 0) {
|
|
24
|
-
|
|
25
|
-
console.log(locales[0], " device language detected");
|
|
26
|
-
return code;
|
|
24
|
+
return resolveDeviceLanguage(locales[0], customLanguages);
|
|
27
25
|
}
|
|
28
26
|
} catch (error) {
|
|
29
27
|
console.warn('Error getting device language:', error);
|
|
@@ -32,7 +30,6 @@ const getDeviceLanguage = (): Language => {
|
|
|
32
30
|
};
|
|
33
31
|
|
|
34
32
|
|
|
35
|
-
|
|
36
33
|
export const CometChatI18nProvider = ({
|
|
37
34
|
children,
|
|
38
35
|
selectedLanguage,
|
|
@@ -41,44 +38,32 @@ export const CometChatI18nProvider = ({
|
|
|
41
38
|
translations
|
|
42
39
|
}: CometChatI18nProviderProps) => {
|
|
43
40
|
const [language, setLanguage] = useState<Language>(() => {
|
|
41
|
+
const customLanguages = translations ? Object.keys(translations) : [];
|
|
44
42
|
if (selectedLanguage) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const allAvailableLanguages = [...availableLanguages, ...customLanguages];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (allAvailableLanguages.includes(selectedLanguage)) {
|
|
52
|
-
return selectedLanguage;
|
|
53
|
-
} else {
|
|
54
|
-
|
|
55
|
-
console.warn(`Language '${selectedLanguage}' not found. Using fallback: ${fallbackLanguage}`);
|
|
56
|
-
return fallbackLanguage;
|
|
43
|
+
const resolved = resolveLanguage([selectedLanguage], customLanguages);
|
|
44
|
+
if (resolved) {
|
|
45
|
+
return resolved;
|
|
57
46
|
}
|
|
47
|
+
console.warn(`Language '${selectedLanguage}' not found. Using fallback: ${fallbackLanguage}`);
|
|
48
|
+
return fallbackLanguage;
|
|
58
49
|
} else if (autoDetectLanguage) {
|
|
59
|
-
|
|
60
|
-
return getDeviceLanguage();
|
|
50
|
+
return getDeviceLanguage(customLanguages);
|
|
61
51
|
}
|
|
62
52
|
return fallbackLanguage;
|
|
63
53
|
});
|
|
64
54
|
|
|
65
55
|
useEffect(() => {
|
|
56
|
+
const customLanguages = translations ? Object.keys(translations) : [];
|
|
66
57
|
if (selectedLanguage) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const allAvailableLanguages = [...availableLanguages, ...customLanguages];
|
|
71
|
-
|
|
72
|
-
if (allAvailableLanguages.includes(selectedLanguage)) {
|
|
73
|
-
setLanguage(selectedLanguage);
|
|
74
|
-
console.log(selectedLanguage, " language set from props");
|
|
58
|
+
const resolved = resolveLanguage([selectedLanguage], customLanguages);
|
|
59
|
+
if (resolved) {
|
|
60
|
+
setLanguage(resolved);
|
|
75
61
|
} else {
|
|
76
62
|
console.warn(`Language '${selectedLanguage}' not found (set via prop). Using fallback: ${fallbackLanguage}`);
|
|
77
63
|
setLanguage(fallbackLanguage);
|
|
78
64
|
}
|
|
79
65
|
} else if (autoDetectLanguage) {
|
|
80
|
-
|
|
81
|
-
setLanguage(getDeviceLanguage());
|
|
66
|
+
setLanguage(getDeviceLanguage(customLanguages));
|
|
82
67
|
}
|
|
83
68
|
}, [selectedLanguage, autoDetectLanguage, fallbackLanguage, translations]);
|
|
84
69
|
|
|
@@ -56,36 +56,155 @@ export interface CustomTranslations {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Look a language up in a bundle map, ignoring case.
|
|
61
|
+
*
|
|
62
|
+
* The shipped keys are not consistently cased — `en-US`/`en-GB`/`en-IN` use an
|
|
63
|
+
* uppercase region while `zh-tw` is lowercase — and callers legitimately pass
|
|
64
|
+
* the BCP-47 spelling (`zh-TW`). Matching case-insensitively means both work.
|
|
65
|
+
*/
|
|
66
|
+
const bundleFor = (
|
|
67
|
+
map: { [languageCode: string]: { [key: string]: string } } | undefined,
|
|
68
|
+
language: Language
|
|
69
|
+
): { [key: string]: string } | undefined => {
|
|
70
|
+
if (!map || !language) {
|
|
71
|
+
return undefined;
|
|
68
72
|
}
|
|
73
|
+
if (map[language]) {
|
|
74
|
+
return map[language];
|
|
75
|
+
}
|
|
76
|
+
const match = Object.keys(map).find(
|
|
77
|
+
k => k.toLowerCase() === language.toLowerCase()
|
|
78
|
+
);
|
|
79
|
+
return match ? map[match] : undefined;
|
|
80
|
+
};
|
|
69
81
|
|
|
70
82
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Resolve a language to the key it should be served from.
|
|
85
|
+
*
|
|
86
|
+
* Candidates are tried in order and matched case-insensitively against the
|
|
87
|
+
* shipped languages plus any custom ones the host supplied. Returns the key as
|
|
88
|
+
* it is actually stored, so downstream lookups are exact.
|
|
89
|
+
*/
|
|
90
|
+
export const resolveLanguage = (
|
|
91
|
+
candidates: (string | undefined)[],
|
|
92
|
+
customLanguages: string[] = []
|
|
93
|
+
): Language | undefined => {
|
|
94
|
+
const keys = [...getAvailableLanguages() as string[], ...customLanguages];
|
|
95
|
+
for (const candidate of candidates) {
|
|
96
|
+
if (!candidate) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const match = keys.find(k => k.toLowerCase() === candidate.toLowerCase());
|
|
100
|
+
if (match) {
|
|
101
|
+
return match;
|
|
102
|
+
}
|
|
74
103
|
}
|
|
104
|
+
return undefined;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The languages to try for a lookup, most specific first: the language itself,
|
|
110
|
+
* then its base ("en-US" -> "en"). Region keys alias to their base bundle, so
|
|
111
|
+
* without the base step a host overriding `en` would stop being honoured the
|
|
112
|
+
* moment a device resolved to `en-US`.
|
|
113
|
+
*/
|
|
114
|
+
const languageChain = (language?: Language): Language[] => {
|
|
115
|
+
const chain: Language[] = [];
|
|
116
|
+
const add = (value?: string) => {
|
|
117
|
+
if (value && !chain.some(c => c.toLowerCase() === value.toLowerCase())) {
|
|
118
|
+
chain.push(value);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
add(language);
|
|
122
|
+
add(language?.split('-')[0]);
|
|
123
|
+
return chain;
|
|
124
|
+
};
|
|
75
125
|
|
|
76
126
|
|
|
77
|
-
|
|
78
|
-
|
|
127
|
+
/**
|
|
128
|
+
* The shape of a `react-native-localize` locale, narrowed to what matters here.
|
|
129
|
+
*/
|
|
130
|
+
export interface DeviceLocale {
|
|
131
|
+
languageCode?: string;
|
|
132
|
+
countryCode?: string;
|
|
133
|
+
languageTag?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Pick the bundle to serve for a device locale.
|
|
139
|
+
*
|
|
140
|
+
* Tried most specific first. `languageTag` can carry a script subtag -- iOS
|
|
141
|
+
* reports Taiwan as `zh-Hant-TW` -- which no shipped key has, so language+region
|
|
142
|
+
* is tried before the bare language. Without that step `zh-Hant-TW` collapses to
|
|
143
|
+
* `zh` and a Traditional Chinese device is served Simplified.
|
|
144
|
+
*/
|
|
145
|
+
export const resolveDeviceLanguage = (
|
|
146
|
+
locale?: DeviceLocale,
|
|
147
|
+
customLanguages: string[] = []
|
|
148
|
+
): Language => {
|
|
149
|
+
if (!locale) {
|
|
150
|
+
return 'en';
|
|
79
151
|
}
|
|
152
|
+
const { languageCode, countryCode, languageTag } = locale;
|
|
153
|
+
return resolveLanguage(
|
|
154
|
+
[
|
|
155
|
+
languageTag,
|
|
156
|
+
languageCode && countryCode ? `${languageCode}-${countryCode}` : undefined,
|
|
157
|
+
languageCode,
|
|
158
|
+
],
|
|
159
|
+
customLanguages
|
|
160
|
+
) ?? 'en';
|
|
161
|
+
};
|
|
80
162
|
|
|
81
163
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
164
|
+
export const translate = (
|
|
165
|
+
language: Language,
|
|
166
|
+
key: string,
|
|
167
|
+
customTranslations?: CustomTranslations,
|
|
168
|
+
fallbackLanguage: Language = 'en'
|
|
169
|
+
): string => {
|
|
170
|
+
|
|
171
|
+
const requested = languageChain(language);
|
|
172
|
+
const fallback = languageChain(fallbackLanguage).filter(
|
|
173
|
+
f => !requested.some(r => r.toLowerCase() === f.toLowerCase())
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const fromCustom = (languages: Language[]) => {
|
|
177
|
+
for (const lang of languages) {
|
|
178
|
+
const bundle = bundleFor(customTranslations, lang);
|
|
179
|
+
if (bundle?.[key]) {
|
|
180
|
+
return bundle[key];
|
|
181
|
+
}
|
|
86
182
|
}
|
|
87
|
-
|
|
183
|
+
return undefined;
|
|
184
|
+
};
|
|
88
185
|
|
|
186
|
+
const fromDefault = (languages: Language[]) => {
|
|
187
|
+
for (const lang of languages) {
|
|
188
|
+
const bundle = bundleFor(defaultTranslations as any, lang);
|
|
189
|
+
if (bundle && key in bundle) {
|
|
190
|
+
return bundle[key];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// A host override for the requested language always wins over the built-in
|
|
197
|
+
// bundle, but never over a built-in bundle for a *different* language --
|
|
198
|
+
// so an `en` override does not leak into a Chinese UI.
|
|
199
|
+
const resolved =
|
|
200
|
+
fromCustom(requested) ??
|
|
201
|
+
fromDefault(requested) ??
|
|
202
|
+
fromCustom(fallback) ??
|
|
203
|
+
fromDefault(fallback);
|
|
204
|
+
|
|
205
|
+
if (resolved !== undefined) {
|
|
206
|
+
return resolved;
|
|
207
|
+
}
|
|
89
208
|
|
|
90
209
|
console.warn(`Missing translation for key: ${key} in language: ${language} and fallback: ${fallbackLanguage}`);
|
|
91
210
|
return key;
|
|
@@ -540,5 +540,78 @@
|
|
|
540
540
|
"PREVIEW_PHOTOS_COUNT": "{count} Fotos",
|
|
541
541
|
"PREVIEW_VIDEOS_COUNT": "{count} Videos",
|
|
542
542
|
"PREVIEW_FILES_COUNT": "{count} Dateien",
|
|
543
|
-
"PREVIEW_AUDIOS_COUNT": "{count} Audios"
|
|
543
|
+
"PREVIEW_AUDIOS_COUNT": "{count} Audios",
|
|
544
|
+
"THREAD_SUBSCRIPTION_SUBSCRIBE": "Thread abonnieren",
|
|
545
|
+
"THREAD_SUBSCRIPTION_UNSUBSCRIBE": "Thread deabonnieren",
|
|
546
|
+
"THREAD_SUBSCRIPTION_SUBSCRIBED_TOAST": "Abonniert. Du wirst über neue Antworten in diesem Thread benachrichtigt.",
|
|
547
|
+
"THREAD_SUBSCRIPTION_UNSUBSCRIBED_TOAST": "Abo beendet. Benachrichtigungen sind aus, bis du antwortest oder erwähnt wirst.",
|
|
548
|
+
"THREAD_SUBSCRIPTION_SUBSCRIBED": "Abonniert",
|
|
549
|
+
"THREAD_SUBSCRIPTION_FAILED": "Aktualisierung fehlgeschlagen. Bitte versuche es erneut.",
|
|
550
|
+
"THREAD_UNAVAILABLE": "Du hast keinen Zugriff mehr auf diesen Thread.",
|
|
551
|
+
"PIN_MESSAGE": "Nachricht anheften",
|
|
552
|
+
"UNPIN_MESSAGE": "Nachricht loslösen",
|
|
553
|
+
"SAVE_MESSAGE": "Nachricht speichern",
|
|
554
|
+
"UNSAVE_MESSAGE": "Nachricht nicht mehr speichern",
|
|
555
|
+
"PIN_MESSAGE_TITLE": "Nachricht anheften",
|
|
556
|
+
"PIN_MESSAGE_CONFIRM": "Möchtest du diese Nachricht an diese Konversation anheften?",
|
|
557
|
+
"UNPIN_MESSAGE_TITLE": "Nachricht loslösen",
|
|
558
|
+
"UNPIN_MESSAGE_CONFIRM": "Möchtest du diese Nachricht von dieser Konversation loslösen?",
|
|
559
|
+
"SAVE_MESSAGE_TITLE": "Nachricht speichern",
|
|
560
|
+
"SAVE_MESSAGE_CONFIRM": "Möchtest du diese Nachricht speichern?",
|
|
561
|
+
"UNSAVE_MESSAGE_TITLE": "Nachricht nicht mehr speichern",
|
|
562
|
+
"UNSAVE_MESSAGE_CONFIRM": "Möchtest du diese Nachricht aus deinen gespeicherten Nachrichten entfernen?",
|
|
563
|
+
"PIN": "Anheften",
|
|
564
|
+
"UNPIN": "Loslösen",
|
|
565
|
+
"UNSAVE": "Nicht mehr speichern",
|
|
566
|
+
"MESSAGE_PINNED": "Nachricht angeheftet",
|
|
567
|
+
"MESSAGE_UNPINNED": "Nachricht losgelöst",
|
|
568
|
+
"MESSAGE_SAVED": "Nachricht gespeichert",
|
|
569
|
+
"MESSAGE_UNSAVED": "Nachricht nicht mehr gespeichert",
|
|
570
|
+
"PINNED": "Angeheftet",
|
|
571
|
+
"SAVED": "Gespeichert",
|
|
572
|
+
"SAVED_MESSAGES": "Gespeicherte Nachrichten",
|
|
573
|
+
"PINNED_MESSAGES": "Angeheftete Nachrichten",
|
|
574
|
+
"PIN_CONVERSATION": "Anheften",
|
|
575
|
+
"UNPIN_CONVERSATION": "Loslösen",
|
|
576
|
+
"CONVERSATION_PINNED": "Konversation angeheftet",
|
|
577
|
+
"CONVERSATION_UNPINNED": "Konversation losgelöst",
|
|
578
|
+
"PIN_CONVERSATION_LIMIT_REACHED": "Du kannst nur {limit} Chats anheften. Löse einen, um einen anderen anzuheften.",
|
|
579
|
+
"PIN_CONVERSATION_LIMIT_REACHED_NO_COUNT": "Du hast dein Limit für angeheftete Chats erreicht. Löse einen, um einen anderen anzuheften.",
|
|
580
|
+
"CONVERSATION_NOT_PINNABLE": "Diese Konversation kann noch nicht angeheftet werden.",
|
|
581
|
+
"UNPIN_CONVERSATION_TITLE": "Konversation loslösen",
|
|
582
|
+
"UNPIN_CONVERSATION_CONFIRM": "Möchtest du diese Konversation vom Anfang deiner Liste loslösen?",
|
|
583
|
+
"NO_SAVED_MESSAGES": "Noch keine gespeicherten Nachrichten",
|
|
584
|
+
"NO_SAVED_MESSAGES_SUBTITLE": "Speichere Nachrichten, um sie jederzeit griffbereit zu haben.",
|
|
585
|
+
"BACK": "Zurück",
|
|
586
|
+
"NO_PINNED_MESSAGES": "Noch keine angehefteten Nachrichten",
|
|
587
|
+
"NO_PINNED_MESSAGES_SUBTITLE": "Hefte wichtige Nachrichten an, damit du sie leicht wiederfindest.",
|
|
588
|
+
"PIN_LIMIT_REACHED": "Du kannst nur {limit} Nachrichten anheften. Löse eine, um eine andere anzuheften.",
|
|
589
|
+
"SAVE_LIMIT_REACHED": "Du kannst bis zu {limit} Nachrichten speichern.",
|
|
590
|
+
"PIN_LIMIT_REACHED_NO_COUNT": "Du hast dein Limit für angeheftete Nachrichten erreicht. Löse eine, um eine andere anzuheften.",
|
|
591
|
+
"SAVE_LIMIT_REACHED_NO_COUNT": "Du hast dein Limit für gespeicherte Nachrichten erreicht.",
|
|
592
|
+
"PIN_NOT_ALLOWED": "Du hast keine Berechtigung, hier Nachrichten anzuheften.",
|
|
593
|
+
"PIN_SAVE_MODERATION_PENDING": "Diese Nachricht wird noch geprüft. Versuche es gleich noch einmal.",
|
|
594
|
+
"PIN_SAVE_FEATURE_OFF": "Diese Funktion ist für diese App nicht verfügbar.",
|
|
595
|
+
"PIN_SAVE_GENERIC_ERROR": "Etwas ist schief gelaufen. Bitte versuchen Sie es erneut.",
|
|
596
|
+
"MESSAGE_NO_LONGER_AVAILABLE": "Diese Nachricht ist nicht mehr verfügbar.",
|
|
597
|
+
"SEARCH_PLACEHOLDER": "Suchen...",
|
|
598
|
+
"SEARCH_NO_RESULTS_TITLE": "Keine Ergebnisse",
|
|
599
|
+
"SEARCH_NO_RESULTS_SUBTITLE": "Beginne zu tippen, um nach Nachrichten und Konversationen zu suchen",
|
|
600
|
+
"SEARCH_NO_RESULTS_FOUND_TITLE": "Keine Ergebnisse gefunden",
|
|
601
|
+
"SEARCH_NO_RESULTS_FOUND_SUBTITLE": "Wir konnten keine Treffer finden. Bitte versuche ein anderes Suchwort.",
|
|
602
|
+
"SEARCH_ERROR_LOADING_CONVERSATIONS": "Fehler beim Laden der Konversationen",
|
|
603
|
+
"SEARCH_ERROR_LOADING_MESSAGES": "Fehler beim Laden der Nachrichten",
|
|
604
|
+
"SEARCH_TRY_AGAIN": "Bitte versuche es später erneut",
|
|
605
|
+
"SEARCH_SEE_MORE": "Mehr anzeigen",
|
|
606
|
+
"SEARCH_LOADING": "Wird geladen...",
|
|
607
|
+
"SEARCH_FILTER_UNREAD": "Ungelesen",
|
|
608
|
+
"SEARCH_FILTER_GROUPS": "Gruppen",
|
|
609
|
+
"SEARCH_FILTER_PHOTOS": "Fotos",
|
|
610
|
+
"SEARCH_FILTER_VIDEOS": "Videos",
|
|
611
|
+
"SEARCH_FILTER_LINKS": "Links",
|
|
612
|
+
"SEARCH_FILTER_DOCUMENTS": "Dokumente",
|
|
613
|
+
"SEARCH_FILTER_AUDIO": "Audio",
|
|
614
|
+
"SEARCH_FILTER_CONVERSATIONS": "Konversationen",
|
|
615
|
+
"SEARCH_FILTER_MESSAGES": "Nachrichten",
|
|
616
|
+
"SEARCH_NO_MESSAGES": "Keine Nachrichten"
|
|
544
617
|
}
|
|
@@ -455,7 +455,6 @@
|
|
|
455
455
|
"AI_AGENT_MESSAGE": "AI agent message",
|
|
456
456
|
"NO_USERS_FOUND": "No Users Found",
|
|
457
457
|
"USERS_EMPTY_STATE_MESSAGE": "We couldn’t find any users matching your search. Try adjusting your search.",
|
|
458
|
-
"SAVE": "Save",
|
|
459
458
|
"RETRY": "Retry",
|
|
460
459
|
"TAP_TO_START_CONVERSATION": "Tap to start conversation",
|
|
461
460
|
"TEXT_TRANSLATED": "Text Translated",
|