Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function OptionRowLHNData({
oneTransactionThreadReport,
reportNameValuePairs,
personalDetails,
preferredLocale: preferredLocale ?? CONST.LOCALES.DEFAULT,
policy,
parentReportAction,
lastMessageTextFromReport,
Expand Down
31 changes: 8 additions & 23 deletions src/components/LocalePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
import React from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import AccountUtils from '@libs/AccountUtils';
import * as App from '@userActions/App';
import {setLocale} from '@userActions/App';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Account, Locale} from '@src/types/onyx';
import Picker from './Picker';
import type {PickerSize} from './Picker/types';

type LocalePickerOnyxProps = {
/** The details about the account that the user is signing in with */
account: OnyxEntry<Account>;

/** Indicates which locale the user currently has selected */
preferredLocale: OnyxEntry<Locale>;
};

type LocalePickerProps = LocalePickerOnyxProps & {
type LocalePickerProps = {
/** Indicates size of a picker component and whether to render the label or not */
size?: PickerSize;
};

function LocalePicker({account, preferredLocale = CONST.LOCALES.DEFAULT, size = 'normal'}: LocalePickerProps) {
function LocalePicker({size = 'normal'}: LocalePickerProps) {
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
const [preferredLocale] = useOnyx(ONYXKEYS.NVP_PREFERRED_LOCALE, {canBeMissing: true});
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false});
const localesToLanguages = CONST.LANGUAGES.map((language) => ({
value: language,
label: translate(`languagePage.languages.${language}.label`),
Expand All @@ -45,7 +37,7 @@ function LocalePicker({account, preferredLocale = CONST.LOCALES.DEFAULT, size =
return;
}

App.setLocale(locale);
setLocale(locale);
}}
isDisabled={shouldDisablePicker}
items={localesToLanguages}
Expand All @@ -61,11 +53,4 @@ function LocalePicker({account, preferredLocale = CONST.LOCALES.DEFAULT, size =

LocalePicker.displayName = 'LocalePicker';

export default withOnyx<LocalePickerProps, LocalePickerOnyxProps>({
account: {
key: ONYXKEYS.ACCOUNT,
},
preferredLocale: {
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
},
})(LocalePicker);
export default LocalePicker;
7 changes: 3 additions & 4 deletions src/components/Reactions/MiniQuickEmojiReactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ function MiniQuickEmojiReactions({reportAction, reportActionID, onEmojiSelected,
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const ref = useRef<View>(null);
const {translate} = useLocalize();
const [preferredLocale] = useOnyx(ONYXKEYS.NVP_PREFERRED_LOCALE, {initialValue: CONST.LOCALES.DEFAULT});
const [preferredSkinTone] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {initialValue: CONST.EMOJI_DEFAULT_SKIN_TONE});
const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {initialValue: {}});
const {translate, preferredLocale} = useLocalize();
const [preferredSkinTone] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true, initialValue: CONST.EMOJI_DEFAULT_SKIN_TONE});
const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true, initialValue: {}});

const openEmojiPicker = () => {
onPressOpenPicker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {Emoji} from '@assets/emojis/types';
import AddReactionBubble from '@components/Reactions/AddReactionBubble';
import EmojiReactionBubble from '@components/Reactions/EmojiReactionBubble';
import Tooltip from '@components/Tooltip';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {getLocalizedEmojiName, getPreferredEmojiCode} from '@libs/EmojiUtils';
import {callFunctionIfActionIsAllowed} from '@userActions/Session';
Expand All @@ -21,9 +22,9 @@ function BaseQuickEmojiReactions({
setIsEmojiPickerActive,
}: BaseQuickEmojiReactionsProps) {
const styles = useThemeStyles();
const [preferredLocale] = useOnyx(ONYXKEYS.NVP_PREFERRED_LOCALE, {initialValue: CONST.LOCALES.DEFAULT});
const [preferredSkinTone] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {initialValue: CONST.EMOJI_DEFAULT_SKIN_TONE});
const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {initialValue: {}});
const {preferredLocale} = useLocalize();
const [preferredSkinTone] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true, initialValue: CONST.EMOJI_DEFAULT_SKIN_TONE});
const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true, initialValue: {}});

