Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply localization to all hard coded text #2718

Merged
merged 3 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 0 additions & 13 deletions src/CONST.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ const CONST = {
SWITCH_REPORT: 'switch_report',
COLD: 'cold',
},
MESSAGES: {
// eslint-disable-next-line max-len
NO_PHONE_NUMBER: 'Please enter a phone number including the country code e.g +447814266907',
MAXIMUM_PARTICIPANTS_REACHED: 'You\'ve reached the maximum number of participants for a group chat.',
},
PRIORITY_MODE: {
GSD: 'gsd',
DEFAULT: 'default',
Expand All @@ -84,14 +79,6 @@ const CONST = {
},
DEFAULT_TIME_ZONE: {automatic: true, selected: 'America/Los_Angeles'},
DEFAULT_ACCOUNT_DATA: {error: '', success: '', loading: false},
PRONOUNS: {
HE_HIM_HIS: 'He/him',
SHE_HER_HERS: 'She/her',
THEY_THEM_THEIRS: 'They/them',
ZE_HIR_HIRS: 'Ze/hir',
SELF_SELECT: 'Self-select',
CALL_ME_BY_MY_NAME: 'Call me by my name',
},
APP_STATE: {
ACTIVE: 'active',
BACKGROUND: 'background',
Expand Down
3 changes: 3 additions & 0 deletions src/ONYXKEYS.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ export default {
REPORT_USER_IS_TYPING: 'reportUserIsTyping_',
REPORT_IOUS: 'reportIOUs_',
},

// Indicates which locale should be used
PREFERRED_LOCALE: 'preferredLocale',
};
6 changes: 5 additions & 1 deletion src/components/AttachmentModal.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import compose from '../libs/compose';
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions';
import HeaderWithCloseButton from './HeaderWithCloseButton';
import fileDownload from '../libs/fileDownload';
import withLocalize, {withLocalizePropTypes} from './withLocalize';

/**
* Modal render prop component that exposes modal launching triggers that can be used
Expand Down Expand Up @@ -46,6 +47,8 @@ const propTypes = {
authToken: PropTypes.string.isRequired,
}).isRequired,

...withLocalizePropTypes,

...windowDimensionsPropTypes,
};

Expand Down Expand Up @@ -133,7 +136,7 @@ class AttachmentModal extends PureComponent {
styles.buttonConfirmText,
]}
>
Upload
{this.props.translate('common.upload')}
</Text>
</TouchableOpacity>
)}
Expand Down Expand Up @@ -165,4 +168,5 @@ export default compose(
key: ONYXKEYS.SESSION,
},
}),
withLocalize,
)(AttachmentModal);
168 changes: 87 additions & 81 deletions src/components/AttachmentPicker/index.native.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import Popover from '../Popover';
import MenuItem from '../MenuItem';
import {Camera, Gallery, Paperclip} from '../Icon/Expensicons';
import withWindowDimensions, {windowDimensionsPropTypes} from '../withWindowDimensions';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import compose from '../../libs/compose';

const propTypes = {
...basePropTypes,
...windowDimensionsPropTypes,
...withLocalizePropTypes,
};

/**
Expand All @@ -34,80 +37,6 @@ const documentPickerOptions = {
type: [RNDocumentPicker.types.allFiles],
};

/**
* Inform the users when they need to grant camera access and guide them to settings
*/
function showPermissionsAlert() {
Alert.alert(
'Camera Permission Required',
'Expensify.cash does not have access to your camera, please enable the permission and try again.',
[
{
text: 'Cancel',
style: 'cancel',
},
{
text: 'Settings',
onPress: () => Linking.openSettings(),
},
],
{cancelable: false},
);
}

/**
* A generic handling when we don't know the exact reason for an error
*
*/
function showGeneralAlert() {
Alert.alert(
'Attachment Error',
'An error occurred while selecting an attachment, please try again',
);
}

/**
* Launch the DocumentPicker. Results are in the same format as ImagePicker
*
* @returns {Promise<DocumentPickerResponse>}
*/
function showDocumentPicker() {
return RNDocumentPicker.pick(documentPickerOptions).catch((error) => {
if (!RNDocumentPicker.isCancel(error)) {
showGeneralAlert(error.message);
throw error;
}
});
}

/**
* Common image picker handling
*
* @param {function} imagePickerFunc - RNImagePicker.launchCamera or RNImagePicker.launchImageLibrary
* @returns {Promise<ImagePickerResponse>}
*/
function showImagePicker(imagePickerFunc) {
return new Promise((resolve, reject) => {
imagePickerFunc(imagePickerOptions, (response) => {
if (response.error) {
switch (response.error) {
case 'Camera permissions not granted':
case 'Permissions weren\'t granted':
showPermissionsAlert();
break;
default:
showGeneralAlert(response.error);
break;
}

reject(new Error(`Error during attachment selection: ${response.error}`));
}

resolve(response);
});
});
}

/**
* The data returned from `show` is different on web and mobile, so use this function to ensure the data we
* send to the xhr will be handled properly.
Expand Down Expand Up @@ -142,18 +71,18 @@ class AttachmentPicker extends Component {
this.menuItemData = [
{
icon: Camera,
text: 'Take Photo',
pickAttachment: () => showImagePicker(RNImagePicker.launchCamera),
text: this.props.translate('attachmentPicker.takePhoto'),
pickAttachment: () => this.showImagePicker(RNImagePicker.launchCamera),
},
{
icon: Gallery,
text: 'Choose from Gallery',
pickAttachment: () => showImagePicker(RNImagePicker.launchImageLibrary),
text: this.props.translate('attachmentPicker.chooseFromGallery'),
pickAttachment: () => this.showImagePicker(RNImagePicker.launchImageLibrary),
},
{
icon: Paperclip,
text: 'Choose Document',
pickAttachment: showDocumentPicker,
text: this.props.translate('attachmentPicker.chooseDocument'),
pickAttachment: this.showDocumentPicker,
eVoloshchak marked this conversation as resolved.
Show resolved Hide resolved
},
];

Expand All @@ -174,6 +103,80 @@ class AttachmentPicker extends Component {
}
}

/**
* Inform the users when they need to grant camera access and guide them to settings
*/
showPermissionsAlert() {
Alert.alert(
this.props.translate('attachmentPicker.cameraPermissionRequired'),
this.props.translate('attachmentPicker.expensifyDoesntHaveAccessToCamera'),
[
{
text: this.props.translate('common.cancel'),
style: 'cancel',
},
{
text: this.props.translate('common.settings'),
Copy link
Contributor

Choose a reason for hiding this comment

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

No such key common.settings in languages/en: https://github.com/Expensify/Expensify.cash/pull/2718/files#diff-22037c1e4dbdea8803b450b3fce06e6c475762a31ecf84b34dc264ba0e443637R3

If it ever becomes the case that the user revoked camera permissions the app will seem to do nothing when they press on "Add Attachment" -> "Take Photo".
While the app actually throws an error here

Revoked.Camera.Permissions.mp4

The problem will be worse if the user selects "Deny & don't ask" as nothing would seem to happen after you press on "Take Photo"

  • Expected: When the app lacks permissions to take photos for some reason it should show alert message explaining why the "Take Photo" button doesn't work
  • Actual: Pressing "Take Photo" does nothing

onPress: () => Linking.openSettings(),
},
],
{cancelable: false},
);
}

/**
* Common image picker handling
*
* @param {function} imagePickerFunc - RNImagePicker.launchCamera or RNImagePicker.launchImageLibrary
* @returns {Promise<ImagePickerResponse>}
*/
showImagePicker(imagePickerFunc) {
return new Promise((resolve, reject) => {
imagePickerFunc(imagePickerOptions, (response) => {
if (response.error) {
switch (response.error) {
case 'Camera permissions not granted':
case 'Permissions weren\'t granted':
this.showPermissionsAlert();
break;
default:
this.showGeneralAlert(response.error);
break;
}
const errorDescription = this.props.translate('attachmentPicker.errorDuringAttachmentSelection');
reject(new Error(`${errorDescription}: ${response.error}`));
eVoloshchak marked this conversation as resolved.
Show resolved Hide resolved
}

resolve(response);
});
});
}

/**
* A generic handling when we don't know the exact reason for an error
*
*/
showGeneralAlert() {
Alert.alert(
this.props.translate('attachmentPicker.attachmentError'),
this.props.translate('attachmentPicker.errorWhileSelectingAttachment'),
);
}

/**
* Launch the DocumentPicker. Results are in the same format as ImagePicker
*
* @returns {Promise<DocumentPickerResponse>}
*/
showDocumentPicker() {
return RNDocumentPicker.pick(documentPickerOptions).catch((error) => {
if (!RNDocumentPicker.isCancel(error)) {
this.showGeneralAlert(error.message);
throw error;
}
});
}

/**
* Triggers the `onPicked` callback with the selected attachment
*/
Expand Down Expand Up @@ -247,4 +250,7 @@ class AttachmentPicker extends Component {

AttachmentPicker.propTypes = propTypes;
AttachmentPicker.displayName = 'AttachmentPicker';
export default withWindowDimensions(AttachmentPicker);
export default compose(
withWindowDimensions,
withLocalize,
)(AttachmentPicker);
14 changes: 11 additions & 3 deletions src/components/AttachmentView.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import PDFView from './PDFView';
import ImageView from './ImageView';
import Icon from './Icon';
import {Paperclip} from './Icon/Expensicons';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import compose from '../libs/compose';

const propTypes = {
// URL to full-sized attachment
Expand All @@ -15,18 +17,21 @@ const propTypes = {
file: PropTypes.shape({
name: PropTypes.string,
}),

...withLocalizePropTypes,
};

const defaultProps = {
file: {
name: 'Unknown Filename',
name: '',
},
};

const AttachmentView = (props) => {
// Check both sourceURL and file.name since PDFs dragged into the the text field
// will appear with a sourceURL that is a blob
if (Str.isPDF(props.sourceURL) || (props.file && Str.isPDF(props.file.name))) {
if (Str.isPDF(props.sourceURL)
|| (props.file && Str.isPDF(props.file.name || props.translate('attachmentView.unknownFilename')))) {
return (
<PDFView
sourceURL={props.sourceURL}
Expand Down Expand Up @@ -59,4 +64,7 @@ AttachmentView.propTypes = propTypes;
AttachmentView.defaultProps = defaultProps;
AttachmentView.displayName = 'AttachmentView';

export default memo(AttachmentView);
export default compose(
memo,
withLocalize,
)(AttachmentView);
17 changes: 12 additions & 5 deletions src/components/ConfirmModal.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Modal from './Modal';
import styles from '../styles/styles';
import CONST from '../CONST';
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import compose from '../libs/compose';

const propTypes = {
/** Title of the modal */
Expand All @@ -31,12 +33,14 @@ const propTypes = {
/** Modal content text */
prompt: PropTypes.string,

...withLocalizePropTypes,

...windowDimensionsPropTypes,
};

const defaultProps = {
confirmText: 'Yes',
cancelText: 'No',
confirmText: '',
cancelText: '',
prompt: '',
};

Expand Down Expand Up @@ -68,7 +72,7 @@ const ConfirmModal = props => (
styles.buttonSuccessText,
]}
>
{props.confirmText}
{props.confirmText || props.translate('common.yes')}
</Text>
</TouchableOpacity>

Expand All @@ -77,7 +81,7 @@ const ConfirmModal = props => (
onPress={props.onCancel}
>
<Text style={styles.buttonText}>
{props.cancelText}
{props.cancelText || props.translate('common.no')}
</Text>
</TouchableOpacity>
</View>
Expand All @@ -87,4 +91,7 @@ const ConfirmModal = props => (
ConfirmModal.propTypes = propTypes;
ConfirmModal.defaultProps = defaultProps;
ConfirmModal.displayName = 'ConfirmModal';
export default withWindowDimensions(ConfirmModal);
export default compose(
withWindowDimensions,
withLocalize,
)(ConfirmModal);
Loading