@neiderruiz/editor-js-translate
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Translate Blocks Editor.js package

install package

npm i @neiderruiz/editor-js-translate

how to use it?

import { translateBlocks } form '@neiderruiz/editor-js-translate'

// translateBlocks(blocks, dest = 'en', locale = 'es')

// translation of an example from spanish to english
const blocks = {
      "time": 1690752723058,
      "blocks": [
        {
          "id": "yA6AFPfrks",
          "type": "paragraph",
          "data": {
            "text": "ejemplo traduccion de parrafo"
          }
        },
        {
          "id": "74aVbHQs3p",
          "type": "paragraph",
          "data": {
            "text": "traducimos otro parrafo de ejemplo"
          }
        },
        {
          "id": "fAmL1N8jzn",
          "type": "header",
          "data": {
            "text": "esta es una traduccion de un titulo",
            "level": 1
          }
        },
        {
          "id": "fAmL1N8jzn",
          "type": "header",
          "data": {
            "text": "suponiendo que es un titulo h2",
            "level": 2
          }
        }
      ],
      "version": "2.27.2"
    }

    translateBlocks(blocks, 'en','es').then(result => {
        console.log(result)
    })

result example english

{
    "time": 1690752723058,
    "blocks": [
        {
            "id": "yA6AFPfrks",
            "type": "paragraph",
            "data": {
                "text": "Paragraph translation example"
            }
        },
        {
            "id": "74aVbHQs3p",
            "type": "paragraph",
            "data": {
                "text": "We translate another example paragraph"
            }
        },
        {
            "id": "fAmL1N8jzn",
            "type": "header",
            "data": {
                "text": "this is a translation of a title",
                "level": 1
            }
        },
        {
            "id": "fAmL1N8jzn",
            "type": "header",
            "data": {
                "text": "assuming it's an h2 title",
                "level": 2
            }
        }
    ],
    "version": "2.27.2"
}

Package Sidebar

Install

npm i @neiderruiz/editor-js-translate

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

13.1 kB

Total Files

12

Last publish

Collaborators

  • neiderruiz