Skip to content

Commit

Permalink
fix(core): changed label keys, inject one-source user no name label
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed May 16, 2022
1 parent 106843f commit 003d46d
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 151 deletions.
287 changes: 145 additions & 142 deletions packages/uikit-react-native-core/src/localization/label.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export interface LabelSet {
LIST_DATE_SEPARATOR: (date: Date, locale?: Locale) => string;
LIST_TOOLTIP_NEW_MSG: (newMessages: SendbirdMessage[]) => string;

/** GroupChannel > List > Message */
LIST_MESSAGE_TIME: (message: SendbirdMessage, locale?: Locale) => string;
LIST_MESSAGE_FILE_TITLE: (message: Sendbird.FileMessage) => string;
LIST_MESSAGE_EDITED_POSTFIX: string;
LIST_MESSAGE_UNKNOWN_TITLE: (message: SendbirdMessage) => string;
LIST_MESSAGE_UNKNOWN_DESC: (message: SendbirdMessage) => string;
/** GroupChannel > Message bubble */
MESSAGE_BUBBLE_TIME: (message: SendbirdMessage, locale?: Locale) => string;
MESSAGE_BUBBLE_FILE_TITLE: (message: Sendbird.FileMessage) => string;
MESSAGE_BUBBLE_EDITED_POSTFIX: string;
MESSAGE_BUBBLE_UNKNOWN_TITLE: (message: SendbirdMessage) => string;
MESSAGE_BUBBLE_UNKNOWN_DESC: (message: SendbirdMessage) => string;

/** GroupChannel > Input */
INPUT_PLACEHOLDER_ACTIVE: string;
Expand Down Expand Up @@ -85,10 +85,10 @@ export interface LabelSet {
/** GroupChannelList > Header */
HEADER_TITLE: string;

/** GroupChannelList > Preview */
PREVIEW_TITLE: (currentUserId: string, channel: Sendbird.GroupChannel) => string;
PREVIEW_TITLE_CAPTION: (channel: Sendbird.GroupChannel, locale?: Locale) => string;
PREVIEW_BODY: (channel: Sendbird.GroupChannel) => string;
/** GroupChannelList > Channel preview */
CHANNEL_PREVIEW_TITLE: (currentUserId: string, channel: Sendbird.GroupChannel) => string;
CHANNEL_PREVIEW_TITLE_CAPTION: (channel: Sendbird.GroupChannel, locale?: Locale) => string;
CHANNEL_PREVIEW_BODY: (channel: Sendbird.GroupChannel) => string;

/** GroupChannelList > TypeSelector > Header */
TYPE_SELECTOR_HEADER_TITLE: string;
Expand Down Expand Up @@ -174,144 +174,147 @@ type LabelCreateOptions = {
* @param {LabelCreateOptions.dateLocale} dateLocale Date locale (from date-fns)
* @param {LabelCreateOptions.overrides} [overrides] Localized label strings
* */
export const createBaseLabel = ({ dateLocale, overrides }: LabelCreateOptions): LabelSet => ({
GROUP_CHANNEL: {
HEADER_TITLE: (currentUserId, channel) => getGroupChannelTitle(currentUserId, channel, '(No name)'),
LIST_BANNER_FROZEN: 'Channel frozen',
LIST_DATE_SEPARATOR: (date, locale) => dateSeparator(date, locale ?? dateLocale),
LIST_TOOLTIP_NEW_MSG: (newMessages) => `${newMessages.length} new messages`,
export const createBaseLabel = ({ dateLocale, overrides }: LabelCreateOptions): LabelSet => {
const USER_NO_NAME = overrides?.STRINGS?.USER_NO_NAME ?? '(No name)';
return {
GROUP_CHANNEL: {
HEADER_TITLE: (currentUserId, channel) => getGroupChannelTitle(currentUserId, channel, USER_NO_NAME),
LIST_BANNER_FROZEN: 'Channel frozen',
LIST_DATE_SEPARATOR: (date, locale) => dateSeparator(date, locale ?? dateLocale),
LIST_TOOLTIP_NEW_MSG: (newMessages) => `${newMessages.length} new messages`,

LIST_MESSAGE_TIME: (message, locale) => messageTime(new Date(message.createdAt), locale ?? dateLocale),
LIST_MESSAGE_FILE_TITLE: (message) => truncate(message.name, { mode: 'mid', maxLen: 20 }),
LIST_MESSAGE_EDITED_POSTFIX: ' (Edited)',
LIST_MESSAGE_UNKNOWN_TITLE: () => '(Unknown message type)',
LIST_MESSAGE_UNKNOWN_DESC: () => 'Cannot read this message.',
MESSAGE_BUBBLE_TIME: (message, locale) => messageTime(new Date(message.createdAt), locale ?? dateLocale),
MESSAGE_BUBBLE_FILE_TITLE: (message) => truncate(message.name, { mode: 'mid', maxLen: 20 }),
MESSAGE_BUBBLE_EDITED_POSTFIX: ' (Edited)',
MESSAGE_BUBBLE_UNKNOWN_TITLE: () => '(Unknown message type)',
MESSAGE_BUBBLE_UNKNOWN_DESC: () => 'Cannot read this message.',

INPUT_PLACEHOLDER_ACTIVE: 'Enter message',
INPUT_PLACEHOLDER_DISABLED: 'Chat is unavailable in this channel',
INPUT_EDIT_OK: 'Save',
INPUT_EDIT_CANCEL: 'Cancel',
INPUT_PLACEHOLDER_ACTIVE: 'Enter message',
INPUT_PLACEHOLDER_DISABLED: 'Chat is unavailable in this channel',
INPUT_EDIT_OK: 'Save',
INPUT_EDIT_CANCEL: 'Cancel',

DIALOG_MESSAGE_COPY: 'Copy',
DIALOG_MESSAGE_EDIT: 'Edit',
DIALOG_MESSAGE_SAVE: 'Save',
DIALOG_MESSAGE_DELETE: 'Delete',
DIALOG_MESSAGE_DELETE_CONFIRM_TITLE: 'Delete message?',
DIALOG_MESSAGE_DELETE_CONFIRM_OK: 'Delete',
DIALOG_MESSAGE_DELETE_CONFIRM_CANCEL: 'Cancel',
DIALOG_MESSAGE_FAILED_RETRY: 'Retry',
DIALOG_MESSAGE_FAILED_REMOVE: 'Remove',
DIALOG_MESSAGE_COPY: 'Copy',
DIALOG_MESSAGE_EDIT: 'Edit',
DIALOG_MESSAGE_SAVE: 'Save',
DIALOG_MESSAGE_DELETE: 'Delete',
DIALOG_MESSAGE_DELETE_CONFIRM_TITLE: 'Delete message?',
DIALOG_MESSAGE_DELETE_CONFIRM_OK: 'Delete',
DIALOG_MESSAGE_DELETE_CONFIRM_CANCEL: 'Cancel',
DIALOG_MESSAGE_FAILED_RETRY: 'Retry',
DIALOG_MESSAGE_FAILED_REMOVE: 'Remove',

DIALOG_ATTACHMENT_CAMERA: 'Camera',
DIALOG_ATTACHMENT_PHOTO_LIBRARY: 'Photo library',
DIALOG_ATTACHMENT_FILES: 'Files',
...overrides?.GROUP_CHANNEL,
},
GROUP_CHANNEL_INFO: {
HEADER_TITLE: 'Channel information',
HEADER_RIGHT: 'Edit',
MENU_NOTIFICATION: 'Notification',
MENU_MEMBERS: 'Members',
MENU_LEAVE_CHANNEL: 'Leave channel',
DIALOG_CHANGE_NAME: 'Change channel name',
DIALOG_CHANGE_IMAGE: 'Change channel image',
DIALOG_CHANGE_IMAGE_MENU_TITLE: 'Change channel image',
DIALOG_CHANGE_IMAGE_MENU_CAMERA: 'Take photo',
DIALOG_CHANGE_IMAGE_MENU_PHOTO_LIBRARY: 'Choose photo',
DIALOG_CHANGE_NAME_PROMPT_TITLE: 'Change name',
DIALOG_CHANGE_NAME_PROMPT_PLACEHOLDER: 'Enter name',
DIALOG_CHANGE_NAME_PROMPT_OK: 'Save',
DIALOG_CHANGE_NAME_PROMPT_CANCEL: 'Cancel',
...overrides?.GROUP_CHANNEL_INFO,
},
GROUP_CHANNEL_LIST: {
HEADER_TITLE: 'Channels',
PREVIEW_TITLE: (currentUserId, channel) => getGroupChannelTitle(currentUserId, channel, '(No name)'),
PREVIEW_TITLE_CAPTION: (channel, locale) => getGroupChannelPreviewTime(channel, locale ?? dateLocale),
PREVIEW_BODY: (channel) => getGroupChannelLastMessage(channel),
TYPE_SELECTOR_HEADER_TITLE: 'Channel type',
TYPE_SELECTOR_GROUP: 'Group',
TYPE_SELECTOR_SUPER_GROUP: 'Super group',
TYPE_SELECTOR_BROADCAST: 'Broadcast',
DIALOG_CHANNEL_TITLE: (currentUserId, channel) => getGroupChannelTitle(currentUserId, channel, '(No name)'),
DIALOG_CHANNEL_NOTIFICATION: (channel) => {
if (!channel) return '';
if (channel.myPushTriggerOption === 'off') return 'Turn on notifications';
return 'Turn off notifications';
DIALOG_ATTACHMENT_CAMERA: 'Camera',
DIALOG_ATTACHMENT_PHOTO_LIBRARY: 'Photo library',
DIALOG_ATTACHMENT_FILES: 'Files',
...overrides?.GROUP_CHANNEL,
},
DIALOG_CHANNEL_LEAVE: 'Leave channel',
...overrides?.GROUP_CHANNEL_LIST,
},
GROUP_CHANNEL_MEMBERS: {
HEADER_TITLE: 'Members',
USER_BAR_ME_POSTFIX: ' (You)',
USER_BAR_OPERATOR: 'Operator',
DIALOG_USER_DISMISS_OPERATOR: 'Dismiss operator',
DIALOG_USER_MUTE: 'Mute',
DIALOG_USER_BAN: 'Ban',
...overrides?.GROUP_CHANNEL_MEMBERS,
},
GROUP_CHANNEL_CREATE: {
HEADER_TITLE: 'Select members',
HEADER_RIGHT: ({ selectedUsers }) => {
const len = selectedUsers.length;
if (len === 0) return 'Create';
return `${len} Create`;
GROUP_CHANNEL_INFO: {
HEADER_TITLE: 'Channel information',
HEADER_RIGHT: 'Edit',
MENU_NOTIFICATION: 'Notification',
MENU_MEMBERS: 'Members',
MENU_LEAVE_CHANNEL: 'Leave channel',
DIALOG_CHANGE_NAME: 'Change channel name',
DIALOG_CHANGE_NAME_PROMPT_TITLE: 'Change name',
DIALOG_CHANGE_NAME_PROMPT_PLACEHOLDER: 'Enter name',
DIALOG_CHANGE_NAME_PROMPT_OK: 'Save',
DIALOG_CHANGE_NAME_PROMPT_CANCEL: 'Cancel',
DIALOG_CHANGE_IMAGE: 'Change channel image',
DIALOG_CHANGE_IMAGE_MENU_TITLE: 'Change channel image',
DIALOG_CHANGE_IMAGE_MENU_CAMERA: 'Take photo',
DIALOG_CHANGE_IMAGE_MENU_PHOTO_LIBRARY: 'Choose photo',
...overrides?.GROUP_CHANNEL_INFO,
},
...overrides?.GROUP_CHANNEL_CREATE,
},
GROUP_CHANNEL_INVITE: {
HEADER_TITLE: 'Invite members',
HEADER_RIGHT: ({ selectedUsers }) => {
const len = selectedUsers.length;
if (len === 0) return 'Invite';
return `${len} Invite`;
GROUP_CHANNEL_LIST: {
HEADER_TITLE: 'Channels',
CHANNEL_PREVIEW_TITLE: (currentUserId, channel) => getGroupChannelTitle(currentUserId, channel, USER_NO_NAME),
CHANNEL_PREVIEW_TITLE_CAPTION: (channel, locale) => getGroupChannelPreviewTime(channel, locale ?? dateLocale),
CHANNEL_PREVIEW_BODY: (channel) => getGroupChannelLastMessage(channel),
TYPE_SELECTOR_HEADER_TITLE: 'Channel type',
TYPE_SELECTOR_GROUP: 'Group',
TYPE_SELECTOR_SUPER_GROUP: 'Super group',
TYPE_SELECTOR_BROADCAST: 'Broadcast',
DIALOG_CHANNEL_TITLE: (currentUserId, channel) => getGroupChannelTitle(currentUserId, channel, USER_NO_NAME),
DIALOG_CHANNEL_NOTIFICATION: (channel) => {
if (!channel) return '';
if (channel.myPushTriggerOption === 'off') return 'Turn on notifications';
return 'Turn off notifications';
},
DIALOG_CHANNEL_LEAVE: 'Leave channel',
...overrides?.GROUP_CHANNEL_LIST,
},
...overrides?.GROUP_CHANNEL_INVITE,
},
STRINGS: {
USER_NO_NAME: '(No name)',
TYPING_INDICATOR_TYPINGS: (users, NO_NAME = '(No name)') => {
const userNames = users.map((u) => u.nickname || NO_NAME);
if (userNames.length === 0) return;
if (userNames.length === 1) return `${userNames[0]} is typing...`;
if (users.length === 2) return `${userNames.join(' and ')} are typing...`;
return 'Several people are typing...';
GROUP_CHANNEL_MEMBERS: {
HEADER_TITLE: 'Members',
USER_BAR_ME_POSTFIX: ' (You)',
USER_BAR_OPERATOR: 'Operator',
DIALOG_USER_DISMISS_OPERATOR: 'Dismiss operator',
DIALOG_USER_MUTE: 'Mute',
DIALOG_USER_BAN: 'Ban',
...overrides?.GROUP_CHANNEL_MEMBERS,
},
...overrides?.STRINGS,
},
PLACEHOLDER: {
NO_BANNED_MEMBERS: 'No banned members',
NO_CHANNELS: 'There are no channels',
NO_MESSAGES: 'There are no messages',
NO_MUTED_MEMBERS: 'No muted members',
NO_RESULTS_FOUND: 'No results found',
...overrides?.PLACEHOLDER,
ERROR_SOMETHING_IS_WRONG: {
MESSAGE: 'Something is wrong',
RETRY_LABEL: 'Retry',
...overrides?.PLACEHOLDER?.ERROR_SOMETHING_IS_WRONG,
GROUP_CHANNEL_CREATE: {
HEADER_TITLE: 'Select members',
HEADER_RIGHT: ({ selectedUsers }) => {
const len = selectedUsers.length;
if (len === 0) return 'Create';
return `${len} Create`;
},
...overrides?.GROUP_CHANNEL_CREATE,
},
},
DIALOG: {
ALERT_DEFAULT_OK: 'OK',
PROMPT_DEFAULT_OK: 'Submit',
PROMPT_DEFAULT_CANCEL: 'Cancel',
PROMPT_DEFAULT_PLACEHOLDER: 'Enter',
...overrides?.DIALOG,
},
TOAST: {
COPY_OK: 'Copied',
DOWNLOAD_START: 'Downloading...',
DOWNLOAD_OK: 'File saved',
DOWNLOAD_ERROR: "Couldn't download file.",
OPEN_CAMERA_ERROR: "Couldn't open camera.",
OPEN_FILES_ERROR: "Couldn't open files.",
OPEN_PHOTO_LIBRARY_ERROR: "Couldn't open photo library.",
DELETE_MSG_ERROR: "Couldn't delete message.",
RESEND_MSG_ERROR: "Couldn't send message.",
SEND_MSG_ERROR: "Couldn't send message.",
UPDATE_MSG_ERROR: "Couldn't edit message.",
...overrides?.TOAST,
},
});
GROUP_CHANNEL_INVITE: {
HEADER_TITLE: 'Invite members',
HEADER_RIGHT: ({ selectedUsers }) => {
const len = selectedUsers.length;
if (len === 0) return 'Invite';
return `${len} Invite`;
},
...overrides?.GROUP_CHANNEL_INVITE,
},
STRINGS: {
USER_NO_NAME,
TYPING_INDICATOR_TYPINGS: (users, NO_NAME = USER_NO_NAME) => {
const userNames = users.map((u) => u.nickname || NO_NAME);
if (userNames.length === 0) return;
if (userNames.length === 1) return `${userNames[0]} is typing...`;
if (users.length === 2) return `${userNames.join(' and ')} are typing...`;
return 'Several people are typing...';
},
...overrides?.STRINGS,
},
PLACEHOLDER: {
NO_BANNED_MEMBERS: 'No banned members',
NO_CHANNELS: 'There are no channels',
NO_MESSAGES: 'There are no messages',
NO_MUTED_MEMBERS: 'No muted members',
NO_RESULTS_FOUND: 'No results found',
...overrides?.PLACEHOLDER,
ERROR_SOMETHING_IS_WRONG: {
MESSAGE: 'Something is wrong',
RETRY_LABEL: 'Retry',
...overrides?.PLACEHOLDER?.ERROR_SOMETHING_IS_WRONG,
},
},
DIALOG: {
ALERT_DEFAULT_OK: 'OK',
PROMPT_DEFAULT_OK: 'Submit',
PROMPT_DEFAULT_CANCEL: 'Cancel',
PROMPT_DEFAULT_PLACEHOLDER: 'Enter',
...overrides?.DIALOG,
},
TOAST: {
COPY_OK: 'Copied',
DOWNLOAD_START: 'Downloading...',
DOWNLOAD_OK: 'File saved',
DOWNLOAD_ERROR: "Couldn't download file.",
OPEN_CAMERA_ERROR: "Couldn't open camera.",
OPEN_FILES_ERROR: "Couldn't open files.",
OPEN_PHOTO_LIBRARY_ERROR: "Couldn't open photo library.",
DELETE_MSG_ERROR: "Couldn't delete message.",
RESEND_MSG_ERROR: "Couldn't send message.",
SEND_MSG_ERROR: "Couldn't send message.",
UPDATE_MSG_ERROR: "Couldn't edit message.",
...overrides?.TOAST,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ const createGroupChannelListFragment = (initModule?: Partial<GroupChannelListMod
],
)}
coverUrl={channel.coverUrl}
title={LABEL.GROUP_CHANNEL_LIST.PREVIEW_TITLE(currentUser?.userId ?? '', channel)}
titleCaption={LABEL.GROUP_CHANNEL_LIST.PREVIEW_TITLE_CAPTION(channel)}
body={LABEL.GROUP_CHANNEL_LIST.PREVIEW_BODY(channel)}
title={LABEL.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_TITLE(currentUser?.userId ?? '', channel)}
titleCaption={LABEL.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_TITLE_CAPTION(channel)}
body={LABEL.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_BODY(channel)}
badgeCount={channel.unreadMessageCount}
bodyIcon={channel.lastMessage?.isFileMessage() ? 'file-document' : undefined}
frozen={channel.isFrozen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const BaseFileMessage: React.FC<FileMessageProps & { type: 'image' | 'audio' | '
containerStyle={{ backgroundColor: colors.background, padding: 2, borderRadius: 8, marginRight: 8 }}
/>
<Text numberOfLines={1} body3 color={color.textMsg}>
{LABEL.GROUP_CHANNEL.LIST_MESSAGE_FILE_TITLE(message)}
{LABEL.GROUP_CHANNEL.MESSAGE_BUBBLE_FILE_TITLE(message)}
</Text>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const MessageTime: React.FC<Props> = ({ message, grouping, style }) => {
return (
<View style={style}>
<Text caption4 color={colors.ui.message.incoming.enabled.textTime}>
{LABEL.GROUP_CHANNEL.LIST_MESSAGE_TIME(message)}
{LABEL.GROUP_CHANNEL.MESSAGE_BUBBLE_TIME(message)}
</Text>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ const UnknownMessage: React.FC<UnknownMessageProps> = ({ message, variant, press
return (
<View style={[styles.container, { backgroundColor: color.background }]}>
<Text body3 color={colors.onBackground01}>
{LABEL.GROUP_CHANNEL.LIST_MESSAGE_UNKNOWN_TITLE(message)}
{LABEL.GROUP_CHANNEL.MESSAGE_BUBBLE_UNKNOWN_TITLE(message)}
</Text>
<Text body3 color={colors.onBackground02}>
{LABEL.GROUP_CHANNEL.LIST_MESSAGE_UNKNOWN_DESC(message)}
{LABEL.GROUP_CHANNEL.MESSAGE_BUBBLE_UNKNOWN_DESC(message)}
</Text>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const BaseUserMessage: React.FC<UserMessageProps> = ({ message, variant, pressed
{message.message}
{Boolean(message.updatedAt) && (
<Text body3 color={color.textEdited}>
{LABEL.GROUP_CHANNEL.LIST_MESSAGE_EDITED_POSTFIX}
{LABEL.GROUP_CHANNEL.MESSAGE_BUBBLE_EDITED_POSTFIX}
</Text>
)}
</URLParsedText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const OpenGraphUserMessage: React.FC<Props> = ({ message, variant, pressed, ogMe
{message.message}
{Boolean(message.updatedAt) && (
<Text body3 color={color.textEdited}>
{LABEL.GROUP_CHANNEL.LIST_MESSAGE_EDITED_POSTFIX}
{LABEL.GROUP_CHANNEL.MESSAGE_BUBBLE_EDITED_POSTFIX}
</Text>
)}
</URLParsedText>
Expand Down

0 comments on commit 003d46d

Please sign in to comment.