@cometchat/chat-uikit-react-native 5.0.1 → 5.1.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/.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/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +87 -41
- package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +10 -0
- package/ios/SoundPlayer.m +8 -0
- package/lib/CometChatMessageList/CometChatMessageList.js +1 -1
- package/lib/CometChatMessageList/CometChatMessageList.js.map +1 -1
- package/lib/extensions/Stickers/StickersExtensionDecorator.d.ts +1 -2
- package/lib/extensions/Stickers/StickersExtensionDecorator.js +1 -2
- package/lib/extensions/Stickers/StickersExtensionDecorator.js.map +1 -1
- package/lib/shared/CometChatUiKit/CometChatUIKit.d.ts +2 -1
- package/lib/shared/CometChatUiKit/CometChatUIKit.js +2 -1
- package/lib/shared/CometChatUiKit/CometChatUIKit.js.map +1 -1
- package/lib/shared/index.d.ts +15 -13
- package/lib/shared/index.js +30 -12
- package/lib/shared/index.js.map +1 -1
- package/lib/shared/utils/CometChatMessagePreview/CometChatMessagePreview.d.ts +10 -1
- package/lib/shared/utils/CometChatMessagePreview/CometChatMessagePreview.js +8 -0
- package/lib/shared/utils/CometChatMessagePreview/CometChatMessagePreview.js.map +1 -1
- package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.d.ts +29 -0
- package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js +29 -0
- package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js.map +1 -0
- package/lib/shared/utils/CometChatMessagePreview/index.d.ts +2 -1
- package/lib/shared/utils/CometChatMessagePreview/index.js +3 -1
- package/lib/shared/utils/CometChatMessagePreview/index.js.map +1 -1
- package/lib/shared/utils/CometChatMessagePreview/style.d.ts +16 -16
- package/lib/shared/utils/MessageUtils.js +11 -10
- package/lib/shared/utils/MessageUtils.js.map +1 -1
- package/lib/shared/utils/index.d.ts +2 -2
- package/lib/shared/utils/index.js +2 -2
- package/lib/shared/utils/index.js.map +1 -1
- package/lib/theme/context.js +1 -1
- package/lib/theme/context.js.map +1 -1
- package/lib/theme/default/index.d.ts +6 -0
- package/lib/theme/default/index.js +178 -0
- package/lib/theme/default/index.js.map +1 -1
- package/lib/theme/provider.js +1 -1
- package/lib/theme/provider.js.map +1 -1
- package/package.json +6 -4
- package/react-native-cometchat-ui-kit.podspec +1 -1
- package/src/CometChatConversations/CometChatConversations.tsx +34 -29
- package/src/CometChatConversations/style.ts +5 -2
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +56 -44
- package/src/CometChatGroups/CometChatGroups.tsx +13 -10
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +203 -57
- package/src/CometChatMessageComposer/styles.tsx +2 -6
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +8 -48
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +8 -14
- package/src/CometChatMessageList/CometChatMessageList.tsx +18 -10
- package/src/CometChatMessageList/style.ts +0 -16
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +3 -2
- package/src/CometChatUsers/CometChatUsers.tsx +9 -8
- package/src/calls/CallUtils.ts +14 -14
- package/src/calls/CallingExtensionDecorator.tsx +13 -12
- package/src/calls/CometChatCallBubble/CometChatCallBubble.tsx +4 -3
- package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +15 -12
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +8 -6
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +4 -2
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +7 -6
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +7 -6
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +3 -2
- package/src/extensions/MessageTranslation/MessageTranslationBubble.tsx +3 -2
- package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +26 -17
- package/src/extensions/Polls/Polls.tsx +53 -17
- package/src/extensions/Polls/PollsDecorator.tsx +5 -3
- package/src/extensions/Stickers/CometChatStickerKeyboard/CometChatStickerKeyboard.tsx +5 -4
- package/src/extensions/Stickers/CometChatStickerKeyboard/hooks.ts +3 -2
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +5 -2
- package/src/index.ts +10 -4
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +1 -2
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +116 -32
- package/src/shared/framework/DataSource.ts +5 -2
- package/src/shared/framework/DataSourceDecorator.tsx +4 -4
- package/src/shared/framework/MessageDataSource.tsx +178 -46
- package/src/shared/helper/LocalizedDateHelper.ts +317 -0
- package/src/shared/helper/functions.js +69 -1
- package/src/shared/helper/useLocalizedDateHook.tsx +16 -0
- package/src/shared/index.ts +7 -2
- package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +106 -0
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +99 -0
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizeContext.tsx +15 -0
- package/src/shared/resources/CometChatLocalizeNew/LocalizationManager.ts +65 -0
- package/src/shared/resources/CometChatLocalizeNew/index.ts +25 -0
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/de/translation.json +10 -1
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/en/translation.json +10 -1
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/es/translation.json +10 -1
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/fr/translation.json +10 -1
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/hi/translation.json +11 -1
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/hu/translation.json +10 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +456 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +456 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +456 -0
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/lt/translation.json +10 -1
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/ms/translation.json +10 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +456 -0
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/pt/translation.json +10 -1
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/ru/translation.json +10 -1
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/sv/translation.json +11 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +456 -0
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/zh/translation.json +11 -1
- package/src/shared/resources/{CometChatLocalize → CometChatLocalizeNew}/resources/zh-tw/translation.json +10 -1
- package/src/shared/resources/CometChatLocalizeNew/type.ts +7 -0
- package/src/shared/resources/CometChatLocalizeNew/useCometChatTranslationHook.ts +24 -0
- package/src/shared/resources/index.ts +2 -2
- package/src/shared/utils/CommonUtils.ts +2 -1
- package/src/shared/utils/PermissionUtil.ts +5 -4
- package/src/shared/utils/conversationUtils.ts +11 -9
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +8 -5
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +1 -1
- package/src/shared/views/CometChatDate/CometChatDate.tsx +17 -14
- package/src/shared/views/CometChatDateSeperator/CometChatDateSeparator.tsx +6 -4
- package/src/shared/views/CometChatDeletedBubble/CometChatDeletedBubble.tsx +3 -2
- package/src/shared/views/CometChatEmojiKeyboard/emojis.ts +11 -8
- package/src/shared/views/CometChatList/CometChatList.tsx +5 -4
- package/src/shared/views/CometChatMediaRecorder/CometChatAudioPreview/CometChatAudioPreview.tsx +15 -9
- package/src/shared/views/CometChatMediaRecorder/CometChatMediaRecorder.tsx +5 -4
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -2
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +7 -6
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +10 -7
- package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +1 -0
- package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +24 -47
- package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +68 -73
- package/src/theme/type.ts +0 -2
- package/lib/theme/default/default.d.ts +0 -6
- package/lib/theme/default/default.js +0 -179
- package/lib/theme/default/default.js.map +0 -1
- package/src/shared/resources/CometChatLocalize/CometChatLocalize.ts +0 -183
- package/src/shared/resources/CometChatLocalize/index.ts +0 -3
- package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +0 -447
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { Language } from "../resources/CometChatLocalizeNew/type";
|
|
2
|
+
import { getCometChatTranslation } from "../../shared";
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import 'dayjs/locale/en'; // English
|
|
5
|
+
import 'dayjs/locale/hi'; // Hindi
|
|
6
|
+
import 'dayjs/locale/ja'; // Japanese
|
|
7
|
+
import 'dayjs/locale/ko'; // Korean
|
|
8
|
+
import 'dayjs/locale/ru'; // Russian
|
|
9
|
+
import 'dayjs/locale/pt'; // Portuguese
|
|
10
|
+
import 'dayjs/locale/es'; // Spanish
|
|
11
|
+
import 'dayjs/locale/fr'; // French
|
|
12
|
+
import 'dayjs/locale/de'; // German
|
|
13
|
+
import 'dayjs/locale/it'; // Italian
|
|
14
|
+
import 'dayjs/locale/tr'; // Turkish
|
|
15
|
+
import 'dayjs/locale/zh'; // Chinese (Simplified)
|
|
16
|
+
import 'dayjs/locale/zh-tw'; // Chinese (Traditional)
|
|
17
|
+
import 'dayjs/locale/ms'; // Malay
|
|
18
|
+
import 'dayjs/locale/sv'; // Swedish
|
|
19
|
+
import 'dayjs/locale/lt'; // Lithuanian
|
|
20
|
+
import 'dayjs/locale/hu'; // Hungarian
|
|
21
|
+
import 'dayjs/locale/nl'; // Dutch
|
|
22
|
+
// Import other languages as needed
|
|
23
|
+
|
|
24
|
+
// Dayjs plugins
|
|
25
|
+
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
26
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
27
|
+
// Initialize plugins
|
|
28
|
+
dayjs.extend(localizedFormat);
|
|
29
|
+
dayjs.extend(relativeTime);
|
|
30
|
+
import * as RNLocalize from 'react-native-localize';
|
|
31
|
+
|
|
32
|
+
const t = getCometChatTranslation();
|
|
33
|
+
|
|
34
|
+
export class LocalizedDateHelper {
|
|
35
|
+
public static patterns = {
|
|
36
|
+
timeFormat: "timeFormat",
|
|
37
|
+
dayDateFormat: "dayDateFormat",
|
|
38
|
+
dayWeekDayDateFormat: "dayWeekDayDateFormat",
|
|
39
|
+
dayWeekDayDateTimeFormat: "dayWeekDayDateTimeFormat",
|
|
40
|
+
dayDateTimeFormat: "dayDateTimeFormat",
|
|
41
|
+
callBubble: "callBubble",
|
|
42
|
+
callLogs: "callLogs",
|
|
43
|
+
relativeMinutes: "relativeMinutes",
|
|
44
|
+
conversationDate: "conversationDate",
|
|
45
|
+
} as const;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Maps language codes to full locale codes and numeral systems
|
|
49
|
+
*/
|
|
50
|
+
public getLocaleConfig(locale: Language): { localeCode: string, dateFormattingLocale: string, dayJsLocale: string } {
|
|
51
|
+
// Map language codes to full locale codes
|
|
52
|
+
const localeMap: Record<string, string> = {
|
|
53
|
+
'en': 'en',
|
|
54
|
+
'en-IN': 'en', // English (India)
|
|
55
|
+
'en-US': 'en-US', // English (United States)
|
|
56
|
+
'en-GB': 'en-GB', // English (United Kingdom)
|
|
57
|
+
'nl': 'nl-NL', // Dutch
|
|
58
|
+
'fr': 'fr-FR', // French
|
|
59
|
+
'de': 'de-DE', // German
|
|
60
|
+
'hi': 'hi-IN', // Hindi
|
|
61
|
+
'it': 'it-IT', // Italian
|
|
62
|
+
'ja': 'ja-JP', // Japanese
|
|
63
|
+
'ko': 'ko-KR', // Korean
|
|
64
|
+
'pt': 'pt-PT', // Portuguese
|
|
65
|
+
'ru': 'ru-RU', // Russian
|
|
66
|
+
'es': 'es-ES', // Spanish
|
|
67
|
+
'tr': 'tr-TR', // Turkish
|
|
68
|
+
'zh': 'zh-CN', // Chinese (Simplified)
|
|
69
|
+
'zh-tw': 'zh-TW', // Chinese (Traditional)
|
|
70
|
+
'ms': 'ms-MY', // Malay
|
|
71
|
+
'sv': 'sv-SE', // Swedish
|
|
72
|
+
'lt': 'lt-LT', // Lithuanian
|
|
73
|
+
'hu': 'hu-HU', // Hungarian
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Map to dayjs locale codes (usually simpler than full locale codes)
|
|
77
|
+
const dayJsLocaleMap: Record<string, string> = {
|
|
78
|
+
'en-IN': 'en',
|
|
79
|
+
'en-GB': 'en-gb',
|
|
80
|
+
'zh-tw': 'zh-tw',
|
|
81
|
+
// Most other languages use their basic code in dayjs
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
localeCode: localeMap[locale] || locale,
|
|
86
|
+
dateFormattingLocale: LocalizedDateHelper.getFullLocaleForDateFormatting(locale),
|
|
87
|
+
dayJsLocale: dayJsLocaleMap[locale] || locale
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Check if the locale prefers 12-hour clock format
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
private shouldUse12HourClock(locale: Language): boolean {
|
|
96
|
+
const twelveHourLocales = [
|
|
97
|
+
'en-US', 'en-GB', 'en',
|
|
98
|
+
'hi-IN', 'hi',
|
|
99
|
+
'ms-MY', 'ms'
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
const { localeCode, dayJsLocale } = this.getLocaleConfig(locale);
|
|
103
|
+
|
|
104
|
+
if (twelveHourLocales.includes(localeCode)) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const isKnownToDayjs =
|
|
109
|
+
Boolean(dayjs.Ls[dayJsLocale]) || Boolean(dayjs.Ls[localeCode]);
|
|
110
|
+
|
|
111
|
+
if (!isKnownToDayjs) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Format time using dayjs
|
|
120
|
+
*/
|
|
121
|
+
private formatTime(date: Date, locale: Language): string {
|
|
122
|
+
const { dayJsLocale } = this.getLocaleConfig(locale);
|
|
123
|
+
|
|
124
|
+
// Apply locale to Day.js
|
|
125
|
+
dayjs.locale(dayJsLocale);
|
|
126
|
+
|
|
127
|
+
// Decide between 12-hour and 24-hour
|
|
128
|
+
const use12Hour = this.shouldUse12HourClock(locale);
|
|
129
|
+
|
|
130
|
+
// Build format string
|
|
131
|
+
const formatString = use12Hour ? "h:mm A" : "HH:mm";
|
|
132
|
+
|
|
133
|
+
// Return formatted time (with localized AM/PM if available in locale)
|
|
134
|
+
return dayjs(date).format(formatString);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Gets the full locale tag needed for date formatting
|
|
139
|
+
* This extends simple language codes to include region information
|
|
140
|
+
*/
|
|
141
|
+
public static getFullLocaleForDateFormatting(language: Language): string {
|
|
142
|
+
// If we have a language that includes region (like en-US), use it directly
|
|
143
|
+
if (language.includes('-')) {
|
|
144
|
+
return language;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// DEFAULT MAPPINGS - Always use these explicit mappings instead of device detection
|
|
148
|
+
const defaultRegionMap: Record<string, string> = {
|
|
149
|
+
'en': 'en-IN', // Default English to IN format (DD/MM/YYYY)
|
|
150
|
+
'en-IN': 'en-IN',
|
|
151
|
+
'en-US': 'en-US',
|
|
152
|
+
'en-GB': 'en-GB',
|
|
153
|
+
'es': 'es-ES',
|
|
154
|
+
'fr': 'fr-FR',
|
|
155
|
+
'de': 'de-DE',
|
|
156
|
+
'pt': 'pt-BR',
|
|
157
|
+
'it': 'it-IT',
|
|
158
|
+
'ru': 'ru-RU',
|
|
159
|
+
'zh': 'zh-CN',
|
|
160
|
+
'ja': 'ja-JP',
|
|
161
|
+
'hi': 'hi-IN',
|
|
162
|
+
'ms': 'ms-MY',
|
|
163
|
+
'sv': 'sv-SE',
|
|
164
|
+
'lt': 'lt-LT',
|
|
165
|
+
'hu': 'hu-HU',
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// Return the mapped region or construct a default one
|
|
169
|
+
return defaultRegionMap[language] || `${language}-${language.toUpperCase()}`;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Format date specifically for conversation list
|
|
173
|
+
*/
|
|
174
|
+
private formatConversationDate(date: Date, locale: Language): string {
|
|
175
|
+
const { dateFormattingLocale, dayJsLocale } = this.getLocaleConfig(locale);
|
|
176
|
+
|
|
177
|
+
// Set dayjs locale for weekday names
|
|
178
|
+
dayjs.locale(dayJsLocale);
|
|
179
|
+
|
|
180
|
+
const now = dayjs();
|
|
181
|
+
const messageDate = dayjs(date);
|
|
182
|
+
const startOfToday = now.startOf('day');
|
|
183
|
+
|
|
184
|
+
// Today - show just the time with AM/PM (maintain existing behavior)
|
|
185
|
+
if (messageDate.isAfter(startOfToday)) {
|
|
186
|
+
return this.formatTime(date, locale);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Yesterday (maintain existing behavior)
|
|
190
|
+
if (messageDate.isAfter(startOfToday.subtract(1, 'day'))) {
|
|
191
|
+
return t("YESTERDAY");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
// For dates older than current week, use locale-appropriate date format
|
|
196
|
+
try {
|
|
197
|
+
// Use Intl.DateTimeFormat with the full locale tag for proper date formatting
|
|
198
|
+
const options: Intl.DateTimeFormatOptions = {
|
|
199
|
+
day: 'numeric',
|
|
200
|
+
month: 'numeric',
|
|
201
|
+
year: 'numeric'
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const formatter = new Intl.DateTimeFormat(dateFormattingLocale, options);
|
|
205
|
+
const formattedDate = formatter.format(date);
|
|
206
|
+
|
|
207
|
+
return formattedDate
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
} catch (error) {
|
|
211
|
+
console.warn('Error formatting date with Intl.DateTimeFormat:', error);
|
|
212
|
+
return ""
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Format date for date separators (more detailed than conversation list)
|
|
218
|
+
*/
|
|
219
|
+
private formatDateSeparator(date: Date, locale: Language): string {
|
|
220
|
+
const { dayJsLocale } = this.getLocaleConfig(locale);
|
|
221
|
+
|
|
222
|
+
// Set dayjs locale
|
|
223
|
+
dayjs.locale(dayJsLocale);
|
|
224
|
+
|
|
225
|
+
const now = dayjs();
|
|
226
|
+
const messageDate = dayjs(date);
|
|
227
|
+
const startOfToday = now.startOf('day');
|
|
228
|
+
|
|
229
|
+
// Today
|
|
230
|
+
if (messageDate.isAfter(startOfToday)) {
|
|
231
|
+
return t("TODAY");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Yesterday
|
|
235
|
+
if (messageDate.isAfter(startOfToday.subtract(1, 'day'))) {
|
|
236
|
+
return t("YESTERDAY");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Within current week (show weekday)
|
|
240
|
+
if (messageDate.isAfter(startOfToday.subtract(6, 'day'))) {
|
|
241
|
+
// Use dayjs for weekday name
|
|
242
|
+
return messageDate.format('dddd');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Older messages, show full date
|
|
246
|
+
const formattedDate = messageDate.format('D MMM, YYYY');
|
|
247
|
+
return formattedDate
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Format date and time together
|
|
252
|
+
*/
|
|
253
|
+
private formatDateTimeWithSeparator(date: Date, locale: Language): string {
|
|
254
|
+
const { dayJsLocale } = this.getLocaleConfig(locale);
|
|
255
|
+
|
|
256
|
+
// Set dayjs locale
|
|
257
|
+
dayjs.locale(dayJsLocale);
|
|
258
|
+
|
|
259
|
+
const now = dayjs();
|
|
260
|
+
const messageDate = dayjs(date);
|
|
261
|
+
const startOfToday = now.startOf('day');
|
|
262
|
+
const time = this.formatTime(date, locale);
|
|
263
|
+
|
|
264
|
+
// Today
|
|
265
|
+
if (messageDate.isAfter(startOfToday)) {
|
|
266
|
+
return `${t("TODAY")} ${time}`;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Yesterday
|
|
270
|
+
if (messageDate.isAfter(startOfToday.subtract(1, 'day'))) {
|
|
271
|
+
return `${t("YESTERDAY")} ${time}`;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Within current week
|
|
275
|
+
if (messageDate.isAfter(startOfToday.subtract(6, 'day'))) {
|
|
276
|
+
return `${messageDate.format('dddd')} ${time}`;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Older messages
|
|
280
|
+
const formattedDate = messageDate.format('D MMM, YYYY');
|
|
281
|
+
return `${formattedDate} ${time}`;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Public method to get formatted date according to pattern
|
|
286
|
+
*/
|
|
287
|
+
getFormattedDate(timestamp: number, pattern: string, locale: Language = "en"): string {
|
|
288
|
+
const date = new Date(timestamp);
|
|
289
|
+
|
|
290
|
+
switch (pattern) {
|
|
291
|
+
case LocalizedDateHelper.patterns.timeFormat:
|
|
292
|
+
return this.formatTime(date, locale);
|
|
293
|
+
case LocalizedDateHelper.patterns.dayDateFormat:
|
|
294
|
+
case LocalizedDateHelper.patterns.dayWeekDayDateFormat:
|
|
295
|
+
return this.formatDateSeparator(date, locale);
|
|
296
|
+
|
|
297
|
+
case LocalizedDateHelper.patterns.dayWeekDayDateTimeFormat:
|
|
298
|
+
case LocalizedDateHelper.patterns.dayDateTimeFormat:
|
|
299
|
+
return this.formatDateTimeWithSeparator(date, locale);
|
|
300
|
+
|
|
301
|
+
case LocalizedDateHelper.patterns.conversationDate:
|
|
302
|
+
return this.formatConversationDate(date, locale);
|
|
303
|
+
|
|
304
|
+
case LocalizedDateHelper.patterns.callBubble:
|
|
305
|
+
case LocalizedDateHelper.patterns.callLogs:
|
|
306
|
+
const { dayJsLocale } = this.getLocaleConfig(locale);
|
|
307
|
+
dayjs.locale(dayJsLocale);
|
|
308
|
+
const use12Hour = this.shouldUse12HourClock(locale);
|
|
309
|
+
const formatString = use12Hour ? "D MMM, h:mm A" : "D MMM, HH:mm";
|
|
310
|
+
return dayjs(date).format(formatString);
|
|
311
|
+
default:
|
|
312
|
+
return this.formatDateSeparator(date, locale);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export const localizedDateHelperInstance = new LocalizedDateHelper();
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { useCometChatTranslation } from "../resources/CometChatLocalizeNew";
|
|
2
|
+
import { localizedDateHelperInstance } from "./LocalizedDateHelper";
|
|
3
|
+
import dayjs from "dayjs";
|
|
4
|
+
|
|
1
5
|
export const CheckPropertyExists = (obj, propkey) => {
|
|
2
6
|
return Object.prototype.hasOwnProperty.call(obj, propkey);
|
|
3
7
|
}
|
|
@@ -33,4 +37,68 @@ export const getMetadataByKey = (message, metadataKey) => {
|
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
return null;
|
|
36
|
-
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function getLastSeenTime(timestamp) {
|
|
43
|
+
try {
|
|
44
|
+
if (timestamp === null) return t("LAST_SEEN_UNKNOWN");
|
|
45
|
+
|
|
46
|
+
// Convert to milliseconds if in seconds
|
|
47
|
+
if (String(timestamp).length === 10) timestamp *= 1000;
|
|
48
|
+
|
|
49
|
+
// Get user's current language from the translation hook
|
|
50
|
+
const { language,t } = useCometChatTranslation();
|
|
51
|
+
|
|
52
|
+
// Set the appropriate Day.js locale
|
|
53
|
+
dayjs.locale(language);
|
|
54
|
+
|
|
55
|
+
const now = dayjs();
|
|
56
|
+
const lastSeenTime = dayjs(timestamp);
|
|
57
|
+
const diffInMinutes = now.diff(lastSeenTime, "minute");
|
|
58
|
+
const diffInHours = now.diff(lastSeenTime, "hour");
|
|
59
|
+
const diffInDays = now.diff(lastSeenTime, "day");
|
|
60
|
+
|
|
61
|
+
// For very recent times (< 1 min) → "a few seconds ago"
|
|
62
|
+
if (diffInMinutes < 1) {
|
|
63
|
+
const relativeTimeString = lastSeenTime.fromNow();
|
|
64
|
+
// Day.js will give "a few seconds ago" localized
|
|
65
|
+
return `${t("LAST_SEEN")} ${relativeTimeString}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// For times less than 24 hours → relative ("X minutes ago", "X hours ago")
|
|
69
|
+
if (diffInHours < 24) {
|
|
70
|
+
const relativeTimeString = lastSeenTime.fromNow();
|
|
71
|
+
return `${t("LAST_SEEN")} ${relativeTimeString}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// For yesterday with time
|
|
75
|
+
if (diffInDays === 1) {
|
|
76
|
+
const timeFormat = localizedDateHelperInstance.getFormattedDate(
|
|
77
|
+
timestamp,
|
|
78
|
+
"timeFormat",
|
|
79
|
+
language
|
|
80
|
+
);
|
|
81
|
+
return `${t("LAST_SEEN")} ${t("YESTERDAY")} ${timeFormat}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// For dates within the past week → weekday + time
|
|
85
|
+
if (diffInDays < 7) {
|
|
86
|
+
const formattedDate = localizedDateHelperInstance.getFormattedDate(
|
|
87
|
+
timestamp,
|
|
88
|
+
"dayWeekDayDateTimeFormat",
|
|
89
|
+
language
|
|
90
|
+
);
|
|
91
|
+
return `${t("LAST_SEEN")} ${formattedDate}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Older dates → full date + time
|
|
95
|
+
return `${t("LAST_SEEN")} ${localizedDateHelperInstance.getFormattedDate(
|
|
96
|
+
timestamp,
|
|
97
|
+
"dayDateTimeFormat",
|
|
98
|
+
language
|
|
99
|
+
)}`;
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.log(e);
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useCometChatTranslation } from "../resources/CometChatLocalizeNew";
|
|
3
|
+
import { localizedDateHelperInstance } from "./../helper/LocalizedDateHelper";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook to use localized date formatting with current language
|
|
7
|
+
*/
|
|
8
|
+
export const useLocalizedDate = () => {
|
|
9
|
+
const { language } = useCometChatTranslation();
|
|
10
|
+
|
|
11
|
+
return useMemo(() => ({
|
|
12
|
+
formatDate: (timestamp: number, pattern: string): string => {
|
|
13
|
+
return localizedDateHelperInstance.getFormattedDate(timestamp, pattern, language);
|
|
14
|
+
}
|
|
15
|
+
}), [language]);
|
|
16
|
+
};
|
package/src/shared/index.ts
CHANGED
|
@@ -37,7 +37,6 @@ export {
|
|
|
37
37
|
CometChatMessageTemplate,
|
|
38
38
|
} from "./modals";
|
|
39
39
|
|
|
40
|
-
export { CometChatLocalize, localize } from "./resources/CometChatLocalize";
|
|
41
40
|
export {
|
|
42
41
|
CometChatConversationUtils,
|
|
43
42
|
CometChatMessagePreview,
|
|
@@ -106,4 +105,10 @@ export { CometChatUIKit, CometChatUIKitHelper, UIKitSettings } from "./CometChat
|
|
|
106
105
|
|
|
107
106
|
export type { CometChatMessageComposerAction } from "./helper/types";
|
|
108
107
|
|
|
109
|
-
export { messageStatus } from "./utils/CometChatMessageHelper/index";
|
|
108
|
+
export { messageStatus } from "./utils/CometChatMessageHelper/index";
|
|
109
|
+
|
|
110
|
+
export { getCometChatTranslation, getCurrentLanguage} from "./resources/CometChatLocalizeNew/LocalizationManager";
|
|
111
|
+
export { useLocalizedDate } from "./helper/useLocalizedDateHook";
|
|
112
|
+
export { LocalizedDateHelper } from "./helper/LocalizedDateHelper";
|
|
113
|
+
export { useCometChatTranslation } from "./resources/CometChatLocalizeNew/useCometChatTranslationHook";
|
|
114
|
+
export {getLastSeenTime} from "./helper/functions";
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React, { ReactNode, useState, useEffect, useMemo, useCallback } from "react";
|
|
2
|
+
import { getAvailableLanguages, translate } from "./CometChatLocalizationHelper";
|
|
3
|
+
import { CometChatLocalizeContext } from "./CometChatLocalizeContext";
|
|
4
|
+
import { setGlobalLanguage } from './LocalizationManager';
|
|
5
|
+
import * as RNLocalize from 'react-native-localize';
|
|
6
|
+
import { Language } from "./type";
|
|
7
|
+
|
|
8
|
+
interface CometChatI18nProviderProps {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
selectedLanguage?: Language;
|
|
11
|
+
autoDetectLanguage?: boolean;
|
|
12
|
+
fallbackLanguage?: Language;
|
|
13
|
+
translations?: {
|
|
14
|
+
[languageCode: string]: {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getDeviceLanguage = (): Language => {
|
|
21
|
+
try {
|
|
22
|
+
const locales = RNLocalize.getLocales();
|
|
23
|
+
if (Array.isArray(locales) && locales.length > 0) {
|
|
24
|
+
const code = locales[0].languageCode as Language;
|
|
25
|
+
console.log(locales[0], " device language detected");
|
|
26
|
+
return code;
|
|
27
|
+
}
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.warn('Error getting device language:', error);
|
|
30
|
+
}
|
|
31
|
+
return 'en';
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export const CometChatI18nProvider = ({
|
|
37
|
+
children,
|
|
38
|
+
selectedLanguage,
|
|
39
|
+
autoDetectLanguage = true,
|
|
40
|
+
fallbackLanguage = 'en',
|
|
41
|
+
translations
|
|
42
|
+
}: CometChatI18nProviderProps) => {
|
|
43
|
+
const [language, setLanguage] = useState<Language>(() => {
|
|
44
|
+
if (selectedLanguage) {
|
|
45
|
+
console.log(selectedLanguage, " selected language provided");
|
|
46
|
+
const availableLanguages = getAvailableLanguages();
|
|
47
|
+
const customLanguages = translations ? Object.keys(translations) : [];
|
|
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;
|
|
57
|
+
}
|
|
58
|
+
} else if (autoDetectLanguage) {
|
|
59
|
+
console.log("Using device language");
|
|
60
|
+
return getDeviceLanguage();
|
|
61
|
+
}
|
|
62
|
+
return fallbackLanguage;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (selectedLanguage) {
|
|
67
|
+
console.log(selectedLanguage, " selected language changed via props");
|
|
68
|
+
const availableLanguages = getAvailableLanguages();
|
|
69
|
+
const customLanguages = translations ? Object.keys(translations) : [];
|
|
70
|
+
const allAvailableLanguages = [...availableLanguages, ...customLanguages];
|
|
71
|
+
|
|
72
|
+
if (allAvailableLanguages.includes(selectedLanguage)) {
|
|
73
|
+
setLanguage(selectedLanguage);
|
|
74
|
+
console.log(selectedLanguage, " language set from props");
|
|
75
|
+
} else {
|
|
76
|
+
console.warn(`Language '${selectedLanguage}' not found (set via prop). Using fallback: ${fallbackLanguage}`);
|
|
77
|
+
setLanguage(fallbackLanguage);
|
|
78
|
+
}
|
|
79
|
+
} else if (autoDetectLanguage) {
|
|
80
|
+
console.log("Auto-detecting device language");
|
|
81
|
+
setLanguage(getDeviceLanguage());
|
|
82
|
+
}
|
|
83
|
+
}, [selectedLanguage, autoDetectLanguage, fallbackLanguage, translations]);
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
setGlobalLanguage(language, translations, fallbackLanguage);
|
|
88
|
+
}, [language, translations, fallbackLanguage]);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
const t = useCallback((key: string): string => {
|
|
92
|
+
return translate(language, key, translations, fallbackLanguage);
|
|
93
|
+
}, [language, translations, fallbackLanguage]);
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
const contextValue = useMemo(() => ({
|
|
97
|
+
language,
|
|
98
|
+
t,
|
|
99
|
+
}), [language, t]);
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<CometChatLocalizeContext.Provider value={contextValue}>
|
|
103
|
+
{children}
|
|
104
|
+
</CometChatLocalizeContext.Provider>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import de from './resources/de/translation.json';
|
|
2
|
+
import en from './resources/en/translation.json';
|
|
3
|
+
import es from './resources/es/translation.json';
|
|
4
|
+
import fr from './resources/fr/translation.json';
|
|
5
|
+
import hi from './resources/hi/translation.json';
|
|
6
|
+
import hu from './resources/hu/translation.json';
|
|
7
|
+
import lt from './resources/lt/translation.json';
|
|
8
|
+
import ms from './resources/ms/translation.json';
|
|
9
|
+
import pt from './resources/pt/translation.json';
|
|
10
|
+
import ru from './resources/ru/translation.json';
|
|
11
|
+
import sv from './resources/sv/translation.json';
|
|
12
|
+
import zh from './resources/zh/translation.json';
|
|
13
|
+
import zhTw from './resources/zh-tw/translation.json';
|
|
14
|
+
import ja from './resources/ja/translation.json';
|
|
15
|
+
import ko from './resources/ko/translation.json';
|
|
16
|
+
import tr from './resources/tr/translation.json';
|
|
17
|
+
import nl from './resources/nl/translation.json';
|
|
18
|
+
import it from './resources/it/translation.json';
|
|
19
|
+
import { Language } from './type';
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export type TranslationKey = keyof typeof en;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const defaultTranslations = {
|
|
26
|
+
de,
|
|
27
|
+
en,
|
|
28
|
+
es,
|
|
29
|
+
fr,
|
|
30
|
+
hi,
|
|
31
|
+
hu,
|
|
32
|
+
lt,
|
|
33
|
+
ms,
|
|
34
|
+
pt,
|
|
35
|
+
ru,
|
|
36
|
+
sv,
|
|
37
|
+
zh,
|
|
38
|
+
ja,
|
|
39
|
+
ko,
|
|
40
|
+
tr,
|
|
41
|
+
nl,
|
|
42
|
+
it,
|
|
43
|
+
"zh-tw":zhTw,
|
|
44
|
+
"en-IN" : en,
|
|
45
|
+
"en-GB" : en,
|
|
46
|
+
"en-US" : en,
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
export type SupportedLanguage = keyof typeof defaultTranslations;
|
|
51
|
+
|
|
52
|
+
export interface CustomTranslations {
|
|
53
|
+
[languageCode: string]: {
|
|
54
|
+
[key: string]: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export const translate = (
|
|
60
|
+
language: Language,
|
|
61
|
+
key: string,
|
|
62
|
+
customTranslations?: CustomTranslations,
|
|
63
|
+
fallbackLanguage: Language = 'en'
|
|
64
|
+
): string => {
|
|
65
|
+
|
|
66
|
+
if (customTranslations?.[language]?.[key]) {
|
|
67
|
+
return customTranslations[language][key];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const defaultTranslation = defaultTranslations[language as SupportedLanguage];
|
|
72
|
+
if (defaultTranslation && key in defaultTranslation) {
|
|
73
|
+
return defaultTranslation[key as TranslationKey];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if (language !== fallbackLanguage && customTranslations?.[fallbackLanguage]?.[key]) {
|
|
78
|
+
return customTranslations[fallbackLanguage][key];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if (language !== fallbackLanguage) {
|
|
83
|
+
const fallbackTranslation = defaultTranslations[fallbackLanguage as SupportedLanguage];
|
|
84
|
+
if (fallbackTranslation && key in fallbackTranslation) {
|
|
85
|
+
return fallbackTranslation[key as TranslationKey];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
console.warn(`Missing translation for key: ${key} in language: ${language} and fallback: ${fallbackLanguage}`);
|
|
91
|
+
return key;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
export const getAvailableLanguages = (): SupportedLanguage[] => {
|
|
96
|
+
return Object.keys(defaultTranslations) as SupportedLanguage[];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export default defaultTranslations;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { createContext } from 'react';
|
|
2
|
+
import { CometChatLocalizeContextType } from './type';
|
|
3
|
+
import { translate } from './CometChatLocalizationHelper';
|
|
4
|
+
|
|
5
|
+
const fallbackTranslate = (key: string): string => {
|
|
6
|
+
console.warn(`Translation function called outside of CometChatI18nProvider for key: ${key}. Using fallback.`);
|
|
7
|
+
return translate('en', key, undefined, 'en');
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const defaultContextValue: CometChatLocalizeContextType = {
|
|
11
|
+
language: 'en',
|
|
12
|
+
t: fallbackTranslate,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const CometChatLocalizeContext = createContext<CometChatLocalizeContextType>(defaultContextValue);
|