Skip to content

Commit

Permalink
Dictionary alias (#1270)
Browse files Browse the repository at this point in the history
* Able to edit dictionary alias on settings

* Fix lint

* Persist alias

* Alias for tag

* Fix lint

* update test

* draft

* handle dom data binder for contenteditable

* kanji dict alias

* alias frequency dict

* update test

* add alias to anki

* Revert "add alias to anki"

This reverts commit 7fd82f1.

* Fix alias not working correctly for grouped entries

* Remove contenteditable event listener

* renaming

* reset original name when alias empty && make alias pastable

* refactor

* Handle contenteditable empty makes observer child triggered

* lint

* add alias to anki glossary && add dictionary-alias marker

* fallback to dictionary name if alias is empty

* update handlebars

* add alias to test

* update test glossary

* fixing test

* add alias term frequncy & pitch accent anki

* Pass dictionary alias to all anki type

* update all unit tests

* test populate alias after update

* clean up

* alias for frequency handlebars

* Alias for pronunciation dict

* lint

* refactor

* trim alias && save on enter

* move edit alias to kebab menu

* fix lint issues

* Update text

* update doc for {dictionary} marker
  • Loading branch information
khaitruong922 authored Aug 7, 2024
1 parent 9ef85b5 commit ecd9ffc
Show file tree
Hide file tree
Showing 30 changed files with 3,061 additions and 356 deletions.
6 changes: 4 additions & 2 deletions docs/anki-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Flashcard fields can be configured with the following steps:
| `{cloze-prefix}` | Fragment of the containing `{sentence}` starting at the beginning of `{sentence}` until the beginning of `{cloze-body}`. |
| `{cloze-suffix}` | Fragment of the containing `{sentence}` starting at the end of `{cloze-body}` until the end of `{sentence}`. |
| `{conjugation}` | Conjugation path from the raw inflected term to the source term. |
| `{dictionary}` | Name of the dictionary from which the card is being created (unavailable in _grouped_ mode). |
| `{dictionary}` | Original name of the dictionary from which the card is being created (unavailable in _grouped_ mode). |
| `{dictionary-alias}` | Display name of the dictionary from which the card is being created (unavailable in _grouped_ mode). |
| `{document-title}` | Title of the web page that the term appeared in. |
| `{expression}` | Term expressed as kanji (will be displayed in kana if kanji is not available). |
| `{frequencies}` | Frequency information for the term. |
Expand Down Expand Up @@ -79,7 +80,8 @@ Flashcard fields can be configured with the following steps:
| `{cloze-body}` | Raw, inflected parent term as it appeared before being reduced to dictionary form by Yomitan. |
| `{cloze-prefix}` | Fragment of the containing `{sentence}` starting at the beginning of `{sentence}` until the beginning of `{cloze-body}`. |
| `{cloze-suffix}` | Fragment of the containing `{sentence}` starting at the end of `{cloze-body}` until the end of `{sentence}`. |
| `{dictionary}` | Name of the dictionary from which the card is being created. |
| `{dictionary}` | Original name of the dictionary from which the card is being created. |
| `{dictionary-alias}` | Display name of the dictionary from which the card is being created. |
| `{document-title}` | Title of the web page that the kanji appeared in. |
| `{frequencies}` | Frequency information for the kanji. |
| `{frequency-harmonic-rank}` | The harmonic mean of frequency data for the current kanji. Defaults to rank 9999999 when frequency data is not found, indicating extremely low rank-based kanji usage. |
Expand Down
4 changes: 4 additions & 0 deletions ext/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,10 @@ input[type=number].dictionary-priority {
overflow: auto;
}

#dictionary-alias-input {
width: 100%;
}

