Skip to content

Commit

Permalink
Merge branch 'master' into welcome-page-dictionary
Browse files Browse the repository at this point in the history
Signed-off-by: Kuuuube <[email protected]>
  • Loading branch information
Kuuuube authored Jul 29, 2024
2 parents 2bdc15f + b602851 commit e69f963
Show file tree
Hide file tree
Showing 107 changed files with 4,267 additions and 1,053 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@
"ext/js/language/sh/serbo-croatian-text-preprocessors.js",
"ext/js/language/sq/albanian-transforms.js",
"ext/js/language/vi/viet-text-preprocessors.js",
"ext/js/language/tl/tagalog-transforms.js",
"ext/js/language/text-processors.js",
"ext/js/language/translator.js",
"ext/js/language/zh/chinese.js",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/auto-approve-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
if: github.actor == 'djahandarie'
steps:
- name: Download workflow artifact
uses: dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe # v3.1.4
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: auto-approve.yml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/create-prerelease-on-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ jobs:
files: builds/*

- name: Dispatch publish-chrome-development
uses: aurelien-baudet/workflow-dispatch@93e95b157d791ae7f42aef8f8a0d3d723eba1c31 # pin@v2
uses: aurelien-baudet/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7 # pin@v2
with:
workflow: publish-chrome-development
token: ${{ secrets.GITHUB_TOKEN }}
wait-for-completion: false

- name: Dispatch publish-firefox-development
uses: aurelien-baudet/workflow-dispatch@93e95b157d791ae7f42aef8f8a0d3d723eba1c31 # pin@v2
uses: aurelien-baudet/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7 # pin@v2
with:
workflow: publish-firefox-development
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/delay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
actions: write
steps:
- name: Start the next attempt
uses: aurelien-baudet/workflow-dispatch@93e95b157d791ae7f42aef8f8a0d3d723eba1c31 # pin@v2
uses: aurelien-baudet/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7 # pin@v2
with:
workflow: ${{ github.event.inputs.workflow }}
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
path: dictionaries

- name: Grab latest screenshots from master branch
uses: dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe # pin@v2
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # pin@v2
continue-on-error: true
id: master-screenshots
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/playwright_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ jobs:
github.event.workflow_run.conclusion == 'success'
steps:
- name: Grab playwright-output from PR run
uses: dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe # pin@v2
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # pin@v2
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
run_id: ${{ github.event.workflow_run.id }}
name: playwright-output

- name: Grab master-screenshots-outcome from PR run
uses: dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe # pin@v2
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # pin@v2
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-chrome-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
# Schedule a next attempt if store refused to accept new version because it
# still has a previous one in review
- name: Start the next attempt with the delay
uses: aurelien-baudet/workflow-dispatch@93e95b157d791ae7f42aef8f8a0d3d723eba1c31 # pin@v2
uses: aurelien-baudet/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7 # pin@v2
if: |
steps.getNextAttemptNumber.outputs.result &&
steps.webStoreUpload.outputs.inReviewError == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-chrome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
# Schedule a next attempt if store refused to accept new version because it
# still has a previous one in review
- name: Start the next attempt with the delay
uses: aurelien-baudet/workflow-dispatch@93e95b157d791ae7f42aef8f8a0d3d723eba1c31 # pin@v2
uses: aurelien-baudet/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7 # pin@v2
if: |
steps.getNextAttemptNumber.outputs.result &&
steps.webStoreUpload.outputs.inReviewError == 'true'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
contents: write
steps:
- name: Dispatch publish-chrome
uses: aurelien-baudet/workflow-dispatch@93e95b157d791ae7f42aef8f8a0d3d723eba1c31 # pin@v2
uses: aurelien-baudet/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7 # pin@v2
with:
workflow: publish-chrome
token: ${{ secrets.GITHUB_TOKEN }}
wait-for-completion: false

- name: Dispatch publish-firefox
uses: aurelien-baudet/workflow-dispatch@93e95b157d791ae7f42aef8f8a0d3d723eba1c31 # pin@v2
uses: aurelien-baudet/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7 # pin@v2
with:
workflow: publish-firefox
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ Several command line arguments are available for these scripts:

If no arguments are specified, the command is equivalent to `build.bat --all`.

### Loading an unpacked build into Chromium browsers

After building, you can load the compiled extension into Chromium browsers.

- Navigate to the [extensions page](chrome://extensions/)
- Turn on the toggle on the top right that says "Developer Mode"
- Click "Load Unpacked" on the top left
- Select the `ext` folder.

Immediately you should see the "Welcome" page!

Note: Yomitan may or may not update when you make and save new code changes locally. It depends on what file you've changed. Yomitan runs as collection of two programs. There is the background process called the "service worker" and there is the frontend called the "content_script". The frontend will reload on save, but to update the backend you need to click on the update icon next to the extension in `chrome://extensions/`. If you make changes to the manifest you will need to rerun `npm run build` to regenerate the manifest file.

### Build Tools

The build process can use the [7-zip](https://www.7-zip.org/) archiving tool to create the packed zip builds
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/themoeway/yomitan/badge)](https://securityscorecards.dev/viewer/?uri=github.com/themoeway/yomitan)
[![Discord](https://dcbadge.vercel.app/api/server/UGNPMDE7zC?style=flat)](https://discord.gg/UGNPMDE7zC)

**Visit [Yomitan Wiki](https://yomitan.wiki) to learn more!**

:wave: **Yomitan is [the successor](https://foosoft.net/posts/passing-the-torch-to-yomitan/) to Yomichan** ([migration guide](./docs/yomichan-migration.md#migrating-from-yomichan)) which was [sunset](https://foosoft.net/posts/sunsetting-the-yomichan-project/) by its owner on Feb 26, 2023. We have made a number of [foundational changes](#changes) to ensure **the project stays alive, works on latest browser versions, and is easy to contribute to**.

📢 **New contributors [welcome](#contributing)!**
Expand All @@ -13,7 +15,7 @@

## What is Yomitan?

Yomitan turns your web browser into a tool for building Japanese language literacy by helping you **read** texts that would otherwise be too difficult to tackle.
Yomitan turns your web browser into a tool for building language literacy by helping you **read** texts that would otherwise be too difficult to tackle in [a variety of supported languages](./docs/supported-languages.md).

Yomitan provides powerful features not available in other browser-based dictionaries:

Expand Down Expand Up @@ -48,6 +50,7 @@ Yomitan provides powerful features not available in other browser-based dictiona
- 🕷️ [Known browser bugs](./docs/browser-bugs.md)
-[Frequently asked questions](./docs/faq.md)
- 🔒 [Browser Permissions](./docs/permissions.md)
- 🌎 [Supported Languages](./docs/supported-languages.md)

## Installation

Expand Down
4 changes: 4 additions & 0 deletions benches/japanese-language-transformer.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('japanese language transformer', () => {
'愛しい',
'愛しそう',
'愛しすぎる',
'愛し過ぎる',
'愛しかったら',
'愛しかったり',
'愛しくて',
Expand Down Expand Up @@ -67,6 +68,7 @@ describe('japanese language transformer', () => {
'食べなさい',
'食べそう',
'食べすぎる',
'食べ過ぎる',
'食べたい',
'食べたら',
'食べたり',
Expand Down Expand Up @@ -118,6 +120,7 @@ describe('japanese language transformer', () => {
'きなさい',
'きそう',
'きすぎる',
'き過ぎる',
'きたい',
'きたら',
'きたり',
Expand Down Expand Up @@ -170,6 +173,7 @@ describe('japanese language transformer', () => {
'しなさい',
'しそう',
'しすぎる',
'し過ぎる',
'したい',
'したら',
'したり',
Expand Down
4 changes: 2 additions & 2 deletions docs/anki-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Flashcard fields can be configured with the following steps:
| `{reading}` | Kana reading for the term (empty for terms where the expression is the reading). |
| `{screenshot}` | Screenshot of the web page taken at the time the term was added. |
| `{search-query}` | The full search query shown on the search page. |
| `{selection-text}` | The selected text on the search page or popup. |
| `{popup-selection-text}` | The selected text on the search page or popup. |
| `{sentence}` | Sentence, quote, or phrase that the term appears in from the source content. |
| `{sentence-furigana}` | Sentence, quote, or phrase that the term appears in from the source content, with furigana added. |
| `{single-glossary-DICT-NAME}` | Same as `{glossary}`, but with entries from only a single dictionary. The dictionary name will likely be modified, use the options from the ▼ dropdown. |
Expand Down Expand Up @@ -92,7 +92,7 @@ Flashcard fields can be configured with the following steps:
| `{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. |
| `{popup-selection-text}` | The selected text on the search page or popup. |
| `{sentence}` | Sentence, quote, or phrase that the character appears in from the source content. |
| `{sentence-furigana}` | Sentence, quote, or phrase that the character appears in from the source content, with furigana added. |
| `{stroke-count}` | Number of strokes that the kanji character has. |
Expand Down
90 changes: 85 additions & 5 deletions docs/development/language-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,26 @@ Transforms files should export a `LanguageTransformDescriptor`, which is then im

```js
// from language-transformer.d.ts
export type LanguageTransformDescriptor = {
export type LanguageTransformDescriptor<TCondition extends string = string> = {
language: string;
conditions: ConditionMapObject;
transforms: {
[name: string]: Transform;
};
conditions: ConditionMapObject<TCondition>;
transforms: TransformMapObject<TCondition>;
};

export type ConditionMapObject<TCondition extends string> = {
[type in TCondition]: Condition;
};

export type TransformMapObject<TCondition> = {
[name: string]: Transform<TCondition>;
};

```

- `language` is the ISO code of the language
- `conditions` are an object containing parts of speech and grammatical forms that are used to check which deinflections make sense. They are referenced by the deinflection rules.
- `transforms` are the actual deinflection rules
- `TCondition` is an optional generic parameter that can be passed to `LanguageTransformDescriptor`. You can learn more about it at the end of this section.

Let's try and write a bit of deinflection for English, from scratch.

Expand Down Expand Up @@ -320,6 +328,78 @@ Here, by setting `valid` to `false`, we are telling the test function to fail th

You can also optionally pass a `preprocess` helper function to `testLanguageTransformer`. Refer to the language transforms test files for its specific use case.

#### Opting in autocompletion

If you want additional type-checking and autocompletion when writing your deinflection rules, you can add them with just a few extra lines of code. Due to the limitations of TypeScript and JSDoc annotations, we will have to perform some type magic in our transformations file, but you don't need to understand what they mean in detail.

Your `english-transforms.js` file should look like this:

```js
// english-transforms.js
import { suffixInflection } from "../language-transforms.js";

/** @type {import('language-transformer').LanguageTransformDescriptor} */
export const englishTransforms = {
language: "en",
conditions: {
n: {
name: "Noun",
isDictionaryForm: true,
subConditions: ["np", "ns"],
},
np: {
name: "Noun plural",
isDictionaryForm: true,
},
ns: {
name: "Noun singular",
isDictionaryForm: true,
},
},
transforms: {
// omitted
},
};
```

To gain type-safety, we have to pass an additional `TCondition` type parameter to `LanguageTransformDescriptor`. (You can revisit its definition [at the top of this section](#deinflection-rules-aka-language-transforms))

The passed type value should be the union type of all conditions in our transforms. To find this value, we first need to move the `conditions` object outside of `englishTransforms` and extract its type by adding a `/** @typedef {keyof typeof conditions} Condition */` comment at the start of the file. Then, you just need to pass it to the `LanguageTransformDescriptor` type declaration like so:

```js
// english-transforms.js
import { suffixInflection } from "../language-transforms.js";

