Partial implementation of translation/bible loader.
This commit is contained in:
parent
4d40197bf3
commit
91b4b6fc95
2 changed files with 67 additions and 7 deletions
|
|
@ -4,6 +4,9 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -12,8 +15,55 @@ type Translations struct {
|
|||
}
|
||||
|
||||
type Bible struct {
|
||||
Path string
|
||||
Metadata *Metadata
|
||||
Path string `json:"path"`
|
||||
Enabled string `json:"enabled"`
|
||||
Metadata *Metadata `json:"-"`
|
||||
}
|
||||
|
||||
func NewBible(root, translation string) (b *Bible, err error) {
|
||||
var translations Translations
|
||||
var buf []byte
|
||||
var ok bool
|
||||
var fp *os.File
|
||||
|
||||
fp, err = os.Open(filepath.Join(root, "translations.json"))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
buf, err = io.ReadAll(fp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = fp.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(buf, &translations); err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(translations, string(buf))
|
||||
|
||||
if b, ok = translations.Bibles[translation]; !ok {
|
||||
return
|
||||
}
|
||||
|
||||
fp, err = os.Open(filepath.Join(root, b.Path, "meta.json"))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer fp.Close()
|
||||
|
||||
buf, err = io.ReadAll(fp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(buf, &b.Metadata); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type Metadata struct {
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ func Test_ChapterJSON(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(ch)
|
||||
/*fmt.Println(ch)
|
||||
fmt.Println(ch.ChapterDecl)
|
||||
fmt.Println("length:", len(ch.ChapterDecl.Content))
|
||||
|
||||
fmt.Println(ch.NumVerses, ch.ChapterDecl.Number)
|
||||
fmt.Println(ch.NumVerses, ch.ChapterDecl.Number)*/
|
||||
|
||||
if ch.NumVerses != 31 {
|
||||
t.Errorf("expected 31 verses in Genesis 1, got %d", ch.NumVerses)
|
||||
|
|
@ -83,11 +83,21 @@ func Test_VerseFilter(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(ch.FilterVerses(1, 2))
|
||||
//fmt.Println(ch.FilterVerses(1, 2))
|
||||
v := ch.FilterVerses(27, 27)
|
||||
fmt.Println(v)
|
||||
//fmt.Println(v)
|
||||
v.SkipLineBreaks = true
|
||||
fmt.Println(v)
|
||||
//fmt.Println(v)
|
||||
|
||||
t.Error(".")
|
||||
}
|
||||
|
||||
func Test_NewBible(t *testing.T) {
|
||||
b, err := bible.NewBible("../../data", "bsb")
|
||||
if err != nil {
|
||||
t.Error("error loading Bible (BSB):", err)
|
||||
}
|
||||
|
||||
fmt.Println("bible:", b)
|
||||
t.Error(".")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue