FooSoft / yomichan

Japanese pop-up dictionary extension for Chrome and Firefox.
https://foosoft.net/projects/yomichan
Other
1.06k stars 223 forks source link

{glossary} with Compact glossaries + jmdict_extra is not fully compact #2297

Open Aquafina-water-bottle opened 1 year ago

Aquafina-water-bottle commented 1 year ago

Description Using the jmdict_english_extra_with_examples_2023_01_29.zip dictionary from https://github.com/FooSoft/yomichan-import/pull/40, and with Popup Appearance -> Compact glossaries enabled, the exported result of {glossary} does not properly compact some <li> elements. However, it is properly compacted on the actual popup in Yomichan.

I'm guessing it has to do with the dictionary format, i.e. the custom list-style-type.

Example: 仕舞う This example works on the 2nd entry, but not the rest. ```html
  1. (1, v5u, vt, uk, JMdict)
    • to finish
    • to stop
    • to end
    • to put an end to
    • to bring to a close
    • 買い物を済ませてしまったら電話します。
    • I will call you when I have done my shopping.
  2. (2, v5u, vt, uk, JMdict) to close (a business, etc.) | to close down | to shut down | to shut up
  3. (3, v5u, vt, uk, JMdict)
    • to put away
    • to put back
    • to keep
    • to store
    • 本とノートをしまいなさい。
    • Put away your books and notebooks.
  4. (4, aux-v, v5u, uk, JMdict)
    • to do completely
    • to finish
    • after the -te form of a verb
    • やってしまったことは元に戻らない。
    • What is done cannot be undone.
  5. (5, aux-v, v5u, uk, JMdict)
    • to do accidentally
    • to do without meaning to
    • to happen to do
    • after the -te form of a verb
  6. (forms, JMdict) 仕舞う(★) | 終う | 了う | 蔵う
``` ![image](https://user-images.githubusercontent.com/17107540/218248589-f62c6cd0-fe45-48e0-b7c8-6531870d4451.png) ![image](https://user-images.githubusercontent.com/17107540/218248396-820b518d-3323-4b83-9bfe-9093b2768039.png)
Example: 健康 This example works on the 2nd entry, but not the first. ```html
  1. (1, n, JMdict)
    • health
    • 煙草をすうことは健康に悪い。
    • Smoking is bad for the health.
  2. (2, adj-na, JMdict) healthy | sound | fit | wholesome
``` ![image](https://user-images.githubusercontent.com/17107540/218248622-a96e82c9-0caf-430b-8b19-0733baea1422.png) ![image](https://user-images.githubusercontent.com/17107540/218248505-9b26aa64-29fb-4fe9-8ef8-9b9e3aec1b22.png)
Example: 猛暑日 ```html
(n, JMdict)
  • day on which the temperature rises above 35°C
  • extremely hot day
  • see: 夏日 2. day on which the temperature reaches at least 25°C
  • see: 真夏日 day on which the temperature rises above 30°C
``` ![image](https://user-images.githubusercontent.com/17107540/218248817-179bd132-4843-4cb7-b03f-74d666bbabd4.png) ![image](https://user-images.githubusercontent.com/17107540/218248828-b3de4ed4-c6bb-4f7b-89f0-da48cab7c45f.png)

Browser version Chromium 109.0.5414.119

Yomichan version 22.10.23.0

Exported settings file The settings should be more or less the default settings, but I included it here just in case. yomichan-settings-2023-02-11-08-39-37.zip

stephenmk commented 1 year ago

Thanks for the bug report. I'll see if I can find a solution. In the meantime, you can produce the desired behavior by adding some custom CSS to your anki cards:

ul[data-sc-content="glossary"] li {
  display: inline-block;
  padding-right: 1em;
  margin-right: 1em;
  border-right: 2px solid;
}

ul[data-sc-content="glossary"] li:last-of-type {
  padding-right: 0px;
  margin-right: 0px;
  border-right: 0px solid;
}
Example: 仕舞う ![shimau](https://user-images.githubusercontent.com/8003332/218270945-1f208533-15f3-4f16-91d5-e04d1e21b24f.png)
Example: 健康 ![kenkou](https://user-images.githubusercontent.com/8003332/218271012-2b82a618-d359-4778-a51e-b92548d1cd22.png)
Example: 猛暑日 ![moushobi](https://user-images.githubusercontent.com/8003332/218271021-99b21de5-3366-4b03-ad64-e96d89433235.png)
stephenmk commented 1 year ago

First a little background on this. The normal style of glossaries are formatted in the *.json term-bank files like this:

["gloss1", "gloss2", "gloss3"]

In my current redesign of the JMdict file for Yomichan, terms with extra lists of information do not follow this format. Instead of an array of strings, the glossary array only contains one "structured-content" object. Its format looks sort of like this:

[
  {
    "type": "structured-content", 
    "content": [{list-of-glosses},
                {list-of-notes},
                {list-of-references},
                {list-of-example-sentences},
                ...
               ]
  }
]

Within the Yomichan browser popup, we only want the {list-of-glosses} content to be compacted in "compact glossaries" mode. If the example sentences and notes are compacted, they'll lose their emoji icons and line-breaks, making them difficult to distinguish from each other.

I submitted an edit for Yomichan last year which specifically targets this {list-of-glosses} content to make it compacted when "compact glossaries" mode is enabled in the browser popup. But this styling does not carry over to exported Anki cards. For the normal style of glossaries, this conversion to Anki is handled by the Handlebars.js template:

https://github.com/FooSoft/yomichan/blob/2ee3e3a7a18cc8cb71febe3030c149e0280ed9a7/ext/data/templates/default-anki-field-templates.handlebars#L23-L31

On lines 25-26 in the code above, a normal glossary like ["gloss1", "gloss2", "gloss3"] is converted into "gloss1 | gloss 2 | gloss3" during Anki card creation if Yomichan is in compact mode. For my redesigned glossaries, the "length" of the glossary array is always equal to 1 (because it only contains 1 object), and so it it processed in lines 23-24 in the code above.


So I think there are three different approaches we can take to solve this problem

  1. Update the Yomichan browser extension itself to process the {list-of-glosses} content during the export to Anki.
  2. Update my redesigned dictionary file to store the {list-of-glosses} content as regular string glosses. Like this: ["gloss1", "gloss2", "gloss3", {structured-content-object-with-all-extra-info}]
  3. Do nothing and require users to add the custom CSS styles to their Anki cards if they want the glosses compacted.

I think option #1 is probably off the table for now. Too much time and effort.

Option #2 will solve the issue, but I think it's kind of ugly. See the example images below. These are minor gripes, though.

読む in compact mode. There are trailing border symbols. ![yomu_compact](https://user-images.githubusercontent.com/8003332/218282668-84c1c971-df05-4770-aa3d-91ba2c72b4ba.png)
読む in non-compact mode. The extra glosses are no longer flush-left with the other glosses. ![yomu_non_compact](https://user-images.githubusercontent.com/8003332/218282679-e5567f8b-8161-4c0d-bef5-5f8499bfb32c.png)

Option #3 is personally my preference. In the first place, I don't think it's good for Yomichan to be removing the HTML structure from these glossaries during the export to Anki. I like to see the glossaries in "compact mode" when I'm doing reviews on my PC, but on my phone I prefer to have them in bulleted lists. As long as the HTML structure is maintained, I can use CSS to adjust the presentation of the info depending upon the window's screen size. This can't be done when the glossaries are converted to a flat string like gloss1 | gloss2 | gloss3. So I've removed that function (lines 25-26 in the code above) from my Anki export template in my Yomichan settings.

That's just my two cents. If option #2 sounds like the best solution to everyone else, I don't have a problem making that change. It's a pretty simple adjustment.

Aquafina-water-bottle commented 1 year ago

Thanks for the super detailed reply! Out of the three options, I'm personally fine with using custom CSS to compact the cards. However, I know that there are some people that highly prefer plaintext definitions, and my initial guess is that option #2 is not appealing to most people. Right now, I think it would be best to keep this issue up in case anyone wants to pick up the work in Yomichan to implement option #1 since I believe that option is best for all parties (so long as someone wants to spend the time and effort on it.)

One final note: I believe there is a 4th hacky potential option. If the dictionary for option #2 is created and named something different, say JMdict Anki, it would be possible to hide the JMdict Anki dictionary in the popup with CSS. On card export, one would have to edit the handlebars to skip the JMdict (English) dictionary, so it only exports JMdict Anki.

Thanks again for all your hard work on making these dictionaries!