@cometchat/chat-uikit-react-native 5.6.0 → 5.7.0
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/CometChatKeyboardModule.kt +101 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
- package/android/src/main/java/com/reactnativecometchatuikit/KeyboardDirectionWatcher.kt +64 -0
- package/android/src/main/java/com/reactnativecometchatuikit/KeyboardLanguageDirection.kt +44 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +287 -49
- package/ios/CometChatKeyboardModule.m +9 -0
- package/ios/CometChatKeyboardModule.swift +71 -0
- package/ios/KeyboardLanguageDirection.swift +24 -0
- package/ios/RichTextEditorView.swift +253 -51
- package/ios/RichTextEditorViewManager.m +1 -0
- package/package.json +1 -1
- package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +41 -57
- package/src/CometChatAIAssistantChatHistory/Skeleton.tsx +4 -1
- package/src/CometChatAIAssistantChatHistory/style.ts +5 -2
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +21 -8
- package/src/CometChatCompactMessageComposer/styles.ts +7 -7
- package/src/CometChatConversations/CometChatConversations.tsx +36 -30
- package/src/CometChatConversations/Skeleton.tsx +4 -1
- package/src/CometChatConversations/style.ts +1 -1
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +35 -18
- package/src/CometChatGroupMembers/Skeleton.tsx +4 -1
- package/src/CometChatGroupMembers/style.ts +6 -4
- package/src/CometChatGroups/CometChatGroups.tsx +13 -6
- package/src/CometChatGroups/GroupsStyle.ts +1 -1
- package/src/CometChatGroups/Skeleton.tsx +4 -1
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +44 -30
- package/src/CometChatMessageComposer/styles.tsx +1 -1
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +22 -13
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +8 -1
- package/src/CometChatMessageInformation/Skeleton.tsx +4 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +97 -128
- package/src/CometChatMessageList/SwipeToReplyView.tsx +61 -0
- package/src/CometChatMessageList/style.ts +32 -32
- package/src/CometChatMessageList/swipeToReply.ts +25 -0
- package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +10 -3
- package/src/CometChatNotificationFeed/style.ts +1 -1
- package/src/CometChatNotificationFeed/utils.ts +17 -18
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +8 -1
- package/src/CometChatPinnedMessages/style.ts +5 -5
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +2 -0
- package/src/CometChatRichTextEditor/index.tsx +3 -0
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +14 -11
- package/src/CometChatSavedMessages/style.ts +3 -3
- package/src/CometChatSearch/CometChatSearch.tsx +38 -35
- package/src/CometChatSearch/Skeleton.tsx +4 -1
- package/src/CometChatSearch/searchLabels.ts +26 -0
- package/src/CometChatSearch/style.ts +7 -7
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +11 -7
- package/src/CometChatThreadHeader/Header.tsx +2 -2
- package/src/CometChatUsers/CometChatUsers.tsx +8 -1
- package/src/CometChatUsers/Skeleton.tsx +4 -1
- package/src/CometChatUsers/style.ts +1 -1
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +8 -1
- package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +16 -4
- package/src/calls/CometChatCallLogs/Skeleton.tsx +4 -1
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +11 -3
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +10 -2
- package/src/extensions/CollaborativeBubble/style.ts +4 -4
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +1 -1
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +1 -1
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +11 -6
- package/src/extensions/LinkPreview/style.ts +6 -6
- package/src/extensions/Polls/Header.tsx +1 -1
- package/src/extensions/Polls/Polls.tsx +25 -12
- package/src/extensions/Polls/PollsBubble.tsx +10 -6
- package/src/extensions/Polls/style.ts +4 -4
- package/src/extensions/Stickers/CometChatStickerKeyboard/CometChatStickerKeyboard.tsx +2 -2
- package/src/extensions/Stickers/CometChatStickerKeyboard/Skeleton.tsx +1 -1
- package/src/extensions/Stickers/CometChatStickerKeyboard/style.ts +1 -1
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -2
- package/src/index.ts +5 -1
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +17 -0
- package/src/shared/CometChatUiKit/UIKitSettings.ts +8 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +13 -10
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +15 -7
- package/src/shared/formatters/CometChatTextFormatter.ts +11 -0
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +7 -4
- package/src/shared/framework/MessageDataSource.tsx +17 -94
- package/src/shared/helper/LocalizedDateHelper.ts +64 -4
- package/src/shared/helper/helperFunctions.ts +71 -4
- package/src/shared/helper/keyboardDirection.ts +54 -0
- package/src/shared/helper/layoutDirection.ts +205 -0
- package/src/shared/helper/pluralRules.ts +67 -0
- package/src/shared/helper/textDirection.ts +118 -0
- package/src/shared/icons/Icon.tsx +37 -2
- package/src/shared/icons/components/format-list-numbered-rtl.tsx +15 -0
- package/src/shared/offline/OfflineViews.tsx +5 -1
- package/src/shared/offline/notices.ts +15 -21
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +2 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/ar/translation.json +720 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +51 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +51 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +58 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +66 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +50 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +50 -2
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +13 -12
- package/src/shared/utils/CometChatMessagePreview/style.ts +1 -1
- package/src/shared/utils/MessageUtils.tsx +14 -14
- package/src/shared/utils/PermissionUtil.ts +16 -5
- package/src/shared/utils/attachmentLimits.ts +3 -2
- package/src/shared/utils/conversationUtils.ts +3 -5
- package/src/shared/utils/fileIconFontSize.ts +10 -0
- package/src/shared/utils/fileSizeLabel.ts +16 -0
- package/src/shared/utils/groupActionText.ts +75 -0
- package/src/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.tsx +12 -8
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +1 -1
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +5 -3
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +22 -17
- package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +13 -9
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +16 -10
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +10 -6
- package/src/shared/views/CometChatBadge/CometChatBadge.tsx +8 -4
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +6 -2
- package/src/shared/views/CometChatComposerErrorBanner.tsx +3 -1
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +8 -3
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +2 -2
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +5 -3
- package/src/shared/views/CometChatEmojiKeyboard/emojis.ts +8 -8
- package/src/shared/views/CometChatEmojiKeyboard/style.ts +2 -2
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +5 -4
- package/src/shared/views/CometChatImageViewerModal/ImageViewerModal.tsx +7 -3
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +29 -23
- package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +41 -21
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +7 -3
- package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +7 -3
- package/src/shared/views/CometChatList/CometChatList.tsx +10 -14
- package/src/shared/views/CometChatList/Header.tsx +5 -2
- package/src/shared/views/CometChatList/sectionLetter.ts +44 -0
- package/src/shared/views/CometChatList/styles.ts +7 -7
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +6 -4
- package/src/shared/views/CometChatMediaRecorder/CometChatAudioPlayer.tsx +16 -10
- package/src/shared/views/CometChatMediaRecorder/Timer.tsx +5 -1
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +16 -11
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +24 -4
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +18 -2
- package/src/shared/views/CometChatNewMessageIndicator/CometChatNewMessageIndicator.tsx +3 -2
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +3 -2
- package/src/shared/views/CometChatReactionList/ReactionListStyle.tsx +2 -2
- package/src/shared/views/CometChatReactionList/Skeleton.tsx +4 -1
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +6 -2
- package/src/shared/views/CometChatReportDialog/CometChatReportDialog.tsx +7 -3
- package/src/shared/views/CometChatReportDialog/style.ts +1 -1
- package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +1 -1
- package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +20 -13
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +3 -2
- package/src/shared/views/CometChatSuggestionList/Skeleton.tsx +1 -1
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +29 -3
- package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +20 -30
- package/src/shared/views/CometChatTooltipMenu/tooltipPosition.ts +43 -0
- package/src/shared/views/CometChatVideoBubble/style.ts +2 -2
- package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +4 -1
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +22 -22
- package/src/shared/views/SenderLabel.tsx +41 -0
- package/src/theme/default/default.ts +1 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { createContext, isValidElement, useContext, useMemo, useRef, useState, type ComponentRef, type ReactNode } from "react";
|
|
2
|
+
import { I18nManager, Platform, type LayoutChangeEvent, type ScrollView } from "react-native";
|
|
3
|
+
import { messageDirection } from "./textDirection";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The kit's direction setting (ENG-41333, names locked by F2 / ENG-41244).
|
|
7
|
+
* Global: `'auto'` (default, follow the app) | `'ltr'` | `'rtl'`. A component prop takes only
|
|
8
|
+
* `'ltr'` | `'rtl'`; not set = inherit.
|
|
9
|
+
*/
|
|
10
|
+
export type CometChatLayoutDirection = "auto" | "ltr" | "rtl";
|
|
11
|
+
type Direction = "ltr" | "rtl";
|
|
12
|
+
|
|
13
|
+
const asDirection = (value?: string): Direction | undefined =>
|
|
14
|
+
value === "ltr" || value === "rtl" ? value : undefined;
|
|
15
|
+
|
|
16
|
+
let globalDirection: CometChatLayoutDirection = "auto";
|
|
17
|
+
|
|
18
|
+
/** Set by `CometChatUIKit.init({ layoutDirection })` and `CometChatUIKit.setLayoutDirection()`. */
|
|
19
|
+
export function setGlobalLayoutDirection(value?: CometChatLayoutDirection): void {
|
|
20
|
+
globalDirection = asDirection(value) ?? "auto";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getGlobalLayoutDirection(): CometChatLayoutDirection {
|
|
24
|
+
return globalDirection;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The nearest kit component's direction. `undefined` = nothing set above (global `'auto'`). */
|
|
28
|
+
export const LayoutDirectionContext = createContext<Direction | undefined>(undefined);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* §4.1 resolution after the media rule (players pin LTR themselves, see PLAYER_DIRECTION):
|
|
32
|
+
* own setting → nearest enclosing component → global `'ltr'`/`'rtl'`. `undefined` means leave
|
|
33
|
+
* `direction` unset so Yoga inherits the app's direction (global `'auto'`, today's behaviour).
|
|
34
|
+
*/
|
|
35
|
+
export function resolveLayoutDirection(
|
|
36
|
+
own: string | undefined,
|
|
37
|
+
enclosing: Direction | undefined,
|
|
38
|
+
global: CometChatLayoutDirection
|
|
39
|
+
): Direction | undefined {
|
|
40
|
+
return asDirection(own) ?? enclosing ?? asDirection(global);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* For a public component's root and for overlays (Modal content starts a new native root, but
|
|
45
|
+
* React context still reaches it). The global value is read once, when the component is created
|
|
46
|
+
* (F2 decision 3: the runtime setter applies to components created afterwards).
|
|
47
|
+
*/
|
|
48
|
+
export function useComponentLayoutDirection(own?: string): Direction | undefined {
|
|
49
|
+
const enclosing = useContext(LayoutDirectionContext);
|
|
50
|
+
const [global] = useState(getGlobalLayoutDirection);
|
|
51
|
+
return resolveLayoutDirection(own, enclosing, global);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Style for a component root or overlay content; nothing when the direction is inherited. */
|
|
55
|
+
export const directionStyle = (direction?: Direction) =>
|
|
56
|
+
direction ? { direction } : undefined;
|
|
57
|
+
|
|
58
|
+
const appOrGlobal = (): Direction =>
|
|
59
|
+
asDirection(globalDirection) ?? (I18nManager.isRTL ? "rtl" : "ltr");
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Public (F2 decision 5): the direction kit content around the caller lays out in, for an
|
|
63
|
+
* integrator's own views in slots. Read it instead of `I18nManager.isRTL`.
|
|
64
|
+
*/
|
|
65
|
+
export function useCometChatLayoutDirection(): Direction {
|
|
66
|
+
return useContext(LayoutDirectionContext) ?? appOrGlobal();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Internal (F2 decision 7): icon mirroring, tooltip placement, swipe-to-reply. */
|
|
70
|
+
export function useKitRTL(): boolean {
|
|
71
|
+
return useCometChatLayoutDirection() === "rtl";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* ENG-41382: UI text (names, subtitles, titles, labels) starts at the layout's start edge in any
|
|
76
|
+
* script. iOS natural alignment follows the string's first letter ("John" left in an RTL list);
|
|
77
|
+
* React Native resolves `textAlign: "left"` against the Yoga direction, i.e. the start edge.
|
|
78
|
+
* Android text already follows the layout. Not for message bodies: they align by their own
|
|
79
|
+
* language (messageDirection). Put it first so a caller's own textAlign still wins.
|
|
80
|
+
*/
|
|
81
|
+
export const TEXT_START = Platform.OS === "ios" ? ({ textAlign: "left" } as const) : undefined;
|
|
82
|
+
|
|
83
|
+
const INPUT_LEFT = { textAlign: "left" } as const;
|
|
84
|
+
const INPUT_RIGHT = { textAlign: "right" } as const;
|
|
85
|
+
/**
|
|
86
|
+
* ENG-41384: typed text and placeholder start at the kit's start edge. TextInput ignores Yoga
|
|
87
|
+
* `direction` on both platforms and treats textAlign as absolute (Android maps it straight to
|
|
88
|
+
* Gravity.LEFT/RIGHT; iOS TextInput carries no layout direction), so the side is spelled out.
|
|
89
|
+
* Put it first so a caller's own textAlign still wins.
|
|
90
|
+
*/
|
|
91
|
+
export function useInputTextAlign() {
|
|
92
|
+
return useKitRTL() ? INPUT_RIGHT : INPUT_LEFT;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const NATURAL: { textAlign?: "left" | "right" } = {};
|
|
96
|
+
|
|
97
|
+
/** The text a formatted node shows: its strings, in order (mention chips included). */
|
|
98
|
+
function textContent(node: ReactNode): string {
|
|
99
|
+
if (typeof node === "string" || typeof node === "number") return String(node);
|
|
100
|
+
if (Array.isArray(node)) return node.map(textContent).join("");
|
|
101
|
+
if (isValidElement<{ children?: ReactNode }>(node)) return textContent(node.props.children);
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* ENG-57281: whether the composer's text has a letter yet. Pass the raw input string where there is
|
|
107
|
+
* one: the standard composer's formatters turn ANY non-empty input into an element, digits and emoji
|
|
108
|
+
* too. For an element, its shown text is read instead.
|
|
109
|
+
*/
|
|
110
|
+
export function composerHasLetters(text: ReactNode): boolean {
|
|
111
|
+
return messageDirection(typeof text === "string" ? text : textContent(text)) !== null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* ENG-57281: the composer's typed text aligns by its own language, like a message bubble: English
|
|
116
|
+
* starts on the left in an RTL screen, Arabic on the right in an LTR one. A TextInput takes one
|
|
117
|
+
* textAlign for all its lines, so with letters the alignment is left unset (natural): each line then
|
|
118
|
+
* follows its own first strong letter on iOS and Android. With no letter yet, the caret goes on the
|
|
119
|
+
* side of the keyboard's language (`keyboard`, see useKeyboardDirection): an English keyboard starts
|
|
120
|
+
* at the left of an RTL screen. No keyboard language, the kit's start edge (ENG-41384). A TextInput
|
|
121
|
+
* draws its placeholder with the same textAlign, so while focused it moves with the caret.
|
|
122
|
+
* `hasLetters`: composerHasLetters() of the raw input, computed once by the caller.
|
|
123
|
+
*/
|
|
124
|
+
export function useComposerTextAlign(
|
|
125
|
+
hasLetters: boolean,
|
|
126
|
+
keyboard?: Direction
|
|
127
|
+
): { textAlign?: "left" | "right" } {
|
|
128
|
+
const start = useInputTextAlign();
|
|
129
|
+
if (hasLetters) return NATURAL;
|
|
130
|
+
return keyboard === "rtl" ? INPUT_RIGHT : keyboard === "ltr" ? INPUT_LEFT : start;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* ENG-41390: for drawings with fixed x positions (SVG loading skeletons). Flex layouts mirror by
|
|
135
|
+
* themselves; an SVG doesn't, so it is flipped as a whole in RTL.
|
|
136
|
+
*/
|
|
137
|
+
const MIRROR_X = { transform: [{ scaleX: -1 }] } as const;
|
|
138
|
+
export function useRtlMirror() {
|
|
139
|
+
return useKitRTL() ? MIRROR_X : undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* ENG-41316: audio and video players read left to right in every language — play at the left, the
|
|
144
|
+
* waveform or seek bar filling from the left (design: Audio Bubble, Media Recorder, RTL). The one
|
|
145
|
+
* place the kit pins a direction; everything else follows the layout.
|
|
146
|
+
*/
|
|
147
|
+
export const PLAYER_DIRECTION = { direction: "ltr" } as const;
|
|
148
|
+
/** Player times (elapsed/total) align under the player's left end; iOS text ignores `direction`. */
|
|
149
|
+
export const PLAYER_TIME_ALIGN = { textAlign: "left", writingDirection: "ltr" } as const;
|
|
150
|
+
/**
|
|
151
|
+
* ENG-41314: code reads left to right in every language (as on Android and Flutter). For a code
|
|
152
|
+
* block's Text, before any integrator style: `textAlign: "left"` resolves against the node's own
|
|
153
|
+
* direction (see ownLanguageTextStyle), and iOS text ignores `direction`, hence writingDirection.
|
|
154
|
+
*/
|
|
155
|
+
export const CODE_DIRECTION = { direction: "ltr", writingDirection: "ltr", textAlign: "left" } as const;
|
|
156
|
+
|
|
157
|
+
type ScrollViewRef = ComponentRef<typeof ScrollView>;
|
|
158
|
+
type ScrollStartProps = {
|
|
159
|
+
ref?: (view: ScrollViewRef | null) => void;
|
|
160
|
+
onLayout?: (e: LayoutChangeEvent) => void;
|
|
161
|
+
onContentSizeChange?: (width: number, height: number) => void;
|
|
162
|
+
onScrollBeginDrag?: (e: unknown) => void;
|
|
163
|
+
};
|
|
164
|
+
const NO_SCROLL_START: ScrollStartProps = {};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* ENG-41342: a horizontal ScrollView opens at its start edge in RTL on iOS. RN iOS mirrors an RTL
|
|
168
|
+
* ScrollView with scaleX(-1) on the UIScrollView and on its zoom view; when the native view is
|
|
169
|
+
* recycled (a remount, e.g. the Messages screen's composer key), prepareForRecycle sets zoomScale 1
|
|
170
|
+
* after resetting the offset, UIKit reads the mirrored zoom view as zoom -1 and moves the offset to
|
|
171
|
+
* the END, and reuse keeps it. So until the user drags, scroll back to the start whenever either
|
|
172
|
+
* width changes. RN takes an RTL scrollTo x as contentWidth - width - x natively, so the start is
|
|
173
|
+
* x = contentWidth - width. The state lives as long as one ScrollView: a new one (the toolbar
|
|
174
|
+
* remounted after the voice recorder) starts undragged and unmeasured. Spread the result on the
|
|
175
|
+
* ScrollView; LTR and Android get nothing.
|
|
176
|
+
*/
|
|
177
|
+
export function useIosRtlScrollStart(direction?: Direction): ScrollStartProps {
|
|
178
|
+
const rtl = (direction ?? (I18nManager.isRTL ? "rtl" : "ltr")) === "rtl";
|
|
179
|
+
const active = Platform.OS === "ios" && rtl;
|
|
180
|
+
const size = useRef({ view: null as ScrollViewRef | null, content: 0, viewport: 0, dragged: false });
|
|
181
|
+
return useMemo(() => {
|
|
182
|
+
if (!active) return NO_SCROLL_START;
|
|
183
|
+
const toStart = () => {
|
|
184
|
+
const { content, viewport, dragged } = size.current;
|
|
185
|
+
if (dragged || !viewport || content <= viewport) return;
|
|
186
|
+
size.current.view?.scrollTo({ x: content - viewport, animated: false });
|
|
187
|
+
};
|
|
188
|
+
return {
|
|
189
|
+
ref: (view) => {
|
|
190
|
+
if (view !== size.current.view) size.current = { view, content: 0, viewport: 0, dragged: false };
|
|
191
|
+
},
|
|
192
|
+
onLayout: (e) => {
|
|
193
|
+
size.current.viewport = e.nativeEvent.layout.width;
|
|
194
|
+
toStart();
|
|
195
|
+
},
|
|
196
|
+
onContentSizeChange: (width) => {
|
|
197
|
+
size.current.content = width;
|
|
198
|
+
toStart();
|
|
199
|
+
},
|
|
200
|
+
onScrollBeginDrag: () => {
|
|
201
|
+
size.current.dragged = true;
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}, [active]);
|
|
205
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Language } from "../resources/CometChatLocalizeNew/type";
|
|
2
|
+
import { getCurrentLanguage } from "../resources/CometChatLocalizeNew/LocalizationManager";
|
|
3
|
+
import { localizeDigits } from "./LocalizedDateHelper";
|
|
4
|
+
|
|
5
|
+
export type PluralCategory = "zero" | "one" | "two" | "few" | "many" | "other";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* CLDR cardinal plural category of a whole count below a million in the kit language.
|
|
9
|
+
* Hermes has no Intl.PluralRules, so the rules are written out for the shipped languages;
|
|
10
|
+
* any other language gets one / other.
|
|
11
|
+
*/
|
|
12
|
+
export function pluralCategory(count: number, language: Language): PluralCategory {
|
|
13
|
+
const n = Math.abs(Math.trunc(count));
|
|
14
|
+
const n10 = n % 10;
|
|
15
|
+
const n100 = n % 100;
|
|
16
|
+
switch (language.split("-")[0].toLowerCase()) {
|
|
17
|
+
case "ar":
|
|
18
|
+
if (n === 0) return "zero";
|
|
19
|
+
if (n === 1) return "one";
|
|
20
|
+
if (n === 2) return "two";
|
|
21
|
+
if (n100 >= 3 && n100 <= 10) return "few";
|
|
22
|
+
if (n100 >= 11) return "many";
|
|
23
|
+
return "other";
|
|
24
|
+
case "ru":
|
|
25
|
+
if (n10 === 1 && n100 !== 11) return "one";
|
|
26
|
+
if (n10 >= 2 && n10 <= 4 && (n100 < 12 || n100 > 14)) return "few";
|
|
27
|
+
return "many";
|
|
28
|
+
case "lt":
|
|
29
|
+
if (n100 >= 11 && n100 <= 19) return "other";
|
|
30
|
+
if (n10 === 1) return "one";
|
|
31
|
+
if (n10 >= 2) return "few";
|
|
32
|
+
return "other";
|
|
33
|
+
case "fr":
|
|
34
|
+
case "hi":
|
|
35
|
+
case "pt":
|
|
36
|
+
return n <= 1 ? "one" : "other";
|
|
37
|
+
case "ja":
|
|
38
|
+
case "ko":
|
|
39
|
+
case "ms":
|
|
40
|
+
case "zh":
|
|
41
|
+
return "other";
|
|
42
|
+
default:
|
|
43
|
+
return n === 1 ? "one" : "other";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* "{count} …" from the translation key `<key>_<CATEGORY>` (e.g. SEARCH_FILE_COUNT_FEW), with the
|
|
49
|
+
* count in that language's digits. Every bundle has `_ONE` and `_OTHER`; a language whose rule
|
|
50
|
+
* uses more categories (ar, ru, lt) also has those forms. Pass the language `t` translates into
|
|
51
|
+
* (useCometChatTranslation's `language`): CometChatI18nProvider swaps `t` during render but sets
|
|
52
|
+
* the global language in an effect, so the default can still be the previous language. A form the
|
|
53
|
+
* bundle lacks (t returns the key) falls back to `_OTHER`, never a raw key.
|
|
54
|
+
*/
|
|
55
|
+
export function pluralCountLabel(
|
|
56
|
+
t: (key: string) => string,
|
|
57
|
+
key: string,
|
|
58
|
+
count: number,
|
|
59
|
+
language: Language = getCurrentLanguage()
|
|
60
|
+
): string {
|
|
61
|
+
const formKey = `${key}_${pluralCategory(count, language).toUpperCase()}`;
|
|
62
|
+
const form = t(formKey);
|
|
63
|
+
return (form === formKey ? t(`${key}_OTHER`) : form).replace(
|
|
64
|
+
/\{count\}/g,
|
|
65
|
+
localizeDigits(String(count), language)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { COLOR_CLOSE_TAG, COLOR_OPEN_TAG, HEX_COLOR_REGEX } from "../formatters/richTextWireFormat";
|
|
2
|
+
|
|
3
|
+
// ENG-41314: direction of a piece of user text, by its first strong character (what HTML's
|
|
4
|
+
// dir="auto" does). Used so a message aligns by its own language, not the chat's direction.
|
|
5
|
+
|
|
6
|
+
// Hebrew, Arabic, Syriac, Thaana, NKo, Samaritan, Mandaic, Arabic Extended, and the
|
|
7
|
+
// Hebrew/Arabic presentation forms.
|
|
8
|
+
// Arabic-Indic digits (U+0660-0669, U+06F0-06F9) and U+FEFF are bidi-weak, not strong RTL: left out.
|
|
9
|
+
const RTL_CHAR = /[\u0590-\u065F\u066A-\u06EF\u06FA-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFE]/;
|
|
10
|
+
// Any letter in another script counts as a strong left-to-right character.
|
|
11
|
+
const STRONG_CHAR = /\p{L}/u;
|
|
12
|
+
// hasVisibleDigit: a 0-9 the reader sees. A keycap emoji ("1️⃣", "#️⃣") is an emoji, not a digit.
|
|
13
|
+
const KEYCAP = /[0-9#*]\uFE0F?\u20E3/g;
|
|
14
|
+
const DIGIT = /[0-9]/;
|
|
15
|
+
|
|
16
|
+
// ENG-41314 part 2: wrap a name, file name or number before dropping it into a translated
|
|
17
|
+
// sentence, so it keeps its own direction and can't reorder the words around it
|
|
18
|
+
// (FSI U+2068 … PDI U+2069, invisible).
|
|
19
|
+
const FSI = "\u2068";
|
|
20
|
+
const PDI = "\u2069";
|
|
21
|
+
// Bidi controls a display name must not carry into a sentence: an embedded PDI would close our
|
|
22
|
+
// isolate early, an override (RLO U+202E) would reverse the words after it — a spoofing vector.
|
|
23
|
+
const BIDI_CONTROLS = /[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g;
|
|
24
|
+
/**
|
|
25
|
+
* ENG-41456: a display name drawn on its own (list titles, headers, sender names) must not carry
|
|
26
|
+
* bidi controls either — an override (RLO) reverses the text after it, so "Eve" + RLO + "evil"
|
|
27
|
+
* renders as "Evelive" ("Trojan Source"). Strips them; no isolates added (LRI/FSI around a
|
|
28
|
+
* standalone iOS title truncated it before, see pinLtr).
|
|
29
|
+
*/
|
|
30
|
+
export function stripBidiControls(text?: string | null): string {
|
|
31
|
+
return (text || "").replace(BIDI_CONTROLS, "");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isolateText(text: string): string {
|
|
35
|
+
const clean = stripBidiControls(text);
|
|
36
|
+
return clean ? FSI + clean + PDI : "";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ENG-41314: URLs, emails and code are left-to-right whatever the message language. Inside an
|
|
40
|
+
// Arabic message the bidi algorithm otherwise moves their edge punctuation: "/https://x.com/docs"
|
|
41
|
+
// and ";()x = foo" (seen on iOS and Android). A left-to-right mark (LRM U+200E) on each side
|
|
42
|
+
// pins the edges. Not LRI…PDI: in a forced-RTL iOS bubble that truncated the text to one line
|
|
43
|
+
// ("user…"), seen on device and gone with the isolates removed (A/B).
|
|
44
|
+
export const LRM = "\u200E";
|
|
45
|
+
export function pinLtr(text: string): string {
|
|
46
|
+
if (!text || (text.startsWith(LRM) && text.endsWith(LRM))) return text;
|
|
47
|
+
return LRM + text + LRM;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ENG-41314: a sentence built from a translated template takes the template's direction, not the
|
|
51
|
+
// direction of an isolated name at its start. iOS let the name decide: "joined the group أحمد علي"
|
|
52
|
+
// in an English UI (Android skipped the isolate correctly). LRM/RLM in front sets it explicitly.
|
|
53
|
+
const RLM = "\u200F";
|
|
54
|
+
export function withSentenceDirection(sentence: string): string {
|
|
55
|
+
const dir = firstStrongDirection(sentence);
|
|
56
|
+
return dir === "rtl" ? RLM + sentence : dir === "ltr" ? LRM + sentence : sentence;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Fills `${key}` placeholders with isolated names and gives the sentence the template's own
|
|
61
|
+
* direction — the one call every name-in-a-sentence site needs (ENG-41314).
|
|
62
|
+
*/
|
|
63
|
+
export function sentenceWithNames(template: string, names: Record<string, string>): string {
|
|
64
|
+
// One pass: a name that literally contains "${onName}" is never expanded again.
|
|
65
|
+
const out = template.replace(/\$\{(\w+)\}/g, (match, key: string) =>
|
|
66
|
+
Object.prototype.hasOwnProperty.call(names, key) ? isolateText(names[key]) : match
|
|
67
|
+
);
|
|
68
|
+
return withSentenceDirection(out);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Unicode bidi P2/P3: LRM is a strong LTR character, RLM and ALM strong RTL, and anything inside
|
|
72
|
+
// an isolate (LRI/RLI/FSI … PDI) is skipped — so the result agrees with withSentenceDirection().
|
|
73
|
+
const LRI = "\u2066";
|
|
74
|
+
const RLI = "\u2067";
|
|
75
|
+
export function firstStrongDirection(text: string): "ltr" | "rtl" | null {
|
|
76
|
+
let depth = 0;
|
|
77
|
+
for (const ch of text) {
|
|
78
|
+
if (ch === LRI || ch === RLI || ch === FSI) { depth++; continue; }
|
|
79
|
+
if (ch === PDI) { if (depth > 0) depth--; continue; }
|
|
80
|
+
if (depth > 0) continue;
|
|
81
|
+
if (ch === LRM) return "ltr";
|
|
82
|
+
if (ch === RLM || ch === "\u061C") return "rtl";
|
|
83
|
+
if (RTL_CHAR.test(ch)) return "rtl";
|
|
84
|
+
if (STRONG_CHAR.test(ch)) return "ltr";
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Wire markup the reader never sees: mention tokens (<@uid:x>, <@all:x>) and colour tags
|
|
90
|
+
// (<color=#hex>…</color>). Read raw, "<@uid:" made a message starting with a mention LTR.
|
|
91
|
+
// The colour tag comes from the wire format, so it matches exactly what the rich-text formatter draws.
|
|
92
|
+
// ponytail: the tags ("<color=", "</color>") hold no regex metacharacters, so they go in unescaped.
|
|
93
|
+
const HIDDEN_MARKUP = new RegExp(
|
|
94
|
+
"<@(?:uid|all):[^>]*>|" +
|
|
95
|
+
COLOR_OPEN_TAG + HEX_COLOR_REGEX.source.replace(/^\^|\$$/g, "") + ">|" +
|
|
96
|
+
COLOR_CLOSE_TAG,
|
|
97
|
+
"gi"
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
/** Direction of a message by its first strong character, ignoring markup the reader never sees. */
|
|
101
|
+
export function messageDirection(text: string): "ltr" | "rtl" | null {
|
|
102
|
+
return firstStrongDirection(text.replace(HIDDEN_MARKUP, ""));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Whether the reader sees a 0-9 digit (a mention's uid, a colour tag's hex or a keycap emoji does not count). */
|
|
106
|
+
export function hasVisibleDigit(text: string): boolean {
|
|
107
|
+
return DIGIT.test(text.replace(HIDDEN_MARKUP, "").replace(KEYCAP, ""));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* ENG-41385: style that aligns a piece of user text (a link preview's title or description) by
|
|
112
|
+
* its own language. `direction` on the Text node makes `textAlign: "left"` its own start edge:
|
|
113
|
+
* React Native resolves "left" against the node's Yoga direction. Nothing for text without letters.
|
|
114
|
+
*/
|
|
115
|
+
export function ownLanguageTextStyle(text?: string | null) {
|
|
116
|
+
const dir = messageDirection(text ?? "");
|
|
117
|
+
return dir ? ({ direction: dir, writingDirection: dir, textAlign: "left" } as const) : undefined;
|
|
118
|
+
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
ColorValue,
|
|
4
4
|
DimensionValue,
|
|
5
5
|
Image,
|
|
6
|
+
Platform,
|
|
6
7
|
ImageSourcePropType,
|
|
7
8
|
ImageStyle,
|
|
8
9
|
StyleProp,
|
|
@@ -11,9 +12,38 @@ import {
|
|
|
11
12
|
} from "react-native";
|
|
12
13
|
import { useTheme } from "../../theme";
|
|
13
14
|
import { ICONS } from "./icon-mapping";
|
|
15
|
+
import FormatListNumberedRtl from "./components/format-list-numbered-rtl";
|
|
16
|
+
import { useKitRTL } from "../helper/layoutDirection";
|
|
14
17
|
|
|
15
18
|
export type IconName = keyof typeof ICONS;
|
|
16
19
|
|
|
20
|
+
// ENG-41312: directional icons flip horizontally in RTL (design: Storybook RTL, measured
|
|
21
|
+
// scaleX(-1); per-OS column from decision D-RTL-1). Names are matched without "-fill".
|
|
22
|
+
const MIRROR_ALWAYS = new Set([
|
|
23
|
+
"arrow-back", "arrow-forward", "chevron-left", "chevron-right",
|
|
24
|
+
"send", "ai-send-button", "reply", "reply-all", "forward",
|
|
25
|
+
"subdirectory-arrow-right", "subdirectory-arrow-left", "right-arrow",
|
|
26
|
+
"call-made", "call-received", "call-missed", "call-missed-outgoing",
|
|
27
|
+
"phone-incoming", "phone-outgoing", "phone-missed",
|
|
28
|
+
"incoming-audio", "outgoing-audio", "incoming-video", "outgoing-video", "missed-video-call",
|
|
29
|
+
"format-list-bulleted", "logout",
|
|
30
|
+
]);
|
|
31
|
+
// Android/web flip these; iOS draws real-world objects as-is (Apple's rule).
|
|
32
|
+
const MIRROR_ANDROID_ONLY = new Set(["videocam", "content-copy", "ai-copy-option", "chat", "sticker"]);
|
|
33
|
+
// "format-list-numbered" isn't flipped (that would mirror the digits): RTL swaps in its own
|
|
34
|
+
// drawing with the numbers on the right (ENG-41386).
|
|
35
|
+
const RTL_DRAWINGS: Partial<Record<string, React.ComponentType<any>>> = {
|
|
36
|
+
"format-list-numbered": FormatListNumberedRtl,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function shouldMirrorIcon(name: string, isRTL: boolean, os: string): boolean {
|
|
40
|
+
if (!isRTL) return false;
|
|
41
|
+
const base = name.endsWith("-fill") ? name.slice(0, -5) : name;
|
|
42
|
+
return MIRROR_ALWAYS.has(base) || (os === "android" && MIRROR_ANDROID_ONLY.has(base));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const MIRROR_STYLE: ViewStyle = { transform: [{ scaleX: -1 }] };
|
|
46
|
+
|
|
17
47
|
type IconProps = {
|
|
18
48
|
name?: IconName;
|
|
19
49
|
color?: ColorValue;
|
|
@@ -27,6 +57,7 @@ type IconProps = {
|
|
|
27
57
|
|
|
28
58
|
export const Icon = (props: IconProps) => {
|
|
29
59
|
const theme = useTheme();
|
|
60
|
+
const isRTL = useKitRTL();
|
|
30
61
|
const {
|
|
31
62
|
name,
|
|
32
63
|
color = theme.color.textSecondary,
|
|
@@ -56,10 +87,14 @@ export const Icon = (props: IconProps) => {
|
|
|
56
87
|
);
|
|
57
88
|
}
|
|
58
89
|
if ("name" in props && name) {
|
|
59
|
-
const IconComponent = ICONS[name];
|
|
90
|
+
const IconComponent = (isRTL && RTL_DRAWINGS[name]) || ICONS[name];
|
|
60
91
|
if (IconComponent) {
|
|
92
|
+
const mirror = shouldMirrorIcon(name, isRTL, Platform.OS);
|
|
93
|
+
// The flip goes on the icon's own container, after containerStyle so it wins. No extra
|
|
94
|
+
// wrapper view: an added non-collapsable child under a flattened container crashed
|
|
95
|
+
// Fabric on Android ("addViewAt: failed to insert view", ENG-41312 A/B, 5/5 vs 0/5).
|
|
61
96
|
return (
|
|
62
|
-
<View style={[containerStyle]}>
|
|
97
|
+
<View style={[containerStyle, mirror && MIRROR_STYLE]}>
|
|
63
98
|
<IconComponent
|
|
64
99
|
color={color as any}
|
|
65
100
|
height={typeof height === "number" ? height : (size as number)}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Svg, { Path } from "react-native-svg";
|
|
2
|
+
import type { SvgProps } from "react-native-svg";
|
|
3
|
+
// ENG-41386: RTL drawing of format-list-numbered (design: numbers on the right). The digits move,
|
|
4
|
+
// they are not mirrored; the lines move to the left.
|
|
5
|
+
const SvgComponent = ({ height, width, color }: SvgProps) => (
|
|
6
|
+
<Svg width={width} height={height} fill='none' viewBox='0 0 24 24'>
|
|
7
|
+
<Path
|
|
8
|
+
fill={color}
|
|
9
|
+
transform='translate(17 0)'
|
|
10
|
+
d='M2 17h2v.5H3v1h1v.5H2v1h3v-4H2zm1-9h1V4H2v1h1zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2z'
|
|
11
|
+
/>
|
|
12
|
+
<Path fill={color} d='M3 5v2h14V5zM3 19h14v-2H3zM3 13h14v-2H3z' />
|
|
13
|
+
</Svg>
|
|
14
|
+
);
|
|
15
|
+
export default SvgComponent;
|
|
@@ -13,6 +13,8 @@ import { OfflineHub, OfflineNotice } from "./OfflineHub";
|
|
|
13
13
|
import { noticeCopyText, OFFLINE_STRING_KEYS, offlineNoticeText, Translate } from "./notices";
|
|
14
14
|
import { CONTRACT_IDS } from "./stateContract";
|
|
15
15
|
import { useTheme } from "../../theme";
|
|
16
|
+
// The hook module itself (as shared/index.ts exports it): the folder index also loads the provider.
|
|
17
|
+
import { useCometChatTranslation } from "../resources/CometChatLocalizeNew/useCometChatTranslationHook";
|
|
16
18
|
import { Icon } from "../icons/Icon";
|
|
17
19
|
|
|
18
20
|
const NOTICE_MS = 5000;
|
|
@@ -79,7 +81,9 @@ export interface OfflineNoticeViewProps {
|
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
export const OfflineNoticeView = ({ notice, t, onDismiss, backgroundColor, textColor, actionColor, containerStyle, textStyle, actionTextStyle }: OfflineNoticeViewProps) => {
|
|
82
|
-
|
|
84
|
+
// Count in the language `t` translates into: the provider sets the global language a render later.
|
|
85
|
+
const { language } = useCometChatTranslation();
|
|
86
|
+
const text = offlineNoticeText(notice, t, language);
|
|
83
87
|
const copyText = noticeCopyText(notice);
|
|
84
88
|
// The kit's inverse surface and its text (as in CometChatSearch's active filter), and the
|
|
85
89
|
// highlight text for the action, so the notice follows the light / dark theme.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Localized text for offline notices (README §4 strings). Keys with a count have
|
|
3
|
-
* `_OTHER`
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Localized text for offline notices (README §4 strings). Keys with a count have a form per CLDR
|
|
3
|
+
* plural category (`_ONE` / `_OTHER` everywhere, plus `_ZERO` / `_TWO` / `_FEW` / `_MANY` where the
|
|
4
|
+
* language has them), picked by pluralCountLabel; `{count}` is replaced with the count in the
|
|
5
|
+
* language's digits.
|
|
6
6
|
*
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { pluralCountLabel } from "../helper/pluralRules";
|
|
10
|
+
import { Language } from "../resources/CometChatLocalizeNew/type";
|
|
10
11
|
import { OfflineNotice } from "./OfflineHub";
|
|
11
12
|
|
|
12
13
|
export type Translate = (key: string) => string;
|
|
@@ -35,22 +36,15 @@ export const OFFLINE_STRING_KEYS = Object.freeze({
|
|
|
35
36
|
sendInFlight: "OFFLINE_SEND_IN_FLIGHT",
|
|
36
37
|
});
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** `key` for `count`, from `key_ONE` / `key_OTHER`. */
|
|
48
|
-
export function localizedPlural(t: Translate, key: string, count: number): string {
|
|
49
|
-
const text = t(`${key}_${pluralCategory(count) === "one" ? "ONE" : "OTHER"}`);
|
|
50
|
-
return String(text ?? "").replace(/\{count\}/g, String(count));
|
|
39
|
+
/**
|
|
40
|
+
* `key` for `count` in `language`: pass the language `t` translates into (useCometChatTranslation's
|
|
41
|
+
* `language`); the default is the global language, which the provider sets a render later.
|
|
42
|
+
*/
|
|
43
|
+
export function localizedPlural(t: Translate, key: string, count: number, language?: Language): string {
|
|
44
|
+
return pluralCountLabel((k) => String(t(k) ?? ""), key, count, language);
|
|
51
45
|
}
|
|
52
46
|
|
|
53
|
-
export function offlineNoticeText(notice: OfflineNotice, t: Translate): string {
|
|
47
|
+
export function offlineNoticeText(notice: OfflineNotice, t: Translate, language?: Language): string {
|
|
54
48
|
switch (notice.kind) {
|
|
55
49
|
case "unsent_message_removed":
|
|
56
50
|
return t(OFFLINE_STRING_KEYS.unsentMessageRemoved);
|
|
@@ -59,9 +53,9 @@ export function offlineNoticeText(notice: OfflineNotice, t: Translate): string {
|
|
|
59
53
|
case "file_too_large_offline":
|
|
60
54
|
return t(OFFLINE_STRING_KEYS.fileTooLarge);
|
|
61
55
|
case "messages_not_sent":
|
|
62
|
-
return localizedPlural(t, OFFLINE_STRING_KEYS.messagesNotSent, notice.count ?? 1);
|
|
56
|
+
return localizedPlural(t, OFFLINE_STRING_KEYS.messagesNotSent, notice.count ?? 1, language);
|
|
63
57
|
case "unsent_messages_lost":
|
|
64
|
-
return localizedPlural(t, OFFLINE_STRING_KEYS.unsentMessagesLost, notice.count ?? 1);
|
|
58
|
+
return localizedPlural(t, OFFLINE_STRING_KEYS.unsentMessagesLost, notice.count ?? 1, language);
|
|
65
59
|
case "unsent_messages_maybe_lost":
|
|
66
60
|
return t(OFFLINE_STRING_KEYS.unsentMessagesMaybeLost);
|
|
67
61
|
case "send_in_flight":
|
|
@@ -16,6 +16,7 @@ import ko from './resources/ko/translation.json';
|
|
|
16
16
|
import tr from './resources/tr/translation.json';
|
|
17
17
|
import nl from './resources/nl/translation.json';
|
|
18
18
|
import it from './resources/it/translation.json';
|
|
19
|
+
import ar from './resources/ar/translation.json';
|
|
19
20
|
import { Language } from './type';
|
|
20
21
|
|
|
21
22
|
|
|
@@ -40,6 +41,7 @@ const defaultTranslations = {
|
|
|
40
41
|
tr,
|
|
41
42
|
nl,
|
|
42
43
|
it,
|
|
44
|
+
ar,
|
|
43
45
|
"zh-tw":zhTw,
|
|
44
46
|
"en-IN" : en,
|
|
45
47
|
"en-GB" : en,
|