Skip to content

Commit

Permalink
fix: only display warn when lang is not config
Browse files Browse the repository at this point in the history
  • Loading branch information
zzxming committed Nov 25, 2024
1 parent dc05502 commit 699eafd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/fluent-editor/src/config/editor.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const LANG_CONF = {
'zh-CN': ZH_CN,
}
export const CHANGE_LANGUAGE_EVENT = 'change-language'
export const defaultLanguage = 'en-US'

// Image
export const IMAGE_UPLOADER_MIME_TYPES = [
Expand Down
8 changes: 6 additions & 2 deletions packages/fluent-editor/src/fluent-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ExpandedQuillOptions, Module, Parchment as TypeParchment } from 'q
import type { IEditorConfig } from './config/types'
import Quill from 'quill'
import { FontStyle, LineHeightStyle, SizeStyle, TextIndentStyle } from './attributors'
import { CHANGE_LANGUAGE_EVENT, getListValue, ICONS_CONFIG, inputFile, LANG_CONF } from './config'
import { CHANGE_LANGUAGE_EVENT, defaultLanguage, getListValue, ICONS_CONFIG, inputFile, LANG_CONF } from './config'
import Counter from './counter' // 字符统计
import CustomClipboard from './custom-clipboard' // 粘贴板
import CustomImage from './custom-image/BlotFormatter' // 图片
Expand All @@ -22,6 +22,7 @@ import Strike from './strike' // 删除线
import CustomSyntax from './syntax' // 代码块高亮
import BetterTable from './table/better-table' // 表格
import Toolbar from './toolbar' // 工具栏
import { isUndefined } from './utils/is'
import Video from './video' // 视频
// import GlobalLink from './global-link' // 全局链接
// import QuickMenu from './quick-menu' // 快捷菜单
Expand All @@ -30,9 +31,12 @@ export interface I18NOptions {
langText: Record<string, string>
}
function resolveLanguageOption(options: Partial<I18NOptions>): I18NOptions {
if (isUndefined(options.lang)) {
options.lang = defaultLanguage
}
if (!(options.lang in LANG_CONF)) {
console.warn(`The language ${options.lang} is not supported. Use the default language: en-US`)
options.lang = 'en-US'
options.lang = defaultLanguage
}
return {
lang: options.lang,
Expand Down
3 changes: 2 additions & 1 deletion packages/fluent-editor/src/utils/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isObject, root } from './method'
import { isObject } from './is'
import { root } from './method'

export function debounce(func, wait, options = undefined) {
let lastArgs,
Expand Down
5 changes: 5 additions & 0 deletions packages/fluent-editor/src/utils/is.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function isObject(value): value is object {
const type = typeof value
return value != null && (type === 'object' || type === 'function')
}
export const isUndefined = (val: unknown): val is undefined => val === undefined
5 changes: 0 additions & 5 deletions packages/fluent-editor/src/utils/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ const freeSelf
export const root
= freeGlobalThis || freeGlobal || freeSelf || new Function('return this')()

export function isObject(value) {
const type = typeof value
return value != null && (type === 'object' || type === 'function')
}

export function compareArray(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false
Expand Down

0 comments on commit 699eafd

Please sign in to comment.