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

props.intl.formatMessage values not found #72

Open
gabimoncha opened this issue Oct 2, 2019 · 2 comments
Open

props.intl.formatMessage values not found #72

gabimoncha opened this issue Oct 2, 2019 · 2 comments

Comments

@gabimoncha
Copy link

en.json: {'home.title': 'xxxx {br} xxxx',}

component:

import React from 'react';
import { injectIntl } from 'gatsby-plugin-intl';

const Home = ({ intl }) => {
  return (
    <div>{intl.formatMessage({ id: 'home_title' }, { br: <br /> })}</div>
  );
};

export default injectIntl(Home);

Expected behavior:

xxxx
xxxx

Current behavior:
xxxx [object Object] xxxx

[React Intl] Error formatting message: "home.title" for locale: "en"
Error: The intl string context variable 'br' was not provided to the string 'xxxx {br} xxxx'

@flocbit
Copy link

flocbit commented Oct 12, 2019

You need to use either FormattedMessage or defineMessages like so:

const messages = defineMessages({
   homeTitle: {
      defaultMessage: 'xxxx',
      id: 'xxxx'
   }
})

const Home = ({ intl }) => {
  return (
    <div>{intl.formatMessage(messages.homeTitle)}</div>
  );
};

@gabimoncha
Copy link
Author

@flocbit and how will this work for the translation? Do I have to define a message for every language?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants