From 8d672e7d2544fd50633bf0a216f85252994c7308 Mon Sep 17 00:00:00 2001 From: Richard Garner Date: Sat, 18 May 2024 10:56:16 +1000 Subject: [PATCH 1/3] Add onyomi-hiragana handlebars * Add onyomi-hiragana handlebars * Add docs * Fix typo in documentation of kunyomi/onyomi handlebars --- docs/anki-integration.md | 5 +++-- .../anki-field-templates-upgrade-v36.handlebars | 13 +++++++++++++ .../default-anki-field-templates.handlebars | 4 ++++ ext/js/data/anki-template-util.js | 1 + ext/js/data/options-util.js | 10 +++++++++- ext/settings.html | 6 +++++- 6 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 ext/data/templates/anki-field-templates-upgrade-v36.handlebars diff --git a/docs/anki-integration.md b/docs/anki-integration.md index f12c1268a9..5aa9e10c64 100644 --- a/docs/anki-integration.md +++ b/docs/anki-integration.md @@ -87,8 +87,9 @@ Flashcard fields can be configured with the following steps: | `{frequency-average-rank}` | The average of frequency data for the current kanji. Defaults to rank 9999999 when frequency data is not found, indicating extremely low rank-based kanji usage. | | `{frequency-average-occurrence}` | The average of frequency data for the current kanji. Defaults to 0 occurrences when frequency data is not found, the lowest possible occurrence-based kanji usage. | | `{glossary}` | List of definitions for the kanji. | - | `{kunyomi}` | Kunyomi (Japanese reading) for the kanji expressed as katakana. | - | `{onyomi}` | Onyomi (Chinese reading) for the kanji expressed as hiragana. | + | `{kunyomi}` | Kunyomi (Japanese reading) for the kanji expressed as hiragana. | + | `{onyomi}` | Onyomi (Chinese reading) for the kanji expressed as katakana. | + | `{onyomi-hiragana}` | Onyomi (Chinese reading) for the kanji expressed as hiragana. | | `{screenshot}` | Screenshot of the web page taken at the time the kanji was added. | | `{search-query}` | The full search query shown on the search page. | | `{selection-text}` | The selected text on the search page or popup. | diff --git a/ext/data/templates/anki-field-templates-upgrade-v36.handlebars b/ext/data/templates/anki-field-templates-upgrade-v36.handlebars new file mode 100644 index 0000000000..44b802bbb0 --- /dev/null +++ b/ext/data/templates/anki-field-templates-upgrade-v36.handlebars @@ -0,0 +1,13 @@ +{{<<<<<<<}} +{{#*inline "onyomi"}} + {{~#each definition.onyomi}}{{.}}{{#unless @last}}, {{/unless}}{{/each~}} +{{/inline}} +{{=======}} +{{#*inline "onyomi"}} + {{~#each definition.onyomi}}{{.}}{{#unless @last}}, {{/unless}}{{/each~}} +{{/inline}} + +{{#*inline "onyomi-hiragana"}} + {{~#each definition.onyomi}}{{hiragana (.)}}{{#unless @last}}, {{/unless}}{{/each~}} +{{/inline}} +{{>>>>>>>}} \ No newline at end of file diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 53dab1c1f2..1d0bc867e1 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -173,6 +173,10 @@ {{~#each definition.onyomi}}{{.}}{{#unless @last}}, {{/unless}}{{/each~}} {{/inline}} +{{#*inline "onyomi-hiragana"}} + {{~#each definition.onyomi}}{{hiragana (.)}}{{#unless @last}}, {{/unless}}{{/each~}} +{{/inline}} + {{#*inline "reading"}} {{~#unless modeTermKana~}} {{~#if merge~}} diff --git a/ext/js/data/anki-template-util.js b/ext/js/data/anki-template-util.js index 20170daeac..1c74d74725 100644 --- a/ext/js/data/anki-template-util.js +++ b/ext/js/data/anki-template-util.js @@ -83,6 +83,7 @@ export function getStandardFieldMarkers(type) { 'glossary', 'kunyomi', 'onyomi', + 'onyomi-hiragana', 'screenshot', 'search-query', 'selection-text', diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index 521b4c9b5c..e2fd278901 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -542,7 +542,8 @@ export class OptionsUtil { this._updateVersion32, this._updateVersion33, this._updateVersion34, - this._updateVersion35 + this._updateVersion35, + this._updateVersion36 ]; /* eslint-enable @typescript-eslint/unbound-method */ if (typeof targetVersion === 'number' && targetVersion < result.length) { @@ -1286,6 +1287,13 @@ export class OptionsUtil { await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v35.handlebars'); } + /** + * - Added handlebars for onyomi reading in hiragana. + * @type {import('options-util').UpdateFunction} + */ + async _updateVersion36(options) { + await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v36.handlebars'); + } /** * @param {string} url diff --git a/ext/settings.html b/ext/settings.html index 14342a5b5f..525e99b168 100644 --- a/ext/settings.html +++ b/ext/settings.html @@ -3088,10 +3088,14 @@

Yomitan Settings

{kunyomi} - Kunyomi (Japanese reading) for the kanji, expressed as katakana. + Kunyomi (Japanese reading) for the kanji, expressed as hiragana. {onyomi} + Onyomi (Chinese reading) for the kanji, expressed as katakana. + + + {onyomi-hiragana} Onyomi (Chinese reading) for the kanji, expressed as hiragana. From 599241dd21eef6d0faac3e6ff63ba38505c127a5 Mon Sep 17 00:00:00 2001 From: rhgg2 Date: Sun, 19 May 2024 07:49:49 +1000 Subject: [PATCH 2/3] Update ext/data/templates/anki-field-templates-upgrade-v36.handlebars Co-authored-by: StefanVukovic99 Signed-off-by: rhgg2 --- .../anki-field-templates-upgrade-v36.handlebars | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/ext/data/templates/anki-field-templates-upgrade-v36.handlebars b/ext/data/templates/anki-field-templates-upgrade-v36.handlebars index 44b802bbb0..bbc057ecb1 100644 --- a/ext/data/templates/anki-field-templates-upgrade-v36.handlebars +++ b/ext/data/templates/anki-field-templates-upgrade-v36.handlebars @@ -1,13 +1,3 @@ -{{<<<<<<<}} -{{#*inline "onyomi"}} - {{~#each definition.onyomi}}{{.}}{{#unless @last}}, {{/unless}}{{/each~}} -{{/inline}} -{{=======}} -{{#*inline "onyomi"}} - {{~#each definition.onyomi}}{{.}}{{#unless @last}}, {{/unless}}{{/each~}} -{{/inline}} - {{#*inline "onyomi-hiragana"}} {{~#each definition.onyomi}}{{hiragana (.)}}{{#unless @last}}, {{/unless}}{{/each~}} -{{/inline}} -{{>>>>>>>}} \ No newline at end of file +{{/inline}} \ No newline at end of file From 3d29fdbf9427533903953de1e91bdda90a7cfd4e Mon Sep 17 00:00:00 2001 From: Richard Garner Date: Sun, 19 May 2024 08:47:41 +1000 Subject: [PATCH 3/3] Update tests for onyomi-hiragana handlebars * Update tests for onyomi-hiragana handlebars * Fix typo in code --- ext/data/templates/anki-field-templates-upgrade-v36.handlebars | 2 +- ext/data/templates/default-anki-field-templates.handlebars | 2 +- test/data/anki-note-builder-test-results.json | 2 ++ test/options-util.test.js | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/data/templates/anki-field-templates-upgrade-v36.handlebars b/ext/data/templates/anki-field-templates-upgrade-v36.handlebars index bbc057ecb1..0b07e48315 100644 --- a/ext/data/templates/anki-field-templates-upgrade-v36.handlebars +++ b/ext/data/templates/anki-field-templates-upgrade-v36.handlebars @@ -1,3 +1,3 @@ {{#*inline "onyomi-hiragana"}} - {{~#each definition.onyomi}}{{hiragana (.)}}{{#unless @last}}, {{/unless}}{{/each~}} + {{~#each definition.onyomi}}{{hiragana .}}{{#unless @last}}, {{/unless}}{{/each~}} {{/inline}} \ No newline at end of file diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 1d0bc867e1..bbeff83066 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -174,7 +174,7 @@ {{/inline}} {{#*inline "onyomi-hiragana"}} - {{~#each definition.onyomi}}{{hiragana (.)}}{{#unless @last}}, {{/unless}}{{/each~}} + {{~#each definition.onyomi}}{{hiragana .}}{{#unless @last}}, {{/unless}}{{/each~}} {{/inline}} {{#*inline "reading"}} diff --git a/test/data/anki-note-builder-test-results.json b/test/data/anki-note-builder-test-results.json index 49e0d8fec7..1c78c0db63 100644 --- a/test/data/anki-note-builder-test-results.json +++ b/test/data/anki-note-builder-test-results.json @@ -19,6 +19,7 @@ "glossary": "
  1. utsu meaning 1
  2. utsu meaning 2
  3. utsu meaning 3
  4. utsu meaning 4
  5. utsu meaning 5
", "kunyomi": "う.つ, う.ち-, ぶ.つ", "onyomi": "ダ, ダアス", + "onyomi-hiragana": "だ, だあす", "screenshot": "", "search-query": "fullQuery", "selection-text": "", @@ -50,6 +51,7 @@ "glossary": "
  1. komu meaning 1
  2. komu meaning 2
  3. komu meaning 3
  4. komu meaning 4
  5. komu meaning 5
", "kunyomi": "-こ.む, こ.む, こ.み, -こ.み, こ.める", "onyomi": "", + "onyomi-hiragana": "", "screenshot": "", "search-query": "fullQuery", "selection-text": "", diff --git a/test/options-util.test.js b/test/options-util.test.js index 8fb07263a0..70404ce5c7 100644 --- a/test/options-util.test.js +++ b/test/options-util.test.js @@ -605,7 +605,7 @@ function createOptionsUpdatedTestData1() { } ], profileCurrent: 0, - version: 35, + version: 36, global: { database: { prefixWildcardsSupported: false