From a2af61d891928a85185826b40b741eed5a104696 Mon Sep 17 00:00:00 2001 From: Ruslan Kabatsayev Date: Mon, 3 Feb 2025 12:03:33 +0800 Subject: [PATCH] converter: Handle missing Stellarium locales more gracefully --- .../DescriptionOldLoader.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/util/skyculture-converter/DescriptionOldLoader.cpp b/util/skyculture-converter/DescriptionOldLoader.cpp index afa9e7f6c39c9..81ec2bdcb6ef8 100644 --- a/util/skyculture-converter/DescriptionOldLoader.cpp +++ b/util/skyculture-converter/DescriptionOldLoader.cpp @@ -1162,7 +1162,22 @@ bool DescriptionOldLoader::dump(const QString& outDir) const po_message_iterator_t iterator = po_message_iterator(file, nullptr); // I've found no API to *create* a header, so will try to emulate it with a message - const auto header = poHeaders[locale]; + const auto headerIt = poHeaders.find(locale); + if(headerIt == poHeaders.end()) + { + qWarning().nospace() << "WARNING: No header for locale " << locale << " found. " + "This could mean that either this locale is not supported by Stellarium, " + "or its designation in the description file name is wrong."; + } + static const auto defaultHeaderTemplate = QLatin1String( + "Project-Id-Version: PACKAGE VERSION\n" + "MIME-Version: 1.0\n" + "Content-Type: text/plain; charset=UTF-8\n" + "Content-Transfer-Encoding: 8bit\n" + "Language: %1\n"); + const QString header = headerIt == poHeaders.end() ? + defaultHeaderTemplate.arg(locale) : + headerIt.value(); const auto headerMsg = po_message_create(); po_message_set_msgid(headerMsg, ""); po_message_set_msgstr(headerMsg, header.toStdString().c_str());