From fc91bf8781e65ce1dc946363dbb10419a145c66b Mon Sep 17 00:00:00 2001 From: tiuweehan <39181981+tiuweehan@users.noreply.github.com> Date: Tue, 4 Feb 2020 20:49:47 +0800 Subject: [PATCH] fix(locale): remove hard coded strings (#3193) --- .gitignore | 3 +- .../src/AuthenticationPage.js | 5 +- .../src/AuthenticationPage.js | 11 +++-- .../src/AuthenticationPage.js | 6 ++- .../src/AuthenticationPage.js | 5 +- .../src/AuthenticationPage.js | 5 +- .../Editor/EditorControlPane/EditorControl.js | 4 +- packages/netlify-cms-locales/src/en/index.js | 22 +++++++++ packages/netlify-cms-locales/src/ja/index.js | 14 ++++++ packages/netlify-cms-locales/src/pl/index.js | 5 ++ .../src/withFileControl.js | 46 ++++++++++--------- .../src/MarkdownControl/RawEditor.js | 5 +- .../src/MarkdownControl/Toolbar.js | 8 +++- .../src/MarkdownControl/VisualEditor.js | 4 +- .../src/MarkdownControl/index.js | 4 ++ 15 files changed, 108 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index c86e9acb..b4a1f70e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ npm-debug.log .tern-project yarn-error.log .vscode/ +.idea/ manifest.yml .imdone/ website/data/contributors.json @@ -18,4 +19,4 @@ coverage/ *.log .env .temp/ -storybook-static/ \ No newline at end of file +storybook-static/ diff --git a/packages/netlify-cms-backend-bitbucket/src/AuthenticationPage.js b/packages/netlify-cms-backend-bitbucket/src/AuthenticationPage.js index 9dd5fc9d..c6f4cef1 100644 --- a/packages/netlify-cms-backend-bitbucket/src/AuthenticationPage.js +++ b/packages/netlify-cms-backend-bitbucket/src/AuthenticationPage.js @@ -17,6 +17,7 @@ export default class BitbucketAuthenticationPage extends React.Component { authEndpoint: PropTypes.string, config: PropTypes.object.isRequired, clearHash: PropTypes.func, + t: PropTypes.func.isRequired, }; state = {}; @@ -70,7 +71,7 @@ export default class BitbucketAuthenticationPage extends React.Component { }; render() { - const { inProgress, config } = this.props; + const { inProgress, config, t } = this.props; return ( ( - {inProgress ? 'Logging in...' : 'Login with Bitbucket'} + {inProgress ? t('auth.loggingIn') : t('auth.loginWithBitbucket')} )} /> diff --git a/packages/netlify-cms-backend-github/src/AuthenticationPage.js b/packages/netlify-cms-backend-github/src/AuthenticationPage.js index 7cdd4665..26736dfa 100644 --- a/packages/netlify-cms-backend-github/src/AuthenticationPage.js +++ b/packages/netlify-cms-backend-github/src/AuthenticationPage.js @@ -29,6 +29,7 @@ export default class GitHubAuthenticationPage extends React.Component { authEndpoint: PropTypes.string, config: PropTypes.object.isRequired, clearHash: PropTypes.func, + t: PropTypes.func.isRequired, }; state = {}; @@ -92,15 +93,17 @@ export default class GitHubAuthenticationPage extends React.Component { }); }; - renderLoginButton = () => - this.props.inProgress || this.state.findingFork ? ( - 'Logging in...' + renderLoginButton = () => { + const { inProgress, t } = this.props; + return inProgress || this.state.findingFork ? ( + t('auth.loggingIn') ) : ( - {' Login with GitHub'} + {t('auth.loginWithGitHub')} ); + }; getAuthenticationPageRenderArgs() { const { requestingFork } = this.state; diff --git a/packages/netlify-cms-backend-gitlab/src/AuthenticationPage.js b/packages/netlify-cms-backend-gitlab/src/AuthenticationPage.js index a0c1e2ae..04e4cd19 100644 --- a/packages/netlify-cms-backend-gitlab/src/AuthenticationPage.js +++ b/packages/netlify-cms-backend-gitlab/src/AuthenticationPage.js @@ -17,6 +17,7 @@ export default class GitLabAuthenticationPage extends React.Component { authEndpoint: PropTypes.string, config: PropTypes.object.isRequired, clearHash: PropTypes.func, + t: PropTypes.func.isRequired, }; state = {}; @@ -68,7 +69,7 @@ export default class GitLabAuthenticationPage extends React.Component { }; render() { - const { inProgress, config } = this.props; + const { inProgress, config, t } = this.props; return ( ( - {inProgress ? 'Logging in...' : 'Login with GitLab'} + {' '} + {inProgress ? t('auth.loggingIn') : t('auth.loginWithGitLab')} )} /> diff --git a/packages/netlify-cms-backend-proxy/src/AuthenticationPage.js b/packages/netlify-cms-backend-proxy/src/AuthenticationPage.js index 4e79ab44..4c41ca9c 100644 --- a/packages/netlify-cms-backend-proxy/src/AuthenticationPage.js +++ b/packages/netlify-cms-backend-proxy/src/AuthenticationPage.js @@ -38,6 +38,7 @@ export default class AuthenticationPage extends React.Component { onLogin: PropTypes.func.isRequired, inProgress: PropTypes.bool, config: PropTypes.object.isRequired, + t: PropTypes.func.isRequired, }; handleLogin = e => { @@ -46,13 +47,13 @@ export default class AuthenticationPage extends React.Component { }; render() { - const { config, inProgress } = this.props; + const { config, inProgress, t } = this.props; return ( - {inProgress ? 'Logging in...' : 'Login'} + {inProgress ? t('auth.loggingIn') : t('auth.login')} {config.site_url && } diff --git a/packages/netlify-cms-backend-test/src/AuthenticationPage.js b/packages/netlify-cms-backend-test/src/AuthenticationPage.js index d1561a7e..21074233 100644 --- a/packages/netlify-cms-backend-test/src/AuthenticationPage.js +++ b/packages/netlify-cms-backend-test/src/AuthenticationPage.js @@ -38,6 +38,7 @@ export default class AuthenticationPage extends React.Component { onLogin: PropTypes.func.isRequired, inProgress: PropTypes.bool, config: PropTypes.object.isRequired, + t: PropTypes.func.isRequired, }; componentDidMount() { @@ -56,13 +57,13 @@ export default class AuthenticationPage extends React.Component { }; render() { - const { config, inProgress } = this.props; + const { config, inProgress, t } = this.props; return ( - {inProgress ? 'Logging in...' : 'Login'} + {inProgress ? t('auth.loggingIn') : t('auth.login')} {config.site_url && } diff --git a/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js b/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js index 04f5c1f4..3b29443c 100644 --- a/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js +++ b/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js @@ -182,7 +182,9 @@ class EditorControl extends React.Component { hasErrors={!!errors} htmlFor={this.uniqueFieldId} > - {`${field.get('label', field.get('name'))}${isFieldOptional ? ' (optional)' : ''}`} + {`${field.get('label', field.get('name'))}${ + isFieldOptional ? ` (${t('editor.editorControl.field.optional')})` : '' + }`} ( -
- {forImage ? this.renderImages() : null} + renderSelection = subject => { + const { t } = this.props; + return (
- {forImage ? null : this.renderFileLinks()} - - Choose different {subject} - - - Remove {subject} - + {forImage ? this.renderImages() : null} +
+ {forImage ? null : this.renderFileLinks()} + + {t(`editor.editorWidgets.${subject}.chooseDifferent`)} + + + {t(`editor.editorWidgets.${subject}.remove`)} + +
-
- ); + ); + }; - renderNoSelection = (subject, article) => ( - - Choose {article} {subject} - - ); + renderNoSelection = subject => { + const { t } = this.props; + return ( + + {t(`editor.editorWidgets.${subject}.choose`)} + + ); + }; render() { const { value, classNameWrapper } = this.props; const subject = forImage ? 'image' : 'file'; - const article = forImage ? 'an' : 'a'; return (
- - {value ? this.renderSelection(subject) : this.renderNoSelection(subject, article)} - + {value ? this.renderSelection(subject) : this.renderNoSelection(subject)}
); } diff --git a/packages/netlify-cms-widget-markdown/src/MarkdownControl/RawEditor.js b/packages/netlify-cms-widget-markdown/src/MarkdownControl/RawEditor.js index 83b36973..45d3e78b 100644 --- a/packages/netlify-cms-widget-markdown/src/MarkdownControl/RawEditor.js +++ b/packages/netlify-cms-widget-markdown/src/MarkdownControl/RawEditor.js @@ -101,7 +101,7 @@ export default class RawEditor extends React.Component { }; render() { - const { className, field } = this.props; + const { className, field, t } = this.props; return ( @@ -110,6 +110,7 @@ export default class RawEditor extends React.Component { buttons={field.get('buttons')} disabled rawMode + t={t} /> @@ -127,6 +128,7 @@ export default class RawEditor extends React.Component { onCut={this.handleCut} onCopy={this.handleCopy} ref={this.processRef} + t={t} /> )} @@ -141,4 +143,5 @@ RawEditor.propTypes = { className: PropTypes.string.isRequired, value: PropTypes.string, field: ImmutablePropTypes.map.isRequired, + t: PropTypes.func.isRequired, }; diff --git a/packages/netlify-cms-widget-markdown/src/MarkdownControl/Toolbar.js b/packages/netlify-cms-widget-markdown/src/MarkdownControl/Toolbar.js index aeeb20ba..5d805376 100644 --- a/packages/netlify-cms-widget-markdown/src/MarkdownControl/Toolbar.js +++ b/packages/netlify-cms-widget-markdown/src/MarkdownControl/Toolbar.js @@ -83,6 +83,7 @@ export default class Toolbar extends React.Component { hasMark: PropTypes.func, hasInline: PropTypes.func, hasBlock: PropTypes.func, + t: PropTypes.func.isRequired, }; isHidden = button => { @@ -113,6 +114,7 @@ export default class Toolbar extends React.Component { hasMark = () => {}, hasInline = () => {}, hasBlock = () => {}, + t, } = this.props; return ( @@ -246,10 +248,12 @@ export default class Toolbar extends React.Component { - Rich Text + {t('editor.editorWidgets.markdown.richText')} - Markdown + + {t('editor.editorWidgets.markdown.markdown')} + ); diff --git a/packages/netlify-cms-widget-markdown/src/MarkdownControl/VisualEditor.js b/packages/netlify-cms-widget-markdown/src/MarkdownControl/VisualEditor.js index 16775e74..e5e2732f 100644 --- a/packages/netlify-cms-widget-markdown/src/MarkdownControl/VisualEditor.js +++ b/packages/netlify-cms-widget-markdown/src/MarkdownControl/VisualEditor.js @@ -82,6 +82,7 @@ export default class Editor extends React.Component { value: PropTypes.string, field: ImmutablePropTypes.map.isRequired, getEditorComponents: PropTypes.func.isRequired, + t: PropTypes.func.isRequired, }; shouldComponentUpdate(nextProps, nextState) { @@ -142,7 +143,7 @@ export default class Editor extends React.Component { }; render() { - const { onAddAsset, getAsset, className, field } = this.props; + const { onAddAsset, getAsset, className, field, t } = this.props; return (
diff --git a/packages/netlify-cms-widget-markdown/src/MarkdownControl/index.js b/packages/netlify-cms-widget-markdown/src/MarkdownControl/index.js index 654af92c..28bdd057 100644 --- a/packages/netlify-cms-widget-markdown/src/MarkdownControl/index.js +++ b/packages/netlify-cms-widget-markdown/src/MarkdownControl/index.js @@ -24,6 +24,7 @@ export default class MarkdownControl extends React.Component { value: PropTypes.string, field: ImmutablePropTypes.map.isRequired, getEditorComponents: PropTypes.func, + t: PropTypes.func.isRequired, }; static defaultProps = { @@ -61,6 +62,7 @@ export default class MarkdownControl extends React.Component { field, getEditorComponents, resolveWidget, + t, } = this.props; const { mode, pendingFocus } = this.state; @@ -77,6 +79,7 @@ export default class MarkdownControl extends React.Component { getEditorComponents={getEditorComponents} resolveWidget={resolveWidget} pendingFocus={pendingFocus && this.setFocusReceived} + t={t} />
); @@ -91,6 +94,7 @@ export default class MarkdownControl extends React.Component { value={value} field={field} pendingFocus={pendingFocus && this.setFocusReceived} + t={t} /> );