package bible import "strings" // canonical English book names, in corpus form. // aliasSeed maps a canonical name to its accepted aliases (Polish abbrev, Polish // full name, English abbrev). Ported verbatim from offline_readings book_aliases.py. var aliasSeed = map[string][]string{ "Genesis": {"Rdz", "Rodzaju", "Gen"}, "Exodus": {"Wj", "Wyjścia", "Ex", "Exod"}, "Leviticus": {"Kpł", "Kapłańska", "Lev"}, "Numbers": {"Lb", "Liczb", "Num"}, "Deuteronomy": {"Pwt", "Powtórzonego Prawa", "Deut"}, "Joshua": {"Joz", "Jozuego", "Jozue"}, "Judges": {"Sdz", "Sędziów"}, "Ruth": {"Rt", "Rut"}, "1 Samuel": {"1 Sm", "1 Samuela"}, "2 Samuel": {"2 Sm", "2 Samuela"}, "1 Kings": {"1 Krl", "1 Królewska"}, "2 Kings": {"2 Krl", "2 Królewska"}, "1 Chronicles": {"1 Krn", "1 Kronik"}, "2 Chronicles": {"2 Krn", "2 Kronik"}, "Ezra": {"Ezd", "Ezdrasza"}, "Nehemiah": {"Ne", "Nehemiasza"}, "Tobit": {"Tb", "Tobiasza"}, "Judith": {"Jdt", "Judyty"}, "Esther": {"Est", "Estery"}, "Job": {"Hi", "Hioba"}, "Psalms": {"Ps", "Psalm", "Psalmy", "Psalmów"}, "Proverbs": {"Prz", "Przysłów", "Przypowieści"}, "Ecclesiastes": {"Koh", "Koheleta", "Eklezjastes"}, "Song of Solomon": {"Pnp", "Pieśń nad Pieśniami", "Pnp"}, "Wisdom": {"Mdr", "Mądrości", "Księga Mądrości"}, "Sirach": {"Syr", "Syracha", "Eklezjastyk", "Mądrość Syracha"}, "Isaiah": {"Iz", "Izajasza"}, "Jeremiah": {"Jr", "Jeremiasza"}, "Lamentations": {"Lm", "Lamentacje", "Treny"}, "Baruch": {"Ba", "Barucha"}, "Ezekiel": {"Ez", "Ezechiela"}, "Daniel": {"Dn", "Daniela"}, "Hosea": {"Oz", "Ozeasza"}, "Joel": {"Jl", "Joela"}, "Amos": {"Am", "Amosa"}, "Obadiah": {"Ab", "Abdiasza"}, "Jonah": {"Jon", "Jonasza"}, "Micah": {"Mi", "Micheasza"}, "Nahum": {"Na", "Nahuma"}, "Habakkuk": {"Ha", "Habakuka"}, "Zephaniah": {"So", "Sofoniasza"}, "Haggai": {"Ag", "Aggeusza"}, "Zechariah": {"Za", "Zachariasza"}, "Malachi": {"Ml", "Malachiasza"}, "1 Maccabees": {"1 Mch", "1 Machabejska", "1 Mach"}, "2 Maccabees": {"2 Mch", "2 Machabejska", "2 Mach"}, "Matthew": {"Mt", "Mateusza", "Mateusz"}, "Mark": {"Mk", "Marka", "Marek"}, "Luke": {"Łk", "Łukasza", "Łukasz"}, "John": {"J", "Jan", "Jana"}, "The Acts": {"Dz", "Dzieje", "Dzieje Apostolskie", "Acts"}, "Romans": {"Rz", "Rzymian"}, "1 Corinthians": {"1 Kor", "1 Koryntian"}, "2 Corinthians": {"2 Kor", "2 Koryntian"}, "Galatians": {"Ga", "Galatów", "Galacjan"}, "Ephesians": {"Ef", "Efezjan"}, "Philippians": {"Flp", "Filipian"}, "Colossians": {"Kol", "Kolosan"}, "1 Thessalonians": {"1 Tes", "1 Tesaloniczan"}, "2 Thessalonians": {"2 Tes", "2 Tesaloniczan"}, "1 Timothy": {"1 Tm", "1 Tymoteusza"}, "2 Timothy": {"2 Tm", "2 Tymoteusza"}, "Titus": {"Tt", "Tytusa"}, "Philemon": {"Flm", "Filemona"}, "Hebrews": {"Hbr", "Hebrajczyków", "Żydów"}, "James": {"Jk", "Jakuba"}, "1 Peter": {"1 P", "1 Piotra"}, "2 Peter": {"2 P", "2 Piotra"}, "1 John": {"1 J", "1 Jana"}, "2 John": {"2 J", "2 Jana"}, "3 John": {"3 J", "3 Jana"}, "Jude": {"Jud", "Judy"}, "Revelation": {"Ap", "Apokalipsa", "Objawienie"}, } var aliasMap map[string]string // lowercased alias -> canonical var canonical []string // canonical names for prefix matching func init() { aliasMap = map[string]string{} seen := map[string]bool{} for name, aliases := range aliasSeed { canonical = append(canonical, name) for _, a := range append([]string{name}, aliases...) { k := strings.ToLower(a) if !seen[k] { seen[k] = true aliasMap[k] = name } } } } // ResolveBook maps an English name/prefix or a Polish alias to a canonical book. func ResolveBook(query string) (string, bool) { q := strings.ToLower(strings.TrimSpace(query)) if c, ok := aliasMap[q]; ok { // exact alias/name return c, true } for _, name := range canonical { // canonical prefix, len>=2 if len(q) >= 2 && strings.HasPrefix(strings.ToLower(name), q) { return name, true } } return "", false } // canonOrder lists every aliasSeed book in scriptural (Catholic canon) order: // 46 Old Testament books then 27 New Testament. It is the ONLY hand-maintained // ordering; the display names are still derived from aliasSeed so there is one // source of truth for spellings. A test asserts canonOrder and aliasSeed hold // exactly the same set. var canonOrder = []string{ // Old Testament "Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Tobit", "Judith", "Esther", "1 Maccabees", "2 Maccabees", "Job", "Psalms", "Proverbs", "Ecclesiastes", "Song of Solomon", "Wisdom", "Sirach", "Isaiah", "Jeremiah", "Lamentations", "Baruch", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi", // New Testament "Matthew", "Mark", "Luke", "John", "The Acts", "Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation", } // BookInfo is one Biblical book's display data for the --list-pl/--list-en // commands (and, in later phases, the reader book pickers). type BookInfo struct { English string // canonical English name, e.g. "John" (the aliasSeed key) Polish string // Polish name, e.g. "Jan" (aliasSeed value [1]) Abbrev string // Polish citation abbreviation, e.g. "J" (aliasSeed value [0]) } // Books returns every Biblical book in scriptural order with its English name, // Polish name and citation abbreviation, all derived from aliasSeed. func Books() []BookInfo { out := make([]BookInfo, 0, len(canonOrder)) for _, name := range canonOrder { a := aliasSeed[name] out = append(out, BookInfo{English: name, Polish: a[1], Abbrev: a[0]}) } return out }