https://www.electronjs.org/ja/docs/latest/tutorial/spellchecker • 59 KB fetched Open original page
スペルチェッカー | Electron
メインコンテンツへ飛ぶ
Electron ドキュメント API ブログ ツール
* Electron Forge
* Electron Fiddle
コミュニティ
* ガバナンス
* 事例紹介
* リソース
リリース 日本語
* English
* Deutsch
* Español
* Français
* 日本語
* Português
* Русский
* 中文
検索
* はじめよう
* Electron のプロセス
* ベストプラクティス
* サンプル
* ダークモード
* デバイスアクセス
* アプリ内購入
*
* キーボード ショート カット
* ディープリンク
* デスクトップランチャーアクション
*
* Menus
* マルチスレッド
* ネイティブなファイルのドラッグ&ドロップ
* ナビゲーション履歴
* 通知
* オフスクリーンレンダリング
* オンライン/オフライン イベントの検出
* プログレスバー
* 最近使用したドキュメント
*
*
* BrowserWindow が表すファイル
*
* スペルチェッカー
* ウェブ埋め込み
* タスクバーのカスタマイズ
*
* ウインドウのカスタマイズ
* 開発
* Native Node Modules
* 配布方法
* テストとデバッグ
* リファレンス
* コントリビューション
*
* サンプル
* スペルチェッカー 目次
スペルチェッカー
v8 以降の Electron は Chromium のスペルチェッカーを内蔵しています。 WindowsとLinuxではHunspell辞書が搭載されており、macOSではネイティブのspellchecker APIが使用されています。
スペルチェッカーを有効にする方法は?
Electron v9 以降では、スペルチェッカーはデフォルトで有効になっています。 Electron 8 では、 webPreferences で有効にする必要があります。
const myWindow = new BrowserWindow ( {
webPreferences : {
spellcheck : true
}
} )
スペルチェッカーが使用する言語を設定する方法は?
macOS ではネイティブ API を使用しているため、スペルチェッカーが使用する言語を設定する方法はありません。 macOS では、デフォルトでネイティブのスペルチェッカーが自動的に使用されている言語を検出します。
Windows および Linux の場合、スペルチェッカーの言語を設定するために使用する Electron API がいくつかあります。
// アメリカ英語とフランス語のチェックする
myWindow . webContents . session . setSpellCheckerLanguages ( [ 'en-US' , 'fr' ] )
// 利用できる言語コードの配列
const possibleLanguages = myWindow . webContents . session . availableSpellCheckerLanguages
デフォルトで、spellchecker は現在の OS ロケールに一致する言語を有効にします。
スペルチェッカーの結果をコンテキストメニューに入れるには?
All the required information to generate a context menu is provided in the context-menu event on each webContents instance. この情報を使ってコンテキストメニューを作る簡単な方法を以下に示します。
const { Menu , MenuItem } = require ( 'electron' )
myWindow . webContents . on ( 'context-menu' , ( event , params ) => {
const menu = new Menu ( )
// スペルの補完をそれぞれ追加します
for ( const suggestion of params . dictionarySuggestions ) {
menu . append ( new MenuItem ( {
label : suggestion ,
click : ( ) => myWindow . webContents . replaceMisspelling ( suggestion )
} ) )
}
// ユーザーがスペルミスの単語を辞書に登録できるようにします
if ( params . misspelledWord ) {
menu . append (
new MenuItem ( {
label : 'Add to dictionary' ,
click : ( ) => myWindow . webContents . session . addWordToSpellCheckerDictionary ( params . misspelledWord )
} )
)
}
menu . popup ( )
} )
スペルチェッカーは Google サービスを使用していますか?
スペルチェッカー自体はタイプした文字列をGoogleサービスへ送信しませんが、 hunspell 辞書ファイルがGoogle CDNからダウンロードされます。 この動作を避けたい場合は、辞書をダウンロードするための代替URLを指定することができます。
myWindow . webContents . session . setSpellCheckerDictionaryDownloadURL ( 'https://example.com/dictionaries/' )
Check out the docs for session.setSpellCheckerDictionaryDownloadURL for more information on where to get the dictionary files from and how you need to host them.
このページを編集
前
BrowserWindow が表すファイル
次
ウェブ埋め込み
* スペルチェッカーを有効にする方法は?
* スペルチェッカーが使用する言語を設定する方法は?
* スペルチェッカーの結果をコンテキストメニューに入れるには?
* スペルチェッカーは Google サービスを使用していますか?
ドキュメント
* 始めましょう
* API リファレンス
チェックリスト
* パフォーマンス
* セキュリティ
ツール
* Electron Forge
* Electron Fiddle
コミュニティ
* ガバナンス
* リソース
* Discord
* Bluesky
* X
* Mastodon
* Stack Overflow
その他
* GitHub
* Open Collective
* Infrastructure Dashboard
Copyright OpenJS Foundation and Electron contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation , please see our Trademark Policy and Trademark List . Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them. The OpenJS Foundation | Terms of Use | Privacy Policy | Bylaws | Code of Conduct | Trademark Policy | Trademark List | Cookie Policy
Hosting and infrastructure graciously provided by