Skip to content

Commit

Permalink
Add description for recommended dictionaries
Browse files Browse the repository at this point in the history
* Add description for recommended dictionaries

* Update ext/data/recommended-dictionaries.json

Co-authored-by: James Maa <[email protected]>
Signed-off-by: Khai Truong <[email protected]>

* Add attribution url

* rename attributionUrl to homepage

* lint

* Apply suggestions from code review

Co-authored-by: marv <[email protected]>
Signed-off-by: Khai Truong <[email protected]>

* update json schema

---------

Signed-off-by: Khai Truong <[email protected]>
Co-authored-by: James Maa <[email protected]>
Co-authored-by: marv <[email protected]>

<rikaitan.link>Y2FiNzc5M2VkYzNlMzIyMmU3MmI5OGYwYTQ4NjJjNDJiMTc3NDg1Mwo=</rikaitan.link>
  • Loading branch information
jason-ojisan committed Sep 2, 2024
1 parent 0c0fe1a commit cf478c9
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 25 deletions.
21 changes: 18 additions & 3 deletions ext/data/recommended-dictionaries.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
{
"ja": {
"terms": [
{"name": "JMdict (Jp->En)", "url": "https://github.com/Ajatt-Tools/jmdict-rikaitan/releases/latest/download/JMdict_english.zip"}
{
"name": "JMdict (Jp->En)",
"downloadUrl": "https://github.com/Ajatt-Tools/jmdict-rikaitan/releases/latest/download/JMdict_english.zip",
"description": "A free and openly licensed Japanese-to-English dictionary with example sentences, usage notes, etymology notes, cross references, antonyms, definition notes.",
"homepage": "https://github.com/Ajatt-Tools/jmdict-rikaitan/"
}
],
"kanji": [
{"name": "KANJIDIC (Jp->En)", "url": "https://github.com/Ajatt-Tools/jmdict-rikaitan/releases/latest/download/KANJIDIC_english.zip"}
{
"name": "KANJIDIC (Jp->En)",
"downloadUrl": "https://github.com/Ajatt-Tools/jmdict-rikaitan/releases/latest/download/KANJIDIC_english.zip",
"description": "An English dictionary with readings, meanings, stroke order diagrams, frequency, grade level, JLPT level and frequency of kanji characters.",
"homepage": "https://github.com/Ajatt-Tools/jmdict-rikaitan/"
}
],
"frequency": [
{"name": "BCCWJ frequency list", "url": "https://github.com/Ajatt-Tools/yomichan-bccwj-frequency-dictionary/releases/download/1.0.1/BCCWJ-LUW.zip"}
{
"name": "BCCWJ frequency list",
"downloadUrl": "https://github.com/Ajatt-Tools/yomichan-bccwj-frequency-dictionary/releases/download/1.0.1/BCCWJ-LUW.zip",
"description": "Based on the Balanced Corpus of Contemporary Written Japanese covering books, magazines, newspapers, blogs, forums, textbooks, and legal documents among others.",
"homepage": "https://github.com/Ajatt-Tools/yomichan-bccwj-frequency-dictionary/"
}
],
"grammar": [],
"pronunciation": []
Expand Down
65 changes: 55 additions & 10 deletions ext/data/schemas/recommended-dictionaries-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@
"type": "object",
"required": [
"name",
"url"
"downloadUrl",
"description"
],
"properties": {
"name": {
"type": "string",
"minLength": 2
},
"url": {
"downloadUrl": {
"type": "string",
"minLength": 2
},
"description": {
"type": "string",
"minLength": 2
},
"homepage": {
"type": "string",
"minLength": 2
}
Expand All @@ -33,14 +42,23 @@
"type": "object",
"required": [
"name",
"url"
"downloadUrl",
"description"
],
"properties": {
"name": {
"type": "string",
"minLength": 2
},
"url": {
"downloadUrl": {
"type": "string",
"minLength": 2
},
"description": {
"type": "string",
"minLength": 2
},
"homepage": {
"type": "string",
"minLength": 2
}
Expand All @@ -53,14 +71,23 @@
"type": "object",
"required": [
"name",
"url"
"downloadUrl",
"description"
],
"properties": {
"name": {
"type": "string",
"minLength": 2
},
"url": {
"downloadUrl": {
"type": "string",
"minLength": 2
},
"description": {
"type": "string",
"minLength": 2
},
"homepage": {
"type": "string",
"minLength": 2
}
Expand All @@ -73,14 +100,23 @@
"type": "object",
"required": [
"name",
"url"
"downloadUrl",
"description"
],
"properties": {
"name": {
"type": "string",
"minLength": 2
},
"url": {
"downloadUrl": {
"type": "string",
"minLength": 2
},
"description": {
"type": "string",
"minLength": 2
},
"homepage": {
"type": "string",
"minLength": 2
}
Expand All @@ -93,14 +129,23 @@
"type": "object",
"required": [
"name",
"url"
"downloadUrl",
"description"
],
"properties": {
"name": {
"type": "string",
"minLength": 2
},
"url": {
"downloadUrl": {
"type": "string",
"minLength": 2
},
"description": {
"type": "string",
"minLength": 2
},
"homepage": {
"type": "string",
"minLength": 2
}
Expand Down
16 changes: 13 additions & 3 deletions ext/js/pages/settings/dictionary-import-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class DictionaryImportController {

/**
*
* @param {import('dictionary-recommended.js').Dictionary[]} recommendedDictionaries
* @param {import('dictionary-recommended.js').RecommendedDictionary[]} recommendedDictionaries
* @param {HTMLElement} dictionariesList
* @param {Set<string>} installedDictionaryNames
* @param {Set<string>} installedDictionaryDownloadUrls
Expand All @@ -222,15 +222,25 @@ export class DictionaryImportController {
}
const template = this._settingsController.instantiateTemplate('recommended-dictionaries-list-item');
const label = querySelectorNotNull(template, '.settings-item-label');
const description = querySelectorNotNull(template, '.description');
/** @type {HTMLAnchorElement} */
const homepage = querySelectorNotNull(template, '.homepage');
/** @type {HTMLButtonElement} */
const button = querySelectorNotNull(template, '.action-button[data-action=import-recommended-dictionary]');
button.disabled = installedDictionaryNames.has(dictionary.name) || installedDictionaryDownloadUrls.has(dictionary.url);
button.disabled = installedDictionaryNames.has(dictionary.name) || installedDictionaryDownloadUrls.has(dictionary.downloadUrl);

const urlAttribute = document.createAttribute('data-import-url');
urlAttribute.value = dictionary.url;
urlAttribute.value = dictionary.downloadUrl;
button.attributes.setNamedItem(urlAttribute);

label.textContent = dictionary.name;
description.textContent = dictionary.description;
if (dictionary.homepage) {
homepage.target = '_blank';
homepage.href = dictionary.homepage;
} else {
homepage.remove();
}

dictionariesList.append(template);
}
Expand Down
4 changes: 4 additions & 0 deletions ext/templates-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
<div class="settings-item-inner">
<div class="settings-item-left">
<strong><div class="settings-item-label"></div></strong>
<div class="settings-item-description description"></div>
<div class="settings-item-description">
<a class="homepage">Homepage</a>
</div>
</div>
<div class="settings-item-right">
<button type="button" class="action-button" data-action="import-recommended-dictionary" data-import-url="">Download</button>
Expand Down
20 changes: 11 additions & 9 deletions types/ext/dictionary-recommended.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@
*/

export type RecommendedDictionaries = {
[key: string]: LanguageDictionaries;
[key: string]: LanguageRecommendedDictionaries;
};

export type LanguageDictionaries = {
terms: Dictionary[];
kanji: Dictionary[];
frequency: Dictionary[];
grammar: Dictionary[];
pronunciation: Dictionary[];
export type LanguageRecommendedDictionaries = {
terms: RecommendedDictionary[];
kanji: RecommendedDictionary[];
frequency: RecommendedDictionary[];
grammar: RecommendedDictionary[];
pronunciation: RecommendedDictionary[];
};

export type Dictionary = {
export type RecommendedDictionary = {
name: string;
url: string;
downloadUrl: string;
description: string;
homepage?: string;
};

export type RecommendedDictionariesTest = {
Expand Down

0 comments on commit cf478c9

Please sign in to comment.