Skip to content

Commit

Permalink
♻️ #13 i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Feb 17, 2019
1 parent a9a605e commit a0ad572
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ts/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const i18n: any = {
export const i18n: I18n = {
en_US: {
emoji: 'Emoji',
bold: 'Blod',
Expand Down
12 changes: 11 additions & 1 deletion src/ts/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ declare var webkitAudioContext: {
new(contextOptions?: AudioContextOptions): AudioContext;
};

interface I18nLang {
en_US: string;
zh_CN: string;
}

interface I18n {
en_US: { [key: string]: string }
zh_CN: { [key: string]: string }
}

interface Classes {
preview?: string
}
Expand Down Expand Up @@ -67,7 +77,7 @@ interface Options {
height?: number | string
width?: number | string
placeholder?: string
lang?: string
lang?: (keyof I18nLang)
toolbar?: Array<string | MenuItem>
resize?: Resize
counter?: number
Expand Down
5 changes: 3 additions & 2 deletions src/ts/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ const genUploadingLabel = (vditor: Vditor, files: any): string => {
}
const lastIndex = file.name.lastIndexOf('.')
const filename = vditor.options.upload.filename(file.name.substr(0, lastIndex)) + file.name.substr(lastIndex)
const lang: (keyof I18nLang) = vditor.options.lang
if (file.size > vditor.options.upload.max) {
vditor.upload.element.className = 'vditor-upload vditor-upload--tip'
vditor.upload.element.children[0].innerHTML = `${file.name} ${i18n[vditor.options.lang].over} ${vditor.options.upload.max / 1024 / 1024}M`
vditor.upload.element.children[0].innerHTML = `${file.name} ${i18n[lang].over} ${vditor.options.upload.max / 1024 / 1024}M`
} else {
uploadingStr += `${tag}[${filename}](${i18n[vditor.options.lang].uploading})\n`
uploadingStr += `${tag}[${filename}](${i18n[lang].uploading})\n`
}
}
return uploadingStr
Expand Down

0 comments on commit a0ad572

Please sign in to comment.