-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: i18n support with i18next compatible API
- Loading branch information
Showing
29 changed files
with
426 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
title: i18n | ||
slug: i18n | ||
position: 105 | ||
--- | ||
|
||
# i18n | ||
|
||
The component is localized entirely in English by default, but you can override these localizations via the `translation` prop - a function that has a signature compatible with the `t` function of i18next. You only need to localize parts of the UI that you'll actually be using, there is no need to localize the entirety of the editor unless you need to. If you're using i18next, you can use browse the [`locales` directory in GitHub](https://github.com/mdx-editor/editor) for a default set of translations or use a tool like [i18next Parser](https://github.com/i18next/i18next-parser) to extract them from the source code. If you're using another i18n library, you can use the `translation` prop to pass in your own translations | ||
|
||
```tsx | ||
|
||
function LocalizedEditor() { | ||
return <MDXEditor translation={(key, defaultValue, interpolations) => { return i18n.t(key, defaultValue, interpolations) }} /> | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
{ | ||
"frontmatterEditor": { | ||
"title": "Edit document frontmatter", | ||
"key": "Key", | ||
"value": "Value", | ||
"addEntry": "Add entry" | ||
}, | ||
"dialogControls": { | ||
"save": "Save", | ||
"cancel": "Cancel" | ||
}, | ||
"uploadImage": { | ||
"uploadInstructions": "Upload an image from your device:", | ||
"addViaUrlInstructions": "Or add an image from an URL:", | ||
"autoCompletePlaceholder": "Select or paste an image src", | ||
"alt": "Alt:", | ||
"title": "Title:" | ||
}, | ||
"imageEditor": { | ||
"editImage": "Edit image" | ||
}, | ||
"createLink": { | ||
"url": "URL", | ||
"urlPlaceholder": "Select or paste an URL", | ||
"title": "Title", | ||
"saveTooltip": "Set URL", | ||
"cancelTooltip": "Cancel change" | ||
}, | ||
"linkPreview": { | ||
"open": "Open {{url}} in new window", | ||
"edit": "Edit link URL", | ||
"copyToClipboard": "Copy to clipboard", | ||
"copied": "Copied!", | ||
"remove": "Remove link" | ||
}, | ||
"table": { | ||
"deleteTable": "Delete table", | ||
"columnMenu": "Column menu", | ||
"textAlignment": "Text alignment", | ||
"alignLeft": "Align left", | ||
"alignCenter": "Align center", | ||
"alignRight": "Align right", | ||
"insertColumnLeft": "Insert a column to the left of this one", | ||
"insertColumnRight": "Insert a column to the right of this one", | ||
"deleteColumn": "Delete this column", | ||
"rowMenu": "Row menu", | ||
"insertRowAbove": "Insert a row above this one", | ||
"insertRowBelow": "Insert a row below this one", | ||
"deleteRow": "Delete this row" | ||
}, | ||
"toolbar": { | ||
"blockTypes": { | ||
"paragraph": "Paragraph", | ||
"quote": "Quote", | ||
"heading": "Heading {{level}}" | ||
}, | ||
"blockTypeSelect": { | ||
"selectBlockTypeTooltip": "Select block type", | ||
"placeholder": "Block type" | ||
}, | ||
"removeBold": "Remove bold", | ||
"bold": "Bold", | ||
"removeItalic": "Italic", | ||
"italic": "Italic", | ||
"underline": "Remove underline", | ||
"removeUnderline": "Underline", | ||
"removeInlineCode": "Remove code format", | ||
"inlineCode": "Inline code format", | ||
"link": "Create link", | ||
"richText": "Rich text", | ||
"diffMode": "Diff mode", | ||
"source": "Source mode", | ||
"admonition": "Insert Admonition", | ||
"codeBlock": "Insert Code Block", | ||
"editFrontmatter": "Edit frontmatter", | ||
"insertFrontmatter": "Insert frontmatter", | ||
"image": "Insert image", | ||
"insertSandpack": "Insert Sandpack", | ||
"table": "Insert Table", | ||
"thematicBreak": "Insert thematic break", | ||
"bulletedList": "Bulleted list", | ||
"numberedList": "Numbered list", | ||
"checkList": "Check list", | ||
"deleteSandpack": "Delete this code block", | ||
"undo": "Undo {{shortcut}}", | ||
"redo": "Redo {{shortcut}}" | ||
}, | ||
"admonitions": { | ||
"note": "Note", | ||
"tip": "Tip", | ||
"danger": "Danger", | ||
"info": "Info", | ||
"caution": "Caution", | ||
"changeType": "Select admonition type", | ||
"placeholder": "Admonition type" | ||
}, | ||
"codeBlock": { | ||
"language": "Code block language", | ||
"selectLanguage": "Select code block language" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react' | ||
import i18next from 'i18next' | ||
import markdown from './assets/live-demo-contents.md?raw' | ||
import { MDXEditor } from '..' | ||
import { ALL_PLUGINS } from './_boilerplate' | ||
|
||
const sl = { | ||
toolbar: { | ||
undo: 'Razveljavi {{shortcut}}', | ||
redo: 'Uveljavi {{shortcut}}', | ||
blockTypeSelect: { | ||
selectBlockTypeTooltip: 'Izberi vrsto bloka', | ||
placeholder: 'Vrsta bloka' | ||
}, | ||
|
||
blockTypes: { | ||
paragraph: 'Odstavek', | ||
heading: 'Naslov', | ||
quote: 'Citat' | ||
} | ||
} | ||
} | ||
|
||
void i18next.init({ | ||
lng: 'sl', // if you're using a language detector, do not define the lng option | ||
debug: true, | ||
resources: { | ||
sl: { | ||
translation: sl | ||
} | ||
} | ||
}) | ||
|
||
export const Example = () => { | ||
return ( | ||
<MDXEditor | ||
translation={(key, defaultValue, interpolations) => { | ||
return i18next.t(key, defaultValue, interpolations) as string | ||
}} | ||
markdown={markdown} | ||
onChange={(md) => console.log('change', { md })} | ||
plugins={ALL_PLUGINS} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.