Skip to content
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

fix: only display warn when lang is not config #130

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 7 additions & 3 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'
console.warn(`The language ${options.lang} is not supported. Use the default language: ${defaultLanguage}`)
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')
}
zzxming marked this conversation as resolved.
Show resolved Hide resolved
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
Loading