return (
<View style={styles.quickReactionsContainer}>
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useSidePanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import KeyboardUtils from '@src/utils/keyboard';
import useLocalize from './useLocalize';
import usePrevious from './usePrevious';
import useResponsiveLayout from './useResponsiveLayout';
import useWindowDimensions from './useWindowDimensions';
Expand All @@ -19,8 +20,8 @@ import useWindowDimensions from './useWindowDimensions';
*/
function useSidePanelDisplayStatus() {
const {isExtraLargeScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const {preferredLocale} = useLocalize();
const [sidePanelNVP] = useOnyx(ONYXKEYS.NVP_SIDE_PANEL, {canBeMissing: true});
const [language] = useOnyx(ONYXKEYS.NVP_PREFERRED_LOCALE, {canBeMissing: true});
const [isModalCenteredVisible = false] = useOnyx(ONYXKEYS.MODAL, {
canBeMissing: true,
selector: (modal) =>
Expand All @@ -30,7 +31,7 @@ function useSidePanelDisplayStatus() {
modal?.type === CONST.MODAL.MODAL_TYPE.CENTERED,
});

const isLanguageUnsupported = language !== CONST.LOCALES.EN;
const isLanguageUnsupported = preferredLocale !== CONST.LOCALES.EN;
const isSidePanelVisible = isExtraLargeScreenWidth ? sidePanelNVP?.open : sidePanelNVP?.openNarrowScreen;

// The Side Panel is hidden when:
Expand Down
17 changes: 3 additions & 14 deletions src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import {setCurrentDate} from './actions/CurrentDate';
import {setNetworkLastOffline} from './actions/Network';
import {translate, translateLocal} from './Localize';
import BaseLocaleListener from './Localize/LocaleListener/BaseLocaleListener';
import Log from './Log';

type CustomStatusTypes = ValueOf<typeof CONST.CUSTOM_STATUS_TYPES>;
Expand Down Expand Up @@ -91,28 +92,16 @@ Onyx.connect({

let isOffline: boolean | undefined;

let preferredLocaleFromOnyx: Locale;

Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
callback: (value) => {
if (!value) {
return;
}
preferredLocaleFromOnyx = value;
},
});

Onyx.connect({
key: ONYXKEYS.NETWORK,
callback: (val) => {
if (!val?.lastOfflineAt) {
setNetworkLastOffline(getLocalDateFromDatetime(preferredLocaleFromOnyx));
setNetworkLastOffline(getLocalDateFromDatetime(BaseLocaleListener.getPreferredLocale()));
}

const newIsOffline = val?.isOffline ?? val?.shouldForceOffline;
if (newIsOffline && isOffline === false) {
setNetworkLastOffline(getLocalDateFromDatetime(preferredLocaleFromOnyx));
setNetworkLastOffline(getLocalDateFromDatetime(BaseLocaleListener.getPreferredLocale()));
}
isOffline = newIsOffline;
},
Expand Down
38 changes: 13 additions & 25 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ import type {
} from '@src/types/onyx';
import type {Attendee, Participant} from '@src/types/onyx/IOU';
import type {Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
import type DeepValueOf from '@src/types/utils/DeepValueOf';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import Timing from './actions/Timing';
import {getEnabledCategoriesCount} from './CategoryUtils';
import filterArrayByMatch from './filterArrayByMatch';
import {isReportMessageAttachment} from './isReportMessageAttachment';
import {formatPhoneNumber} from './LocalePhoneNumber';
import {translate, translateLocal} from './Localize';
import {translateLocal} from './Localize';
import {appendCountryCode, getPhoneNumberWithoutSpecialChars} from './LoginUtils';
import ModifiedExpenseMessage from './ModifiedExpenseMessage';
import Navigation from './Navigation/Navigation';
Expand Down Expand Up @@ -326,17 +325,6 @@ Onyx.connect({
callback: (value) => (allPersonalDetails = isEmptyObject(value) ? {} : value),
});

let preferredLocale: DeepValueOf<typeof CONST.LOCALES> = CONST.LOCALES.DEFAULT;
Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
callback: (value) => {
if (!value) {
return;
}
preferredLocale = value;
},
});

const policies: OnyxCollection<Policy> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
Expand Down Expand Up @@ -617,11 +605,11 @@ function getAlternateText(option: OptionData, {showChatPreviewLine = false, forc
const formattedLastMessageTextWithPrefix = reportPrefix + formattedLastMessageText;

if (isExpenseThread || option.isMoneyRequestReport) {
return showChatPreviewLine && formattedLastMessageText ? formattedLastMessageTextWithPrefix : translate(preferredLocale, 'iou.expense');
return showChatPreviewLine && formattedLastMessageText ? formattedLastMessageTextWithPrefix : translateLocal('iou.expense');
}

if (option.isThread) {
return showChatPreviewLine && formattedLastMessageText ? formattedLastMessageTextWithPrefix : translate(preferredLocale, 'threads.thread');
return showChatPreviewLine && formattedLastMessageText ? formattedLastMessageTextWithPrefix : translateLocal('threads.thread');
}

if (option.isChatRoom && !isAdminRoom && !isAnnounceRoom) {
Expand All @@ -633,11 +621,11 @@ function getAlternateText(option: OptionData, {showChatPreviewLine = false, forc
}

if (option.isTaskReport) {
return showChatPreviewLine && formattedLastMessageText ? formattedLastMessageTextWithPrefix : translate(preferredLocale, 'task.task');
return showChatPreviewLine && formattedLastMessageText ? formattedLastMessageTextWithPrefix : translateLocal('task.task');
}

if (isGroupChat) {
return showChatPreviewLine && formattedLastMessageText ? formattedLastMessageTextWithPrefix : translate(preferredLocale, 'common.group');
return showChatPreviewLine && formattedLastMessageText ? formattedLastMessageTextWithPrefix : translateLocal('common.group');
}

return showChatPreviewLine && formattedLastMessageText
Expand Down Expand Up @@ -725,18 +713,18 @@ function getLastMessageTextForReport(
case CONST.REPORT.ARCHIVE_REASON.ACCOUNT_CLOSED:
case CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY:
case CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED: {
lastMessageTextFromReport = translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, {
lastMessageTextFromReport = translateLocal(`reportArchiveReasons.${archiveReason}`, {
displayName: formatPhoneNumber(getDisplayNameOrDefault(lastActorDetails)),
policyName: getPolicyName({report, policy}),
});
break;
}
case CONST.REPORT.ARCHIVE_REASON.BOOKING_END_DATE_HAS_PASSED: {
lastMessageTextFromReport = translate(preferredLocale, `reportArchiveReasons.${archiveReason}`);
lastMessageTextFromReport = translateLocal(`reportArchiveReasons.${archiveReason}`);
break;
}
default: {
lastMessageTextFromReport = translate(preferredLocale, `reportArchiveReasons.default`);
lastMessageTextFromReport = translateLocal(`reportArchiveReasons.default`);
}
}
} else if (isMoneyRequestAction(lastReportAction)) {
Expand Down Expand Up @@ -2021,22 +2009,22 @@ function getHeaderMessage(hasSelectableOptions: boolean, hasUserToInvite: boolea
const isValidEmail = Str.isValidEmail(searchValue);

if (searchValue && CONST.REGEX.DIGITS_AND_PLUS.test(searchValue) && !isValidPhone && !hasSelectableOptions) {
return translate(preferredLocale, 'messages.errorMessageInvalidPhone');
return translateLocal('messages.errorMessageInvalidPhone');
}

// Without a search value, it would be very confusing to see a search validation message.
// Therefore, this skips the validation when there is no search value.
if (searchValue && !hasSelectableOptions && !hasUserToInvite) {
if (/^\d+$/.test(searchValue) && !isValidPhone) {
return translate(preferredLocale, 'messages.errorMessageInvalidPhone');
return translateLocal('messages.errorMessageInvalidPhone');
}
if (/@/.test(searchValue) && !isValidEmail) {
return translate(preferredLocale, 'messages.errorMessageInvalidEmail');
return translateLocal('messages.errorMessageInvalidEmail');
}
if (hasMatchedParticipant && (isValidEmail || isValidPhone)) {
return '';
}
return translate(preferredLocale, 'common.noResultsFound');
return translateLocal('common.noResultsFound');
}

return '';
Expand All @@ -2047,7 +2035,7 @@ function getHeaderMessage(hasSelectableOptions: boolean, hasUserToInvite: boolea
*/
function getHeaderMessageForNonUserList(hasSelectableOptions: boolean, searchValue: string): string {
if (searchValue && !hasSelectableOptions) {
return translate(preferredLocale, 'common.noResultsFound');
return translateLocal('common.noResultsFound');
}
return '';
}
Expand Down
15 changes: 2 additions & 13 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type Report from '@src/types/onyx/Report';
import type ReportAction from '@src/types/onyx/ReportAction';
import type {Message, OldDotReportAction, OriginalMessage, ReportActions} from '@src/types/onyx/ReportAction';
import type ReportActionName from '@src/types/onyx/ReportActionName';
import type DeepValueOf from '@src/types/utils/DeepValueOf';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {convertToDisplayString} from './CurrencyUtils';
import DateUtils from './DateUtils';
Expand All @@ -27,6 +26,7 @@ import {isReportMessageAttachment} from './isReportMessageAttachment';
import {toLocaleOrdinal} from './LocaleDigitUtils';
import {formatPhoneNumber} from './LocalePhoneNumber';
import {formatMessageElementList, translateLocal} from './Localize';
import BaseLocaleListener from './Localize/LocaleListener/BaseLocaleListener';
import Log from './Log';
import type {MessageElementBase, MessageTextElement} from './MessageElement';
import Parser from './Parser';
Expand Down Expand Up @@ -67,17 +67,6 @@ Onyx.connect({
},
});

let preferredLocale: DeepValueOf<typeof CONST.LOCALES> = CONST.LOCALES.DEFAULT;
Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
callback: (value) => {
if (!value) {
return;
}
preferredLocale = value;
},
});

let allReports: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down Expand Up @@ -2193,7 +2182,7 @@ function getWorkspaceUpdateFieldMessage(action: ReportAction): string {
return translateLocal('workflowsPage.frequencies.lastBusinessDayOfMonth');
}
if (typeof autoReportingOffset === 'number') {
return toLocaleOrdinal(preferredLocale, autoReportingOffset, false);
return toLocaleOrdinal(BaseLocaleListener.getPreferredLocale(), autoReportingOffset, false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not centralize the usage of the preferred locale here by using toLocaleOrdinal from LocaleContextProvider?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a libs file, not a component. I have to centralise the locale using BaseLocaleListener.getPreferredLocale() method only.

}
return '';
};
Expand Down
15 changes: 6 additions & 9 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import type Policy from '@src/types/onyx/Policy';
import type PriorityMode from '@src/types/onyx/PriorityMode';
import type Report from '@src/types/onyx/Report';
import type ReportAction from '@src/types/onyx/ReportAction';
import type DeepValueOf from '@src/types/utils/DeepValueOf';
import {getExpensifyCardFromReportAction} from './CardMessageUtils';
import {extractCollectionItemID} from './CollectionUtils';
import {hasValidDraftComment} from './DraftCommentUtils';
import localeCompare from './LocaleCompare';
import {formatPhoneNumber} from './LocalePhoneNumber';
import {translate, translateLocal} from './Localize';
import {translateLocal} from './Localize';
import {getLastActorDisplayName, getLastMessageTextForReport, getPersonalDetailsForAccountIDs, shouldShowLastActorDisplayName} from './OptionsListUtils';
import Parser from './Parser';
import Performance from './Performance';
Expand Down Expand Up @@ -414,7 +413,6 @@ function getOptionData({
oneTransactionThreadReport,
reportNameValuePairs,
personalDetails,
preferredLocale,
policy,
parentReportAction,
lastMessageTextFromReport: lastMessageTextFromReportProp,
Expand All @@ -424,7 +422,6 @@ function getOptionData({
oneTransactionThreadReport: OnyxEntry<Report>;
reportNameValuePairs: OnyxEntry<ReportNameValuePairs>;
personalDetails: OnyxEntry<PersonalDetailsList>;
preferredLocale: DeepValueOf<typeof CONST.LOCALES>;
policy: OnyxEntry<Policy> | undefined;
parentReportAction: OnyxEntry<ReportAction> | undefined;
lastMessageTextFromReport?: string;
Expand Down Expand Up @@ -587,16 +584,16 @@ function getOptionData({
const targetAccountIDsLength = targetAccountIDs.length !== 0 ? targetAccountIDs.length : (report.lastMessageHtml?.match(/<mention-user[^>]*><\/mention-user>/g)?.length ?? 0);
const verb =
lastActionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM || lastActionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.INVITE_TO_ROOM
? translate(preferredLocale, 'workspace.invite.invited')
: translate(preferredLocale, 'workspace.invite.removed');
const users = translate(preferredLocale, targetAccountIDsLength > 1 ? 'common.members' : 'common.member')?.toLocaleLowerCase();
? translateLocal('workspace.invite.invited')
: translateLocal('workspace.invite.removed');
const users = translateLocal(targetAccountIDsLength > 1 ? 'common.members' : 'common.member')?.toLocaleLowerCase();
result.alternateText = formatReportLastMessageText(`${actorDisplayName ?? lastActorDisplayName} ${verb} ${targetAccountIDsLength} ${users}`);
const roomName = getReportName(allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${lastActionOriginalMessage?.reportID}`]) || lastActionOriginalMessage?.roomName;
if (roomName) {
const preposition =
lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM || lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.INVITE_TO_ROOM
? ` ${translate(preferredLocale, 'workspace.invite.to')}`
: ` ${translate(preferredLocale, 'workspace.invite.from')}`;
? ` ${translateLocal('workspace.invite.to')}`
: ` ${translateLocal('workspace.invite.from')}`;
result.alternateText += `${preposition} ${roomName}`;
}
} else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_NAME)) {
Expand Down
Loading
Loading