Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/redsift/i18next-react-markdown

Embed React elements using markdown in i18next translation strings
https://github.com/redsift/i18next-react-markdown

Last synced: 10 days ago
JSON representation

Embed React elements using markdown in i18next translation strings

Awesome Lists containing this project

README

        

# i18next-react-markdown

Embed React elements using markdown in i18next translation strings.

This wraps `marksy` with an HTML element and React component config import util.

## Getting Started

### Install and Build

```sh
npm install
```

### Storybook

#### Run local storybook

```sh
npm start
```

#### Build storybook

```sh
npm run storybook:build
```

> outputs static storybook site to `docs/`

## Usage

This can be used in your own project and elements can be overriden with custom React components.

Locale keys must have the suffix: `_md` to use markdown.

### Locale usage

Example locale JSON

```json
{
"website": "Website",
"website-header_md": "Visit $t(website)"
}
```

> returns "`Visit Website`"

### i18next processor initialisation

```js
import mdProcessor, { parser as mdParser } from 'i18next-react-markdown';

const elements = {
h1({ id, children }: Attributes) {
return (


{children}


);
},
}

const components = {
Card({ children }: Attributes) {
return (


{children}

);
},
}

const mdProcessor = createProcessor({
elements,
components,
marksyOptions: {} // additional marksy input after elements and components
markedOptions: {}
});

i18n
.use(mdProcessor)
.init({
// ...
postProcess: ['react-markdown'],
// ...
})
```

## Editor usage

```js
import Editor from 'i18next-react-markdown/Editor';

return (

)
```

## Markdown parser usage

```js
import { parser as createMdParser } from 'i18next-react-markdown';

const mdParse = createMdParser(elements, components);
```