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

feat(core): pass locale to custom preview templates #5912

Merged
merged 1 commit into from
Oct 21, 2021
Merged

feat(core): pass locale to custom preview templates #5912

merged 1 commit into from
Oct 21, 2021

Conversation

delucis
Copy link
Contributor

@delucis delucis commented Oct 20, 2021

Closes #5911

Summary

Pass the currently selected locale to the editor preview pane to allow custom preview templates to adapt to different locales (see #5911).

Test plan

I created a collection in dev-test/config.yml with i18n enabled.

In dev-test/index.html I registered a custom preview template to display the passed locale prop:

CMS.registerPreviewTemplate(
  'posts',
  createClass({
    render() {
      return h('p', {}, this.props.locale);
    },
  }),
);

The locale string displayed in the preview pane and toggling between the locale currently being edited updated the preview string.

I’d love to add an integration test for a custom preview template and check the props it receives, but I couldn’t see any existing tests for this.

Checklist

Please add a x inside each checkbox:

  • I have read the contribution guidelines.
  • Code is formatted via running yarn format.
  • Tests are passing via running yarn test.
  • The status checks are successful (continuous integration). Those can be seen below.

A picture of a cute animal (not mandatory but encouraged)

A locale locust:

locust
By Charles J. Sharp - Own work, from Sharp Photography, sharpphotography, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=59068817

@delucis delucis requested a review from a team October 20, 2021 21:22
@delucis
Copy link
Contributor Author

delucis commented Oct 20, 2021

Netlify Deploy Preview seems to be failing on something unrelated:

lerna ERR! yarn run build exited 1 in 'netlify-cms-backend-bitbucket'

Is this something random or could it be related to my one-line change in front-end code?

@erezrokah erezrokah added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Oct 21, 2021
@erezrokah erezrokah mentioned this pull request Oct 21, 2021
@erezrokah
Copy link
Contributor

Is this something random or could it be related to my one-line change in front-end code?

Thanks @delucis #5914 should fix it

Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Thanks @delucis, very useful 🎉

@erezrokah erezrokah merged commit c789852 into decaporg:master Oct 21, 2021
@delucis delucis deleted the delucis/locale-in-custom-previews branch October 21, 2021 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access current locale in Custom Preview Template
2 participants