Skip to content

Commit

Permalink
feat(dicts): add webster learners dict
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed May 26, 2018
1 parent 428cd08 commit 6e0f1ee
Show file tree
Hide file tree
Showing 11 changed files with 11,105 additions and 0 deletions.
27 changes: 27 additions & 0 deletions config/fake-env/fake-ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,33 @@ const fakeFetchData = [
text: () => require('raw-loader!../../test/specs/components/dictionaries/youdao/response/translation.html')
},
},
{
test: {
method: /.*/,
url: /learnersdictionary\.com.*house$/,
},
response: {
text: () => require('raw-loader!../../test/specs/components/dictionaries/learnersdict/response/house.html')
},
},
{
test: {
method: /.*/,
url: /learnersdictionary\.com.*door$/,
},
response: {
text: () => require('raw-loader!../../test/specs/components/dictionaries/learnersdict/response/door.html')
},
},
{
test: {
method: /.*/,
url: /learnersdictionary\.com.*jumblish$/,
},
response: {
text: () => require('raw-loader!../../test/specs/components/dictionaries/learnersdict/response/jumblish.html')
},
},
]

/*-----------------------------------------------*\
Expand Down
40 changes: 40 additions & 0 deletions src/app-config/dicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,43 @@ export function getALlDicts () {
chs: true
}
},
learnersdict: {
/**
* Full content page to jump to when user clicks the title.
* %s will be replaced with the current word.
* %z will be replaced with the traditional Chinese version of the current word
*/
page: 'http://www.learnersdictionary.com/definition/%s',
/**
* If set to true, the dict start searching automatically.
* Otherwise it'll only start seaching when user clicks the unfold button.
* Default MUST be true and let user decide.
*/
defaultUnfold: true,
/**
* This is the default height when the dict first renders the result.
* If the content height is greater than the preferred height,
* the preferred height is used and a mask with a view-more button is shown.
* Otherwise the content height is used.
*/
preferredHeight: 265,
/**
* Only start searching if the selection contains the language.
* Better set default to true and let user decide.
*/
selectionLang: {
eng: true,
chs: true
},
/** Optional dict custom options. Can only be boolean or number. */
options: {
defs: true,
phrase: true,
derived: true,
arts: true,
related: true,
},
},
liangan: {
/**
* Full content page to jump to when user clicks the title.
Expand Down Expand Up @@ -253,6 +290,7 @@ export function getALlDicts () {
eng: true,
chs: true
},
/** Optional dict custom options. Can only be boolean or number. */
options: {
wordfams: false,
collocations: true,
Expand Down Expand Up @@ -291,6 +329,7 @@ export function getALlDicts () {
eng: true,
chs: true
},
/** Optional dict custom options. Can only be boolean or number. */
options: {
related: true,
}
Expand Down Expand Up @@ -385,6 +424,7 @@ export function getALlDicts () {
eng: true,
chs: true
},
/** Optional dict custom options. Can only be boolean or number. */
options: {
basic: true,
collins: true,
Expand Down
58 changes: 58 additions & 0 deletions src/components/dictionaries/learnersdict/View.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react'
import Speaker from '@/components/Speaker'
import { LearnersDictResult, LearnersDictResultLex, LearnersDictResultRelated } from './engine'

export default class DictLearnersDict extends React.PureComponent<{ result: LearnersDictResult }> {
renderLex (result: LearnersDictResultLex) {
return result.items.map(entry => (
<section key={entry.title} className='dictLearnersDict-Entry'>
<header className='dictLearnersDict-Header'>
<span className='hw_d hw_0' dangerouslySetInnerHTML={{ __html: entry.title }} />
<Speaker src={entry.pron} />
</header>
{entry.infs &&
<div className='dictLearnersDict-Header'>
<span className='hw_infs_d' dangerouslySetInnerHTML={{ __html: entry.infs }} />
<Speaker src={entry.infsPron} />
</div>
}
{entry.labels &&
<div className='labels' dangerouslySetInnerHTML={{ __html: entry.labels }} />
}
{entry.senses &&
<div className='sblocks' dangerouslySetInnerHTML={{ __html: entry.senses }} />
}
{entry.arts && entry.arts.length > 0 && entry.arts.map(src => (
<img key={src} src={src} />
))}
{entry.phrases &&
<div className='dros' dangerouslySetInnerHTML={{ __html: entry.phrases }} />
}
{entry.derived &&
<div className='uros' dangerouslySetInnerHTML={{ __html: entry.derived }} />
}
</section>
))
}

renderRelated (result: LearnersDictResultRelated) {
return (
<>
<p>Did you mean:</p>
<ul className='dictLearnersDict-Related' dangerouslySetInnerHTML={{ __html: result.list }} />
</>
)
}

render () {
const { result } = this.props
switch (result.type) {
case 'lex':
return this.renderLex(result)
case 'related':
return this.renderRelated(result)
default:
return null
}
}
}
34 changes: 34 additions & 0 deletions src/components/dictionaries/learnersdict/_locales.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": {
"en": "Merriam-Webster's Learner's Dictionary",
"zh_CN": "韦氏学习词典",
"zh_TW": "韋氏學習字典"
},
"options": {
"defs": {
"en": "Show definitions",
"zh_CN": "显示释义",
"zh_TW": "顯示解釋"
},
"phrase": {
"en": "Show phrases",
"zh_CN": "显示词组",
"zh_TW": "顯示片語"
},
"derived": {
"en": "Show derived words",
"zh_CN": "显示派生词",
"zh_TW": "顯示衍生字"
},
"arts": {
"en": "Show pictures",
"zh_CN": "显示图片释义",
"zh_TW": "顯示圖片解釋"
},
"related": {
"en": "Show related results",
"zh_CN": "失败时显示备选",
"zh_TW": "失敗時顯示備選"
}
}
}
Loading

0 comments on commit 6e0f1ee

Please sign in to comment.