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: add support for 'defaultRichTextElements' in IntlProvider #10

Merged
merged 1 commit into from
Nov 27, 2023

Conversation

ridvankaradag
Copy link
Contributor

Summary

Add 'defaultRichTextElements' support in the IntlProvider component, enhancing compatibility with the react-intl library for improved rich text handling in internationalization.

https://formatjs.io/docs/react-intl/components/#intlprovider

Context

We can use rich text elements for individual components.

<FormattedMessage
          values={{
            p: (...chunks) => <p>{chunks}</p>,
            lineBreak: <br />
          }}
/>

But react-intl also supports defaultRichTextElements prop, which helps us to define them globally.

 <IntlProvider
        locale={lang}
        messages={messages}
        textComponent="span"
        defaultRichTextElements={{
          lineBreak: <br />,
        }}
      >

Here is an example string:

"I want to give a line break here. {lineBreak}Then, I can continue from the next line."

From:
image

To:
image

Usage

reactIntl.ts(x)

export const reactIntl = {
  defaultLocale: 'en',
  locales,
  messages,
  formats,
  defaultRichTextElements: {
    lineBreak: <br />,
  },
};

@stevensacks
Copy link
Owner

LGTM will release shortly

@stevensacks stevensacks merged commit b258ad2 into stevensacks:main Nov 27, 2023
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

Successfully merging this pull request may close these issues.

2 participants