neiderruiz / translate-editor-js
翻译 editorjs.io 的文本块
dev-main
2023-02-27 01:30 UTC
Requires
- neiderruiz/translator-php: dev-1.1x
README
!important 我在我的前端项目中使用这个库的 editorjs
- editorjs 是一个用于构建美丽内容的块式编辑器。它是一个简单易用的库,允许您为项目创建自定义编辑器。它是一个简单易用的库,允许您为项目创建自定义编辑器。
如何使用
- 很简单
安装
composer require neiderruiz/translate-editor-js
使用
// import class use Neiderruiz\TranslateEditorJs\TranslateBlocks; // create instance $yourBlock = 'your json'; $inputLang = 'es'; $outputLang = 'en'; $translate = new TranslateBlocks(json_decode($yourBlock),$inputLang, $outputLang); // yout block is json $result = $translate->translateBlocks(); // $result is json when you can use in editorjs
使用特质
use Neiderruiz\TranslateEditorJs\Traits\TranslateBlocks; class YourClass { use TranslateBlocks; // your code public function yourMethod() { $yourBlock = 'your json'; $inputLang = 'es'; $outputLang = 'en'; $result = $this->translateBlocks(json_decode($yourBlock),$inputLang, $outputLang); // $result is json when you can use in editorjs } }
示例结构条目
{
"time": 1677447641819,
"blocks": [
{
"type": "paragraph",
"data": {
"text": "mi parrafo"
}
},
{
"id": "605c5Lx4q9",
"type": "header",
"data": {
"text": "h2 cabecera",
"level": 6
}
},
{
"id": "WtVEQ3ycUz",
"type": "list",
"data": {
"style": "ordered",
"items": [
"primer item",
"segundo item",
"tercer item"
]
}
},
{
"id": "J5a_cFw4RL",
"type": "image",
"data": {
"file": {
"url": "https://:8000/storage/images/article/lg/95614461843.jpg"
},
"caption": "imagen de salida laravel",
"withBorder": false,
"stretched": false,
"withBackground": false
}
},
{
"id": "VmuTfohBzO",
"type": "warning",
"data": {
"title": "mi titulo de alerta",
"message": "alerta mensaje"
}
},
{
"id": "RFgpoQLNdU",
"type": "quote",
"data": {
"text": "quote ejemplo",
"caption": "ejemplo caption",
"alignment": "left"
}
},
{
"id": "W8E8c3uiZy",
"type": "checklist",
"data": {
"items": [
{
"text": "tarea realizada",
"checked": false
},
{
"text": "añadir nueva tarea",
"checked": false
}
]
}
},
{
"id": "maXaenLJKG",
"type": "delimiter",
"data": {}
},
{
"id": "c-Fv4R20X7",
"type": "linkTool",
"data": {
"link": "https://www.youtube.com/@neiderruiz",
"meta": {}
}
},
{
"id": "SGl1B6Pw7G",
"type": "table",
"data": {
"withHeadings": true,
"content": [
[
"primero",
"segundo",
"tercero"
],
[
"primer texto",
"segundo texto",
"tercer texto"
]
]
}
}
],
"version": "2.24.3"
}
示例输出翻译
{
"time": 1677447641819,
"blocks": [
{
"type": "paragraph",
"data": {
"text": "my paragraph"
}
},
{
"id": "605c5Lx4q9",
"type": "header",
"data": {
"text": "h2 header",
"level": 6
}
},
{
"id": "WtVEQ3ycUz",
"type": "list",
"data": {
"style": "ordered",
"items": [
"first item",
"second item",
"third item"
]
}
},
{
"id": "J5a_cFw4RL",
"type": "image",
"data": {
"file": {
"url": "https://:8000/storage/images/article/lg/95614461843.jpg"
},
"caption": "laravel image output",
"withBorder": false,
"stretched": false,
"withBackground": false
}
},
{
"id": "VmuTfohBzO",
"type": "warning",
"data": {
"title": "my warning title",
"message": "warning message"
}
},
{
"id": "RFgpoQLNdU",
"type": "quote",
"data": {
"text": "quote example",
"caption": "enter caption",
"alignment": "left"
}
},
{
"id": "W8E8c3uiZy",
"type": "checklist",
"data": {
"items": [
{
"text": "task done",
"checked": false
},
{
"text": "add new task",
"checked": false
}
]
}
},
{
"id": "maXaenLJKG",
"type": "delimiter",
"data": {}
},
{
"id": "c-Fv4R20X7",
"type": "linkTool",
"data": {
"link": "https://www.youtube.com/@neiderruiz",
"meta": {}
}
},
{
"id": "SGl1B6Pw7G",
"type": "table",
"data": {
"withHeadings": true,
"content": [
[
"first",
"second",
"third"
],
[
"text first",
"second text",
"third text"
]
]
}
}
],
"version": "2.24.3"
}