Skip to content

Commit

Permalink
Merge pull request #2718 from eVoloshchak/eVoloshchak-localizedString…
Browse files Browse the repository at this point in the history
…s-v2
  • Loading branch information
iwiznia authored May 10, 2021
2 parents 1f44221 + 2685d06 commit c602342
Show file tree
Hide file tree
Showing 50 changed files with 1,061 additions and 515 deletions.
13 changes: 0 additions & 13 deletions src/CONST.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ const CONST = {
COLD: 'cold',
REPORT_ACTION_ITEM_LAYOUT_DEBOUNCE_TIME: 1500,
},
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 @@ -90,14 +85,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,
},
];

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'),
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}`));
}

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

0 comments on commit c602342

Please sign in to comment.