diff --git a/jmdict.go b/jmdict.go index 746f7a0..ceb5835 100644 --- a/jmdict.go +++ b/jmdict.go @@ -1,6 +1,7 @@ package yomichan import ( + "errors" "os" "regexp" "strconv" @@ -48,7 +49,11 @@ func doDisplaySenseNumberTag(headword headword, entry jmdict.JmdictEntry, meta j // Display sense numbers if the entry has more than one sense // or if the headword is found in multiple entries. hash := headword.Hash() - if meta.seqToSenseCount[entry.Sequence] > 1 { + if !meta.extraMode { + return false + } else if meta.language != "eng" { + return false + } else if meta.seqToSenseCount[entry.Sequence] > 1 { return true } else if len(meta.headwordHashToSeqs[hash]) > 1 { return true @@ -68,7 +73,7 @@ func createFormsTerm(headword headword, entry jmdict.JmdictEntry, meta jmdictMet // Don't add "forms" terms to non-English dictionaries. // Information would be duplicated if users installed more // than one version. - if meta.language != "eng" { + if meta.language != "eng" || !meta.extraMode { return dbTerm{}, false } // Don't need a "forms" term for entries with one unique @@ -193,6 +198,10 @@ func extractTerms(headword headword, entry jmdict.JmdictEntry, meta jmdictMetada } func jmdExportDb(inputPath string, outputPath string, languageName string, title string, stride int, pretty bool) error { + if _, ok := langNameToCode[languageName]; !ok { + return errors.New("Unrecognized language parameter: " + languageName) + } + reader, err := os.Open(inputPath) if err != nil { return err diff --git a/jmdict_constants.go b/jmdict_constants.go index 1d49194..cb74233 100644 --- a/jmdict_constants.go +++ b/jmdict_constants.go @@ -42,17 +42,18 @@ var ISOtoFlag = map[string]string{ } var langNameToCode = map[string]string{ - "": "eng", - "english": "eng", - "dutch": "dut", - "french": "fre", - "german": "ger", - "hungarian": "hun", - "italian": "ita", - "russian": "rus", - "slovenian": "slv", - "spanish": "spa", - "swedish": "swe", + "": "eng", + "english": "eng", + "english_extra": "eng", + "dutch": "dut", + "french": "fre", + "german": "ger", + "hungarian": "hun", + "italian": "ita", + "russian": "rus", + "slovenian": "slv", + "spanish": "spa", + "swedish": "swe", } var glossTypeCodeToName = map[LangCode]string{ diff --git a/jmdict_forms.go b/jmdict_forms.go index 59df010..5d01de5 100644 --- a/jmdict_forms.go +++ b/jmdict_forms.go @@ -210,7 +210,7 @@ func formsExportDb(inputPath, outputPath, languageName, title string, stride int return err } - meta := newJmdictMetadata(dictionary, "english") + meta := newJmdictMetadata(dictionary, "") terms := dbTermList{} for _, entry := range dictionary.Entries { diff --git a/jmdict_glossary.go b/jmdict_glossary.go index 0260cbf..d116981 100644 --- a/jmdict_glossary.go +++ b/jmdict_glossary.go @@ -287,7 +287,7 @@ func createGlossaryContent(sense jmdict.JmdictSense, meta jmdictMetadata) any { func createGlossary(sense jmdict.JmdictSense, meta jmdictMetadata) []any { glossary := []any{} - if needsStructuredContent(sense, meta.language) { + if meta.extraMode && needsStructuredContent(sense, meta.language) { glossary = append(glossary, createGlossaryContent(sense, meta)) } else { for _, gloss := range sense.Glossary { diff --git a/jmdict_metadata.go b/jmdict_metadata.go index 99af862..98e35d9 100644 --- a/jmdict_metadata.go +++ b/jmdict_metadata.go @@ -23,6 +23,7 @@ type jmdictMetadata struct { entryDepth map[sequence]int hasMultipleForms map[sequence]bool maxSenseCount int + extraMode bool } type senseID struct { @@ -152,6 +153,7 @@ func newJmdictMetadata(dictionary jmdict.Jmdict, languageName string) jmdictMeta entryDepth: make(map[sequence]int), hasMultipleForms: make(map[sequence]bool), maxSenseCount: 0, + extraMode: languageName == "english_extra", } for _, entry := range dictionary.Entries { diff --git a/scripts/build_dicts.sh b/scripts/build_dicts.sh index 764d1d0..df63ac6 100755 --- a/scripts/build_dicts.sh +++ b/scripts/build_dicts.sh @@ -17,10 +17,11 @@ function refresh_source () { } refresh_source "JMdict_e_examp" -yomichan -language="english" -title="JMdict" src/JMdict_e_examp dst/jmdict_english_with_examples.zip +yomichan -language="english_extra" -title="JMdict" src/JMdict_e_examp dst/jmdict_english_extra_with_examples.zip refresh_source "JMdict" -yomichan -language="english" -title="JMdict" src/JMdict dst/jmdict_english.zip +yomichan -language="english_extra" -title="JMdict" src/JMdict dst/jmdict_english_extra.zip +yomichan -language="english" -title="JMdict (English)" src/JMdict dst/jmdict_english.zip yomichan -language="dutch" -title="JMdict (Dutch)" src/JMdict dst/jmdict_dutch.zip yomichan -language="french" -title="JMdict (French)" src/JMdict dst/jmdict_french.zip yomichan -language="german" -title="JMdict (German)" src/JMdict dst/jmdict_german.zip