-
-
Notifications
You must be signed in to change notification settings - Fork 200
Feature/add translations #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Darginec05
wants to merge
18
commits into
v6
Choose a base branch
from
feature/add-translations
base: v6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bda3b01
feat: first draft at implementing translations
gloaysa 7975ef8
revert: debounce value in ResultMD back to 1000
gloaysa 0c08677
feat: add example for plugin translation
gloaysa 181e51e
chore: add plugins translations
gloaysa 6c1fe3d
fix: ActionMenuList component tree changing on re-render
gloaysa ff2a827
feat: make translations mandatory for Plugin
gloaysa 20c7620
chore: add docs and improve typings
gloaysa 8873d39
docs: add example on how to use translations
gloaysa 7613ba5
fix: pass action to DefaultActionMenuRender and render function
gloaysa 1988ad4
feature/add-translations rewrite approach for translations architecture
Darginec05 1442196
move translations to /locales folder
Darginec05 33ddcc3
remove unused code
Darginec05 7688528
feat: emit language-change event on setLanguage (#442)
gloaysa d9f12ab
feat: enhance translation types and update editor integration
Darginec05 4b562d5
image labels are ready
Darginec05 9c87dbe
added translations for image placeholders
Darginec05 40141ca
media blocks are done with translations
Darginec05 faf36db
working on fixing types
Darginec05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,43 @@ | ||
| import { RecursiveDotNotation } from '../types/i18n'; | ||
|
|
||
| export const DEFAULT_LABEL_TEXT_MAP = { | ||
| // editor: { | ||
| // blockOptions: { | ||
| // delete: 'Delete', | ||
| // duplicate: 'Duplicate', | ||
| // turnInto: 'Turn into', | ||
| // copyBlockLink: 'Copy link to block', | ||
| // }, | ||
| // placeholder: `Type '/' for commands`, | ||
| // }, | ||
| // tools: { | ||
| // toolbar: { | ||
| // highlightColor: { | ||
| // text: 'Text', | ||
| // background: 'Background', | ||
| // customColor: 'Custom color', | ||
| // }, | ||
| // linkTitle: 'Link', | ||
| // }, | ||
| // actionMenu: { | ||
| // noActionsAvailable: 'No actions available', | ||
| // }, | ||
| // link: { | ||
| // title: 'Link title', | ||
| // url: 'Link URL', | ||
| // target: 'Link target', | ||
| // rel: 'Link rel', | ||
| // update: 'Update', | ||
| // add: 'Add', | ||
| // delete: 'Delete link', | ||
| // additionalProps: 'Additional props', | ||
| // targetPlaceholder: 'Edit link target', | ||
| // relPlaceholder: 'Edit link rel', | ||
| // titlePlaceholder: 'Edit link title', | ||
| // urlPlaceholder: 'Edit link URL', | ||
| // }, | ||
| // }, | ||
| }; | ||
|
|
||
| // [TODO] - add types | ||
| export type LabelKeys = {}; | ||
|
||
This file contains hidden or 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,17 @@ | ||
| import { DEFAULT_LABEL_TEXT_MAP, LabelKeys } from '../../constants/labels'; | ||
| import { YooEditor } from '../types'; | ||
|
|
||
| function getNestedValue(obj: any, path: string[]): string | undefined { | ||
| return path.reduce((acc, part) => { | ||
| if (acc && typeof acc === 'object' && part in acc) { | ||
| return acc[part]; | ||
| } | ||
| return undefined; | ||
| }, obj); | ||
| } | ||
|
|
||
| export function getLabelText(editor: YooEditor, key: LabelKeys) { | ||
| const keyParts = key.split('.'); | ||
| const currentLangValue = getNestedValue(DEFAULT_LABEL_TEXT_MAP, keyParts); | ||
| return currentLangValue || ''; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,11 @@ | ||
| export type RecursiveDotNotation<T, P extends string = ''> = T extends object | ||
| ? { | ||
| [K in keyof T]: T[K] extends object | ||
| ? RecursiveDotNotation<T[K], P extends '' ? `${K & string}` : `${P}.${K & string}`> | ||
| : T[K] extends string | ||
| ? P extends '' | ||
| ? `${K & string}` | ||
| : `${P}.${K & string}` | ||
| : never; | ||
| }[keyof T] | ||
| : P; |
This file contains hidden or 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,126 @@ | ||
| # Exports | ||
|
||
|
|
||
| Exports is core package for exporting/importing yoopta content in different formats | ||
| The package `@yoopta/exports` supports exporting/importing in the next formats: | ||
|
|
||
| - HTML | ||
| - Markdown | ||
| - Plain text | ||
|
|
||
| ### Installation | ||
|
|
||
| ```bash | ||
| yarn add @yoopta/exports | ||
| ``` | ||
|
|
||
| ### Usage | ||
|
|
||
| HTML exports/imports example | ||
|
|
||
| ```jsx | ||
| import { html } from '@yoopta/exports'; | ||
|
|
||
| const Editor = () => { | ||
| const editor = useMemo(() => createYooptaEditor(), []); | ||
|
|
||
| // from html to @yoopta content | ||
| const deserializeHTML = () => { | ||
| const htmlString = '<h1>First title</h1>'; | ||
| const content = html.deserialize(editor, htmlString); | ||
|
|
||
| editor.setEditorValue(content); | ||
| }; | ||
|
|
||
| // from @yoopta content to html string | ||
| const serializeHTML = () => { | ||
| const data = editor.getEditorValue(); | ||
| const htmlString = html.serialize(editor, data); | ||
| console.log('html string', htmlString); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <button onClick={deserializeHTML}>Deserialize from html to content</button> | ||
| <button onClick={serializeHTML}>Serialize from content to html</button> | ||
|
|
||
| <YooptaEditor editor={editor} plugins={plugins} /> | ||
| </div> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| Markdown exports/imports example | ||
|
|
||
| ```jsx | ||
| import { markdown } from '@yoopta/exports'; | ||
|
|
||
| const Editor = () => { | ||
| const editor = useMemo(() => createYooptaEditor(), []); | ||
|
|
||
| // from markdown to @yoopta content | ||
| const deserializeMarkdown = () => { | ||
| const markdownString = '# First title'; | ||
| const value = markdown.deserialize(editor, markdownString); | ||
|
|
||
| editor.setEditorValue(value); | ||
| }; | ||
|
|
||
| // from @yoopta content to markdown string | ||
| const serializeMarkdown = () => { | ||
| const data = editor.getEditorValue(); | ||
| const markdownString = markdown.serialize(editor, data); | ||
| console.log('markdown string', markdownString); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <button onClick={deserializeMarkdown}>Deserialize from markdown to content</button> | ||
| <button onClick={serializeMarkdown}>Serialize from content to markdown</button> | ||
|
|
||
| <YooptaEditor editor={editor} plugins={plugins} /> | ||
| </div> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| Plain text exports/imports example | ||
|
|
||
| ```jsx | ||
| import { plainText } from '@yoopta/exports'; | ||
|
|
||
| const Editor = () => { | ||
| const editor = useMemo(() => createYooptaEditor(), []); | ||
|
|
||
| // from plain text to @yoopta content | ||
| const deserializeText = () => { | ||
| const textString = '# First title'; | ||
| const value = plainText.deserialize(editor, textString); | ||
|
|
||
| editor.setEditorValue(value); | ||
| }; | ||
|
|
||
| // from @yoopta content to plain text string | ||
| const serializeText = () => { | ||
| const data = editor.getEditorValue(); | ||
| const textString = plainText.serialize(editor, data); | ||
| console.log('plain text string', textString); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <button onClick={deserializeText}>Deserialize from plain text to content</button> | ||
| <button onClick={serializeText}>Serialize from content to plain text</button> | ||
|
|
||
| <YooptaEditor editor={editor} plugins={plugins} /> | ||
| </div> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| Examples | ||
|
|
||
| - Page - [https://yoopta.dev/examples/withExports](https://yoopta.dev/examples/withExports) | ||
| - Example with HTML - [https://yoopta.dev/examples/withExports/html](https://yoopta.dev/examples/withExports/html) | ||
| - Example with Markdown - [https://yoopta.dev/examples/withExports/markdown](https://yoopta.dev/examples/withExports/markdown) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove