diff --git a/packages/tools/link-tool/README.md b/packages/tools/link-tool/README.md index 177ded412..718dca49b 100644 --- a/packages/tools/link-tool/README.md +++ b/packages/tools/link-tool/README.md @@ -9,3 +9,27 @@ const paragraph = require('yoopta-paragraph'); // TODO: DEMONSTRATE API ``` + +### LinkTool Translation Support + +The `LinkTool` allows you to customize the labels and tooltips to match the language of your application. You can easily pass translated text through the `labels` property, making the tool adaptable for different languages. + +#### Example Configuration with Translations + +Below is an example that sets custom Spanish labels for the "Add" and "Delete" buttons: + +```typescript +export const TOOLS: Tools = { + LinkTool: { + render: (props: LinkToolRenderProps) => + DefaultLinkToolRender({ + labels: { + addLabel: 'AƱadir enlace', // Label for the Add button + deleteLabel: 'Eliminar enlace' // Label for the Delete button + }, + ...props, + }), + tool: LinkTool, + }, +}; + diff --git a/packages/tools/link-tool/src/components/DefaultLinkToolRender.tsx b/packages/tools/link-tool/src/components/DefaultLinkToolRender.tsx index 05f674cf4..3ef9a9e7d 100644 --- a/packages/tools/link-tool/src/components/DefaultLinkToolRender.tsx +++ b/packages/tools/link-tool/src/components/DefaultLinkToolRender.tsx @@ -1,10 +1,25 @@ import { ChangeEvent, useEffect, useState } from 'react'; -import { LinkToolRenderProps, Link } from '../types'; +import {LinkToolRenderProps, LinkToolTranslationProps} from '../types'; import ChevronUp from '../icons/chevronup.svg'; import { useYooptaEditor } from '@yoopta/editor'; const DefaultLinkToolRender = (props: LinkToolRenderProps) => { - const { withLink = true, withTitle = true } = props; + const { withLink = true, withTitle = true, withAdditionalProps = true, labels } = props; + const mergedLabels: LinkToolTranslationProps = { + titleLabel: 'Link Title', + titlePlaceholder: 'Edit link title', + linkLabel: 'Link URL', + linkPlaceholder: 'Edit link URL', + additionalPropsLabel:'Additional props', + targetLabel: 'Link target', + targetPlaceholder: 'Edit link target', + relLabel: 'Link rel', + relPlaceholder: 'Edit link rel', + updateLabel: 'Update', + addLabel: 'Add', + deleteLabel: 'Delete link', + ...labels + } const editor = useYooptaEditor(); const defaultLinkProps = editor.plugins?.LinkPlugin?.elements?.link?.props; @@ -42,7 +57,7 @@ const DefaultLinkToolRender = (props: LinkToolRenderProps) => { {withTitle && (