From 26e6b1c20940fc766c4eadbd64563f0da1880908 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sat, 7 Jan 2023 03:31:40 +0100 Subject: [PATCH] LyXHTML and DocBook: encode language codes as BCP47. --- src/Buffer.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 0728722168..907026eb12 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2172,8 +2172,14 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os, mathmlNamespace = + " xmlns:" + mathmlPrefix + "=\"http://www.w3.org/1998/Math/MathML\""; } + // XML-compatible language code: in lib/languages, language codes are + // given as dictionary file names; HTML5 expects to follow BCP47. This + // function implements a simple heuristic that does the conversion. + std::string htmlCode = params().language->code(); + std::replace(htmlCode.begin(), htmlCode.end(), '_', '-'); + // Directly output the root tag, based on the current type of document. - string attributes = "xml:lang=\"" + params().language->code() + '"' + string attributes = "xml:lang=\"" + htmlCode + '"' + " xmlns=\"http://docbook.org/ns/docbook\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + mathmlNamespace @@ -2239,8 +2245,14 @@ Buffer::ExportStatus Buffer::writeLyXHTMLSource(odocstream & os, output == FullSource || output == OnlyBody || output == IncludedFile; if (output_preamble) { + // HTML5-compatible language code: in lib/languages, language codes are + // given as dictionary file names; HTML5 expects to follow BCP47. This + // function implements a simple heuristic that does the conversion. + std::string htmlCode = params().language->code(); + std::replace(htmlCode.begin(), htmlCode.end(), '_', '-'); + os << "\n" - << "code()) << "\">\n" + << "\n" << "\n" << "\n" << "\n" -- 2.39.5