Skip to content

Commit

Permalink
feat: add skk dict generator
Browse files Browse the repository at this point in the history
  • Loading branch information
mimikun committed Nov 18, 2024
1 parent 2a81084 commit bbc9b77
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ https://github.com/kotofurumiya/genshin-dict/releases/latest
| macOS追加辞書 | 原神辞書_macOS.txt | |
| iPhoneユーザ辞書 | | mac経由で追加可能(後述) |
| Google IME | 原神辞書_Windows.txt | macでもWindows用ファイルで追加可能 |
| SKK | SKK-JISYO.genshin | SKK辞書 |

## 利用方法(Windows)

Expand Down
13 changes: 12 additions & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import fs from 'fs';
import url from 'url';
import path from 'path';
import { loadDictList } from '../worddata/index.js';
import { toKotoeriDict, toMacUserDict, toWindowsImeDict, expandVuHiragana, toUtf16BOM } from './lib/platform.js';
import {
toKotoeriDict,
toMacUserDict,
toWindowsImeDict,
expandVuHiragana,
toUtf16BOM,
toSkkDict,
} from './lib/platform.js';
import { generateDocs } from './lib/docgen.js';
import { DictItem } from '../worddata/dict.js';

Expand All @@ -14,6 +21,7 @@ const distDir = path.join(dirname, '..', 'genshin-dictionary');
const winDictFile = path.join(distDir, '原神辞書_Windows.txt');
const macDictFile = path.join(distDir, '原神辞書_macOS.txt');
const macUserDictFile = path.join(distDir, '原神辞書_macOS_ユーザ辞書.plist');
const skkDictFile = path.join(distDir, 'SKK-JISYO.genshin');

console.log('辞書データを構築しています...');

Expand All @@ -28,6 +36,7 @@ console.log('辞書データを構築しています...');
const winIme = toWindowsImeDict(words);
const kotoeri = toKotoeriDict(words);
const plist = toMacUserDict(words);
const skk = toSkkDict(words);

console.log('ドキュメントを生成しています...');

Expand All @@ -44,9 +53,11 @@ console.log('辞書データを構築しています...');
fs.writeFileSync(winDictFile, toUtf16BOM(winIme));
fs.writeFileSync(macDictFile, kotoeri, 'utf8');
fs.writeFileSync(macUserDictFile, plist, 'utf8');
fs.writeFileSync(skkDictFile, skk, 'utf8');

console.log('完了しました');
console.log(winDictFile);
console.log(macDictFile);
console.log(macUserDictFile);
console.log(skkDictFile);
})();
12 changes: 12 additions & 0 deletions scripts/lib/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ export const toUtf16BOM = (str: string): Buffer => {
const u16leBuf = Buffer.from(`\ufeff${str}`, 'utf16le');
return u16leBuf;
};

export const toSkkDict = (items: DictItem[]) => {
const head = `;; -*- fundamental -*- ; coding: utf-8 -*-
;; okuri-ari entries.
;; okuri-nasi entries.`;
const dicts = items
.map(({ hiragana, word }) => {
return `${hiragana} /${word}/`;
})
.join('\n');
return [head, dicts].join('\n');
};

0 comments on commit bbc9b77

Please sign in to comment.