-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
50 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Mouse Dictionary (https://github.com/wtetsu/mouse-dictionary/) | ||
* Copyright 2018-present wtetsu | ||
* Licensed under MIT | ||
*/ | ||
|
||
import entry from "../entry"; | ||
import entryGeneratorJa from "./ja"; | ||
import entryGeneratorEn from "./en"; | ||
|
||
// Can add other languages here | ||
const generators = { | ||
en: entryGeneratorEn, | ||
ja: entryGeneratorJa, | ||
default: entryGeneratorEn, | ||
}; | ||
|
||
let languageDetector = (text) => (isEnglishText(text) ? "en" : "ja"); | ||
|
||
const isEnglishText = (str) => { | ||
let result = true; | ||
for (let i = 0; i < str.length; i++) { | ||
const code = str.charCodeAt(i); | ||
const isEnglishLike = (0x20 <= code && code <= 0x7e) || code === 0x2011 || code === 0x200c; | ||
if (!isEnglishLike) { | ||
result = false; | ||
break; | ||
} | ||
} | ||
return result; | ||
}; | ||
|
||
const build = () => { | ||
return entry.build(languageDetector, generators); | ||
}; | ||
|
||
export default build; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters