diff --git a/src/app-config/index.ts b/src/app-config/index.ts index 33eccd5f8..c97f052f0 100644 --- a/src/app-config/index.ts +++ b/src/app-config/index.ts @@ -3,7 +3,7 @@ import { getALlDicts } from './dicts' import { getAllContextMenus } from './context-menus' const langUI = (browser.i18n.getUILanguage() || 'en') -const langCode = /^zh-CN|zh-TW|en$/.test(langUI) +const langCode: any = /^zh-CN|zh-TW|en$/.test(langUI) ? langUI === 'zh-HK' ? 'zh-TW' : langUI @@ -45,7 +45,7 @@ export interface AppConfigMutable { animation: boolean /** language code for locales */ - langCode: string + langCode: 'en' | 'zh-CN' | 'zh-TW' /** panel width */ panelWidth: number @@ -208,14 +208,15 @@ export function appConfigFactory (): AppConfig { dict: '', list: [ 'bing', - 'youdao', - 'macmillan', - 'longman', + 'cambridge', 'cobuild', - 'websterlearner', + 'eudic', + 'longman', + 'macmillan', 'oald', 'urban', - 'eudic', + 'websterlearner', + 'youdao', ], accent: 'uk' as ('us' | 'uk') } diff --git a/src/content/components/DictPanel/index.tsx b/src/content/components/DictPanel/index.tsx index 47d4712e2..dafd3bf1b 100644 --- a/src/content/components/DictPanel/index.tsx +++ b/src/content/components/DictPanel/index.tsx @@ -17,6 +17,7 @@ export interface DictPanelProps extends DictPanelDispatchers { readonly isPinned: boolean readonly dictionaries: DictionariesState['dictionaries'] readonly allDictsConfig: DictConfigs + readonly langCode: AppConfig['langCode'] readonly fontSize: number readonly panelWidth: number readonly isAnimation: boolean @@ -57,6 +58,7 @@ export default class DictPanel extends React.Component { const { isFav, isPinned, + langCode, handleDragAreaMouseDown, handleDragAreaTouchStart, searchText, @@ -105,20 +107,27 @@ export default class DictPanel extends React.Component { closePanel, })}
- {activeDicts.map(id => React.createElement(DictItem, { - key: id, - id, - text: (dictionaries.searchHistory[0] || selection.selectionInfo).text, - dictURL: allDictsConfig[id].page, - fontSize, - preferredHeight: allDictsConfig[id].preferredHeight, - panelWidth, - isAnimation, - searchStatus: (dictsInfo[id] as any).searchStatus, - searchResult: (dictsInfo[id] as any).searchResult, - searchText, - updateItemHeight, - }))} + {activeDicts.map(id => { + let dictURL = allDictsConfig[id].page + if (typeof dictURL !== 'string') { + dictURL = dictURL[langCode] || dictURL.en + } + + return React.createElement(DictItem, { + key: id, + id, + text: (dictionaries.searchHistory[0] || selection.selectionInfo).text, + dictURL, + fontSize, + preferredHeight: allDictsConfig[id].preferredHeight, + panelWidth, + isAnimation, + searchStatus: (dictsInfo[id] as any).searchStatus, + searchResult: (dictsInfo[id] as any).searchResult, + searchText, + updateItemHeight, + }) + })}
) diff --git a/src/content/components/DictPanelPortal/index.tsx b/src/content/components/DictPanelPortal/index.tsx index 1108e5d48..edb86dd32 100644 --- a/src/content/components/DictPanelPortal/index.tsx +++ b/src/content/components/DictPanelPortal/index.tsx @@ -4,7 +4,7 @@ import { Spring } from 'react-spring' import DictPanel, { DictPanelDispatchers, DictPanelProps } from '../DictPanel' import { MsgSelection } from '@/typings/message' import { Omit } from '@/typings/helpers' -import { DictID, DictConfigs } from '@/app-config' +import { AppConfig, DictID, DictConfigs } from '@/app-config' const isSaladictPopupPage = !!window.__SALADICT_POPUP_PAGE__ @@ -19,6 +19,7 @@ export interface DictPanelPortalProps extends DictPanelPortalDispatchers { readonly isAnimation: boolean readonly allDictsConfig: DictConfigs readonly fontSize: number + readonly langCode: AppConfig['langCode'] readonly isFav: boolean readonly isPinned: boolean diff --git a/src/content/containers/DictPanelContainer.tsx b/src/content/containers/DictPanelContainer.tsx index 5c1190a4e..9e78196fb 100644 --- a/src/content/containers/DictPanelContainer.tsx +++ b/src/content/containers/DictPanelContainer.tsx @@ -20,6 +20,7 @@ export const mapStateToProps = ({ isAnimation: config.animation, allDictsConfig: config.dicts.all, fontSize: config.fontSize, + langCode: config.langCode, selection,