1.0.4 • Published 3 months ago

@neiderruiz/editor-js-translate v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

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"
}
1.0.4

3 months ago

1.0.3

6 months ago

1.0.2

10 months ago

1.0.1

10 months ago