From b1dcdea95ef4343b8841f52d9b24f2faa9804f7c Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 20 Aug 2021 16:59:43 +0200 Subject: [PATCH] Add language attribute to HTML output. Bug: https://schlomp.space/tastytea/epubgrep/issues/16 --- src/output.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index df3724d..a4b2f2e 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -140,8 +140,10 @@ void html_all(const std::vector> &matches_all, { std::uint64_t count{1}; - cout << "\n" - << "epubgrep output" + cout << "\n"; + // Translators: Replace “en” with your language code here. + cout << format(R"()", translate("en").str()); + cout << "epubgrep output" "" "\n\n"; @@ -182,6 +184,15 @@ void html_all(const std::vector> &matches_all, for (const auto &match : matches) { + const auto lang{[&match] + { + if (!match.language.empty()) + { + return format(R"( lang="{0:s}")", + match.language); + } + return std::string{}; + }()}; cout << " \n"; if (!opts.no_fn_epub) { @@ -190,15 +201,16 @@ void html_all(const std::vector> &matches_all, match.filepath_inside) << '\n'; } - cout << format(R"( {1:s})", - count, match.headline) + cout << format( + R"( {2:s})", count, + lang, match.headline) << '\n'; cout << format(R"( {1:s})", count, match.page) << '\n'; - cout << format(R"( {1:s})" - R"({2:s}{3:s})", - count, match.context.first, match.text, + cout << format(R"( {2:s})" + R"({3:s}{4:s})", + count, lang, match.context.first, match.text, match.context.second) << '\n'; cout << " \n";