i18next-react-markdown

0.1.1 • Public • Published

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

npm install

Storybook

Run local storybook

npm start

Build storybook

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

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

returns "Visit Website"

i18next processor initialisation

import mdProcessor, { parser as mdParser } from 'i18next-react-markdown';
 
const elements = {
  h1({ id, children }: Attributes) {
    return (
      <h1 id={id}>
        {children}
      </h1>
    );
  },
}
 
const components = {
  Card({ children }: Attributes) {
    return (
      <div class="card">
        {children}
      </div>
    );
  },
}
 
const mdProcessor = createProcessor({
  elements,
  components,
  marksyOptions: {} // additional marksy input after elements and components
  markedOptions: {}
});
 
i18n
  .use(mdProcessor)
  .init({
    // ...
    postProcess: ['react-markdown'],
    // ...
  })

Editor usage

import Editor from 'i18next-react-markdown/Editor';
 
return (
  <Editor elements={elements} components={components} />
)

Markdown parser usage

import { parser as createMdParser } from 'i18next-react-markdown';
 
 
const mdParse = createMdParser(elements, components);

Readme

Keywords

Package Sidebar

Install

npm i i18next-react-markdown

Weekly Downloads

5

Version

0.1.1

License

MIT

Unpacked Size

9.32 MB

Total Files

69

Last publish

Collaborators

  • martinhecher