Closed
Description
Currently, the internal representation is very uni-language focused. We have one struct MDBook
containing all the information and the chapters for the book.
To support multiple languages we have to store multiple books with different metadata. There should be one default language, the rest are assumed to be translations.
I propose that MDBook
holds a hashmap with language codes like "en"
or "fr"
as keys and Book
s as values.
pub struct MDBook<'a> {
books: HashMap<&'a str, Book>,
// Other fields omitted
}
The Book
structure would be defined as follows:
pub struct Book {
metadata: BookMetadata,
preface: Vec<Chapter>,
chapters: Vec<Chapter>,
appendix: Vec<Chapter>,
}
Chapter
would be
pub struct Chapter {
title: String,
file: path::PathBuf,
sub_chapters: Vec<Chapter>,
}
And BookMetadata
would be
pub struct BookMetadata {
pub title: String,
pub description: String,
pub language: Language,
authors: Vec<Author>,
translators: Vec<Author>,
}
And finally Author
and Language
would be
pub struct Author {
name: String,
email: Option<String>,
}
pub struct Language {
name: String,
code: String,
}
This is what PR #147 implements. (not merged)
It allows to represent multiple languages, each with different book structures, authors / translators etc.
Open questions
- Would there be a better way to represent the books?
- How do we represent the default language?
Store the key (language code) for the default language inMDBook
?