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

Re-add internationalization beta #5256

Merged
merged 1 commit into from
Sep 15, 2021
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: 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,
};