Michael-F-Bryan/mdbook-epub

[Feature Request] Configure language in EPUB metadata

glatavento opened this issue · 3 comments

Firstly, many thanks to your efforts.

It seems that mdbook-epub set "en" as default language in EPUB metadata:

self.builder.metadata("lang", "en")?;

I found there is a language field in mdbook's book.toml (see general.md), how about writing this option to generated EPUB? This will save a lot of effort for non-English users.

Best regards.

That option goes from mdbook, see here :
https://github.com/rust-lang/mdBook/blob/336640633b1741de644e971a1a2cd8b30c595368/src/config.rs#L419
If I'm not mistaken you can specify it in 'book.toml' file.

I've used such 'lang value' in my fork code for appending such value as part of output 'epub file name'.
See here:
https://github.com/blandger/mdbook-epub/blob/3e9e66e1a836afa7648095653c7bf16212e20c6f/src/lib.rs#L132

So you can use it if you want. The other thing it's not used by mdbook-epub code at all now.

Sorry for my clumsy expression, I found EPUB itself already contains language data (see dc:language, or check content.opf in epub file), and change this

self.builder.metadata("lang", "en")?;

to this

if let Some(lang) = self.ctx.config.book.language.clone() {
    self.builder.metadata("lang", lang)?;
} else {
    self.builder.metadata("lang", "en")?;
}

can write language value (specified in book.toml) to EPUB's metadata. I tried this and it works well, so I'll make a PR; but I'm not a rust expert (nor a EPUB expert), so please correct me if I didn't get it right.

Seems correct, go ahead pls.