/** @typedef {keyof typeof conditions} Condition */

const conditions = {
n: {
name: "Noun",
isDictionaryForm: true,
subConditions: ["np", "ns"],
},
np: {
name: "Noun plural",
isDictionaryForm: true,
},
ns: {
name: "Noun singular",
isDictionaryForm: true,
},
};

/** @type {import('language-transformer').LanguageTransformDescriptor<Condition>} */
export const englishTransforms = {
language: "en",
conditions,
transforms: {
// omitted
},
};
```

Now you should be able to check for types whenever writing a deinflection rule.

### Text Postprocessors

In special cases, text may need to be modified after deinflection. These work exactly like text preprocessors, but are applied after deinflection. Currently, this is only used for Korean, where the Hangul text is disassembled into jamo during preprocessing, and so must be reassembled after deinflection.
Expand Down
2 changes: 1 addition & 1 deletion docs/development/npm-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Scripts can be executed by running `npm run <name>`.
Runs most of the tests that are used more frequently in the typical development process.

- `test:static-analysis`
Runs all of the static analysis tests.
Runs all of the static analysis tests (excluding JSON).

- `test:js`
Runs [eslint](https://eslint.org/) on all of the JavaScript and TypeScript files in the project.
Expand Down
16 changes: 10 additions & 6 deletions docs/dictionaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ Be aware that non-English dictionaries generally contain fewer entries than thei
- [JMdict](https://github.com/themoeway/jmdict-yomitan#jmdict-for-yomitan-1) - There are daily automatically updated builds of JMdict for Yomitan available in this repository. It is available in multiple languages and formats, but we recommend installing the more modern Jitendex for English users.
- [JMnedict](https://github.com/themoeway/jmdict-yomitan#jmnedict-for-yomitan) - Lists readings of person/place/organization names and other proper nouns.
- [KANJIDIC](https://github.com/themoeway/jmdict-yomitan#kanjidic-for-yomitan) - An English dictionary listing readings, meanings, and other info about kanji characters.
- [BCCWJ Frequency Dictionary](https://github.com/toasted-nutbread/yomichan-bccwj-frequency-dictionary) - A frequency dictionary based on the Balanced Corpus of Contemporary Written Japanese.
- [BCCWJ Frequency Dictionary](https://github.com/Kuuuube/yomitan-dictionaries?tab=readme-ov-file#bccwj-suw-luw-combined) - A frequency dictionary based on the Balanced Corpus of Contemporary Written Japanese.

#### Other Languages

- [KTY](https://github.com/themoeway/kaikki-to-yomitan) - Wiktionaries in various languages converted to Yomitan format.
- [KRDICT/STDICT](https://github.com/Lyroxide/yomitan-ko-dic/releases) - Korean dictionaries for Yomitan.
- [words.hk for Yomitan](https://github.com/MarvNC/wordshk-yomitan) - A free Cantonese-English and Cantonese-Cantonese dictionary for Yomitan.
- [CC-CEDICT for Yomitan](https://github.com/MarvNC/cc-cedict-yomitan) - A free Chinese-English dictionary for Yomitan.
- [Wikipedia for Yomitan](https://github.com/MarvNC/wikipedia-yomitan) - All of Japanese and Chinese Wikipedia in Yomitan.
- **Multilingual**
- [KTY](https://github.com/themoeway/kaikki-to-yomitan) - Wiktionaries in various languages converted to Yomitan format.
- [Wikipedia for Yomitan](https://github.com/MarvNC/wikipedia-yomitan) - All of Wikipedia in Yomitan for various languages.
- **Korean**
- [KRDICT/STDICT](https://github.com/Lyroxide/yomitan-ko-dic/releases) - Korean dictionaries for Yomitan.
- **Cantonese**
- [words.hk for Yomitan](https://github.com/MarvNC/wordshk-yomitan) - A free Cantonese-English and Cantonese-Cantonese dictionary for Yomitan.
- **Mandarin**
- [CC-CEDICT for Yomitan](https://github.com/MarvNC/cc-cedict-yomitan) - A free Chinese-English dictionary for Yomitan.

#### EPWING Dictionaries

Expand Down
Loading

0 comments on commit e69f963

Please sign in to comment.