Skip to content

Commit

Permalink
Merge pull request #5256 from Expensify/joe-re-add-internationalizati…
Browse files Browse the repository at this point in the history
…on-beta
  • Loading branch information
roryabraham authored Sep 15, 2021
2 parents 79ba0f2 + 0e6fdbf commit 86bec1b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const CONST = {
FREE_PLAN: 'freePlan',
DEFAULT_ROOMS: 'defaultRooms',
BETA_EXPENSIFY_WALLET: 'expensifyWallet',
INTERNATIONALIZATION: 'internationalization',
},
BUTTON_STATES: {
DEFAULT: 'default',
Expand Down
42 changes: 28 additions & 14 deletions src/components/LocalePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {setLocale} from '../libs/actions/App';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import ONYXKEYS from '../ONYXKEYS';
import CONST from '../CONST';
import Permissions from '../libs/Permissions';
import {translate} from '../libs/translate';
import ExpensiPicker from './ExpensiPicker';

Expand All @@ -16,12 +17,16 @@ const propTypes = {
/** Indicates size of a picker component and whether to render the label or not */
size: PropTypes.oneOf(['normal', 'small']),

/** Beta features list */
betas: PropTypes.arrayOf(PropTypes.string),

...withLocalizePropTypes,
};

const defaultProps = {
preferredLocale: CONST.DEFAULT_LOCALE,
size: 'normal',
betas: [],
};

const localesToLanguages = {
Expand All @@ -37,20 +42,26 @@ const localesToLanguages = {

const LocalePicker = ({
// eslint-disable-next-line no-shadow
preferredLocale, translate, size,
}) => (
<ExpensiPicker
label={size === 'normal' ? translate('preferencesPage.language') : null}
onChange={(locale) => {
if (locale !== preferredLocale) {
setLocale(locale);
}
}}
items={Object.values(localesToLanguages)}
size={size}
value={preferredLocale}
/>
);
preferredLocale, translate, betas, size,
}) => {
if (!Permissions.canUseInternationalization(betas)) {
return null;
}

return (
<ExpensiPicker
label={size === 'normal' ? translate('preferencesPage.language') : null}
onChange={(locale) => {
if (locale !== preferredLocale) {
setLocale(locale);
}
}}
items={Object.values(localesToLanguages)}
size={size}
value={preferredLocale}
/>
);
};

LocalePicker.defaultProps = defaultProps;
LocalePicker.propTypes = propTypes;
Expand All @@ -62,5 +73,8 @@ export default compose(
preferredLocale: {
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
},
betas: {
key: ONYXKEYS.BETAS,
},
}),
)(LocalePicker);
9 changes: 9 additions & 0 deletions src/libs/Permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ function canUseDefaultRooms(betas) {
return _.contains(betas, CONST.BETAS.DEFAULT_ROOMS) || canUseAllBetas(betas);
}

/**
* @param {Array<String>} betas
* @returns {Boolean}
*/
function canUseInternationalization(betas) {
return _.contains(betas, CONST.BETAS.INTERNATIONALIZATION) || canUseAllBetas(betas);
}

/**
* @param {Array<String>} betas
* @returns {Boolean}
Expand All @@ -65,5 +73,6 @@ export default {
canUsePayWithExpensify,
canUseFreePlan,
canUseDefaultRooms,
canUseInternationalization,
canUseWallet,
};

0 comments on commit 86bec1b

Please sign in to comment.