#dictionary-move-up>span.icon-button-inner,
#dictionary-move-down>span.icon-button-inner {
width: 26px;
Expand Down
5 changes: 5 additions & 0 deletions ext/data/schemas/options-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@
"type": "object",
"required": [
"name",
"alias",
"priority",
"enabled",
"allowSecondarySearches",
Expand All @@ -843,6 +844,10 @@
"type": "string",
"default": ""
},
"alias": {
"type": "string",
"default": ""
},
"priority": {
"type": "number",
"default": 0
Expand Down
115 changes: 115 additions & 0 deletions ext/data/templates/anki-field-templates-upgrade-v49.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{{<<<<<<<}}
{{#*inline "glossary-single"}}
{{~#unless brief~}}
{{~#scope~}}
{{~set "any" false~}}
{{~#each definitionTags~}}
{{~#if (op "||" (op "!" @root.compactTags) (op "!" redundant))~}}
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
{{name}}
{{~set "any" true~}}
{{~/if~}}
{{~/each~}}
{{~#unless noDictionaryTag~}}
{{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}}
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
{{dictionary}}
{{~set "any" true~}}
{{~/if~}}
{{~/unless~}}
{{~#if (get "any")}})</i> {{/if~}}
{{~/scope~}}
{{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
{{~/unless~}}
{{~#if (op "<=" glossary.length 1)~}}
{{#each glossary}}{{formatGlossary ../dictionary .}}{{/each}}
{{~else if @root.compactGlossaries~}}
{{#each glossary}}{{formatGlossary ../dictionary .}}{{#unless @last}} | {{/unless}}{{/each}}
{{~else~}}
<ul>{{#each glossary}}<li>{{formatGlossary ../dictionary .}}</li>{{/each}}</ul>
{{~/if~}}
{{~set "previousDictionary" dictionary~}}
{{/inline}}
{{=======}}
{{#*inline "glossary-single"}}
{{~#unless brief~}}
{{~#scope~}}
{{~set "any" false~}}
{{~#each definitionTags~}}
{{~#if (op "||" (op "!" @root.compactTags) (op "!" redundant))~}}
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
{{name}}
{{~set "any" true~}}
{{~/if~}}
{{~/each~}}
{{~#unless noDictionaryTag~}}
{{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}}
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
{{dictionaryAlias}}
{{~set "any" true~}}
{{~/if~}}
{{~/unless~}}
{{~#if (get "any")}})</i> {{/if~}}
{{~/scope~}}
{{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
{{~/unless~}}
{{~#if (op "<=" glossary.length 1)~}}
{{#each glossary}}{{formatGlossary ../dictionary .}}{{/each}}
{{~else if @root.compactGlossaries~}}
{{#each glossary}}{{formatGlossary ../dictionary .}}{{#unless @last}} | {{/unless}}{{/each}}
{{~else~}}
<ul>{{#each glossary}}<li>{{formatGlossary ../dictionary .}}</li>{{/each}}</ul>
{{~/if~}}
{{~set "previousDictionary" dictionary~}}
{{/inline}}
{{>>>>>>>}}

{{<<<<<<<}}
{{#*inline "dictionary"}}
{{~definition.dictionary~}}
{{/inline}}
{{=======}}
{{#*inline "dictionary"}}
{{~definition.dictionary~}}
{{/inline}}

{{#*inline "dictionary-alias"}}
{{~definition.dictionaryAlias~}}
{{/inline}}
{{>>>>>>>}}

{{<<<<<<<}}
{{#*inline "frequencies"}}
{{~#if (op ">" definition.frequencies.length 0)~}}
<ul style="text-align: left;">
{{~#each definition.frequencies~}}
<li>
{{~#if (op "!==" ../definition.type "kanji")~}}
{{~#if (op "||" (op ">" ../uniqueExpressions.length 1) (op ">" ../uniqueReadings.length 1))~}}(
{{~furigana expression reading~}}
) {{/if~}}
{{~/if~}}
{{~dictionary}}: {{frequency~}}
</li>
{{~/each~}}
</ul>
{{~/if~}}
{{/inline}}
{{=======}}
{{#*inline "frequencies"}}
{{~#if (op ">" definition.frequencies.length 0)~}}
<ul style="text-align: left;">
{{~#each definition.frequencies~}}
<li>
{{~#if (op "!==" ../definition.type "kanji")~}}
{{~#if (op "||" (op ">" ../uniqueExpressions.length 1) (op ">" ../uniqueReadings.length 1))~}}(
{{~furigana expression reading~}}
) {{/if~}}
{{~/if~}}
{{~dictionaryAlias}}: {{frequency~}}
</li>
{{~/each~}}
</ul>
{{~/if~}}
{{/inline}}
{{>>>>>>>}}
8 changes: 6 additions & 2 deletions ext/data/templates/default-anki-field-templates.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{~#unless noDictionaryTag~}}
{{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}}
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
{{dictionary}}
{{dictionaryAlias}}
{{~set "any" true~}}
{{~/if~}}
{{~/unless~}}
Expand Down Expand Up @@ -44,6 +44,10 @@
{{~definition.dictionary~}}
{{/inline}}

{{#*inline "dictionary-alias"}}
{{~definition.dictionaryAlias~}}
{{/inline}}

{{#*inline "expression"}}
{{~#if merge~}}
{{~#if modeTermKana~}}
Expand Down Expand Up @@ -365,7 +369,7 @@
{{~furigana expression reading~}}
) {{/if~}}
{{~/if~}}
{{~dictionary}}: {{frequency~}}
{{~dictionaryAlias}}: {{frequency~}}
</li>
{{~/each~}}
</ul>
Expand Down
4 changes: 3 additions & 1 deletion ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,7 @@ export class Backend {
if (mode === 'merge' && !enabledDictionaryMap.has(mainDictionary)) {
enabledDictionaryMap.set(mainDictionary, {
index: enabledDictionaryMap.size,
alias: mainDictionary,
priority: 0,
allowSecondarySearches: false,
partsOfSpeechFilter: true,
Expand Down Expand Up @@ -2516,9 +2517,10 @@ export class Backend {
const enabledDictionaryMap = new Map();
for (const dictionary of options.dictionaries) {
if (!dictionary.enabled) { continue; }
const {name, priority, allowSecondarySearches, partsOfSpeechFilter, useDeinflections} = dictionary;
const {name, alias, priority, allowSecondarySearches, partsOfSpeechFilter, useDeinflections} = dictionary;
enabledDictionaryMap.set(name, {
index: enabledDictionaryMap.size,
alias,
priority,
allowSecondarySearches,
partsOfSpeechFilter,
Expand Down
Loading

0 comments on commit ecd9ffc

Please sign in to comment.