Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit b9dcf33

Browse files
feat: stylo i18n (#1458)
Signed-off-by: peterpeterparker <[email protected]>
1 parent 51a8cef commit b9dcf33

File tree

8 files changed

+17
-19
lines changed

8 files changed

+17
-19
lines changed

studio/src/app/config/editor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import {h1, h2, h3, StyloConfig, ul} from '@deckdeckgo/stylo';
22

3-
import i18n from '../stores/i18n.store';
4-
53
import {imgStorage} from '../plugins/img.storage.plugin';
64
import {imgUnsplash} from '../plugins/img.unsplash.plugin';
75
import {imgGif} from '../plugins/img.gif.plugin';
@@ -15,7 +13,7 @@ export const editorConfig: Partial<StyloConfig> = {
1513
match: ({paragraph}: {paragraph: HTMLElement}) => paragraph?.nodeName.toLowerCase() === 'deckgo-highlight-code',
1614
actions: [
1715
{
18-
text: i18n.state.editor.edit_code,
16+
text: 'edit_code',
1917
icon: `<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 512 512'>
2018
<polygon points='364.13 125.25 87 403 64 448 108.99 425 386.75 147.87 364.13 125.25' style='fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px'/>
2119
<path d='M420.69,68.69,398.07,91.31l22.62,22.63,22.62-22.63a16,16,0,0,0,0-22.62h0A16,16,0,0,0,420.69,68.69Z' style='fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px'/>

studio/src/app/editors/app-doc-editor/app-doc-editor.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ export class AppDocEditor implements ComponentInterface {
6262
// Hack: we need to clean DOM first on reload as we mix both intrinsect elements and dom elements (content editable)
6363
private reloadAfterRender: boolean = false;
6464

65+
private i18nListener: () => void | undefined;
66+
6567
componentWillLoad() {
6668
this.updateEditorToolbarConfig();
69+
70+
this.i18nListener = i18n.onChange('lang', () => this.updateEditorToolbarConfig());
6771
}
6872

6973
async componentDidLoad() {
@@ -84,6 +88,8 @@ export class AppDocEditor implements ComponentInterface {
8488
this.docImageEvents.destroy();
8589

8690
this.destroy();
91+
92+
this.i18nListener?.();
8793
}
8894

8995
/**
@@ -135,7 +141,10 @@ export class AppDocEditor implements ComponentInterface {
135141
private updateEditorToolbarConfig() {
136142
this.editorConfig = {
137143
...this.editorConfig,
138-
lang: i18n.state.lang,
144+
i18n: {
145+
lang: i18n.state.lang,
146+
custom: {...i18n.state.editor}
147+
},
139148
toolbar: {palette: colorStore.state.history.slice(0, 11)}
140149
};
141150
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import {StyloPlugin, StyloPluginCreateParagraphsParams} from '@deckdeckgo/stylo';
22

3-
import i18n from '../stores/i18n.store';
4-
53
import {openCodeModal} from '../utils/editor/plugin.utils';
64

75
export const code: StyloPlugin = {
8-
text: i18n.state.editor.code,
6+
text: 'code',
97
icon: 'code',
108
createParagraphs: (pluginParams: StyloPluginCreateParagraphsParams) => openCodeModal({pluginParams})
119
};

studio/src/app/plugins/hr.plugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import i18n from '../stores/i18n.store';
21
import {createEmptyElement, StyloPlugin, StyloPluginCreateParagraphsParams, transformParagraph} from '@deckdeckgo/stylo';
32

43
export const hr: StyloPlugin = {
5-
text: i18n.state.editor.separator,
4+
text: 'separator',
65
icon: 'hr',
76
createParagraphs: async ({container, paragraph}: StyloPluginCreateParagraphsParams) =>
87
transformParagraph({

studio/src/app/plugins/img.gif.plugin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import {StyloPlugin, StyloPluginCreateParagraphsParams} from '@deckdeckgo/stylo';
22

3-
import i18n from '../stores/i18n.store';
4-
53
import {openPluginModal} from '../utils/editor/plugin.utils';
64

75
export const imgGif: StyloPlugin = {
8-
text: i18n.state.editor.gifs,
6+
text: 'gifs',
97
icon: `<svg width="32" height="32" viewBox="0 0 512 512" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;">
108
<path d="M464,128C464,101.508 442.492,80 416,80L96,80C69.508,80 48,101.508 48,128L48,384C48,410.492 69.508,432 96,432L416,432C442.492,432 464,410.492 464,384L464,128Z" style="fill:none;stroke:currentColor;stroke-width:32px;"/>
119
<g transform="matrix(1,0,0,0.843266,1.54944,39.8473)">

studio/src/app/plugins/img.storage.plugin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import {StorageFile} from '@deckdeckgo/editor';
22
import {StyloPlugin, StyloPluginCreateParagraphsParams} from '@deckdeckgo/stylo';
33

4-
import i18n from '../stores/i18n.store';
5-
64
import {StorageOfflineProvider} from '../providers/storage/storage.offline.provider';
75

86
import {createParagraphImage} from '../utils/editor/plugin.utils';
97

108
export const imgStorage: StyloPlugin = {
11-
text: i18n.state.editor.image,
9+
text: 'image',
1210
icon: 'img',
1311
files: {
1412
accept: 'image/x-png,image/jpeg,image/gif,image/svg+xml,image/webp',

studio/src/app/plugins/img.unsplash.plugin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import {StyloPlugin, StyloPluginCreateParagraphsParams} from '@deckdeckgo/stylo';
22

3-
import i18n from '../stores/i18n.store';
4-
53
import {openPluginModal} from '../utils/editor/plugin.utils';
64

75
export const imgUnsplash: StyloPlugin = {
8-
text: i18n.state.editor.stock_photo,
6+
text: 'stock_photo',
97
icon: `<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
108
<path d="M10 9V0h12v9H10zm12 5h10v18H0V14h10v9h12v-9z" fill="currentColor" fill-rule="nonzero" />
119
</svg>

studio/src/app/stores/i18n.store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ onChange('lang', (lang: Languages) => {
6363
});
6464
});
6565

66-
export default {state};
66+
export default {state, onChange};

0 commit comments

Comments
 (0)