Skip to content

Commit

Permalink
converter: Add comments for constellation names in po files
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Jan 28, 2025
1 parent dd11e41 commit 99c3409
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
8 changes: 8 additions & 0 deletions util/skyculture-converter/ConstellationOldLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ void ConstellationOldLoader::load(const QString& skyCultureDir, const QString& o
loadBoundaries(skyCultureDir);
}

auto ConstellationOldLoader::find(QString const& englishName) const -> const Constellation*
{
for(const auto& cons : constellations)
if(cons.englishName == englishName)
return &cons;
return nullptr;
}

bool ConstellationOldLoader::dumpConstellationsJSON(std::ostream& s) const
{
if(constellations.empty()) return false;
Expand Down
5 changes: 4 additions & 1 deletion util/skyculture-converter/ConstellationOldLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ConstellationOldLoader
{
QString skyCultureName;
public:
struct Constellation
{
QString abbreviation;
Expand All @@ -24,6 +24,8 @@ class ConstellationOldLoader

bool read(QString const& record);
};
private:
QString skyCultureName;
std::vector<Constellation> constellations;
struct RaDec
{
Expand All @@ -45,6 +47,7 @@ class ConstellationOldLoader
bool dumpConstellationsJSON(std::ostream& s) const;
public:
void load(const QString &skyCultureDir, const QString& outDir);
const Constellation* find(QString const& englishName) const;
bool dumpJSON(std::ostream& s) const;
bool hasBoundaries() const { return !boundaries.empty(); }
void setBoundariesType(std::string const& type) { boundariesType = type; }
Expand Down
44 changes: 31 additions & 13 deletions util/skyculture-converter/DescriptionOldLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QDebug>
#include <QRegularExpression>
#include <gettext-po.h>
#include "ConstellationOldLoader.hpp"

namespace
{
Expand Down Expand Up @@ -615,7 +616,8 @@ QString DescriptionOldLoader::translateDescription(const QString& markdownInput,

return text;
}
void DescriptionOldLoader::loadTranslationsOfNames(const QString& poBaseDir, const QString& cultureIdQS, const QString& englishName)
void DescriptionOldLoader::loadTranslationsOfNames(const QString& poBaseDir, const QString& cultureIdQS, const QString& englishName,
const ConstellationOldLoader& consLoader)
{
po_xerror_handler handler = {gettextpo_xerror, gettextpo_xerror2};
const auto cultureId = cultureIdQS.toStdString();
Expand Down Expand Up @@ -663,6 +665,14 @@ void DescriptionOldLoader::loadTranslationsOfNames(const QString& poBaseDir, con
if(!scNameTranslated)
qWarning() << "Couldn't find a translation for the name of the sky culture";

const std::vector<std::pair<std::string, std::string_view>> sourceFiles{
{"skycultures/"+cultureId+"/star_names.fab", "star"},
{"skycultures/"+cultureId+"/dso_names.fab", "dso"},
{"skycultures/"+cultureId+"/planet_names.fab", "planet"},
{"skycultures/"+cultureId+"/asterism_names.fab", "asterism"},
{"skycultures/"+cultureId+"/constellation_names.eng.fab", "constellation"},
};
QString comments;
const auto domains = po_file_domains(file);
for(auto domainp = domains; *domainp; domainp++)
{
Expand All @@ -673,23 +683,31 @@ void DescriptionOldLoader::loadTranslationsOfNames(const QString& poBaseDir, con
{
const auto msgid = po_message_msgid(message);
const auto msgstr = po_message_msgstr(message);
const auto comments = po_message_comments(message);
comments = po_message_comments(message);
const auto xcomments = po_message_extracted_comments(message);
for(int n = 0; ; ++n)
{
const auto filepos = po_message_filepos(message, n);
if(!filepos) break;
const auto refFileName = po_filepos_file(filepos);
for(const auto ref : {
"skycultures/"+cultureId+"/star_names.fab",
"skycultures/"+cultureId+"/dso_names.fab",
"skycultures/"+cultureId+"/planet_names.fab",
"skycultures/"+cultureId+"/asterism_names.fab",
"skycultures/"+cultureId+"/constellation_names.eng.fab",
})
for(const auto ref : sourceFiles)
{
if(refFileName == ref)
dict.push_back({comments, xcomments, msgid, msgstr});
if(refFileName == ref.first)
{
if(ref.second == "constellation")
{
const auto cons = consLoader.find(msgid);
if(cons && !cons->nativeName.isEmpty())
{
comments = englishName+" constellation, native: "+cons->nativeName;
}
else
{
comments = englishName+" constellation";
}
}
dict.push_back({comments.toUtf8().constData(), xcomments, msgid, msgstr});
}
}
}
}
Expand Down Expand Up @@ -719,7 +737,7 @@ void DescriptionOldLoader::locateAndRelocateAllInlineImages(QString& html, const
}

void DescriptionOldLoader::load(const QString& inDir, const QString& poBaseDir, const QString& cultureId, const QString& englishName,
const QString& author, const QString& credit, const QString& license,
const QString& author, const QString& credit, const QString& license, const ConstellationOldLoader& consLoader,
const bool fullerConversionToMarkdown, const bool footnotesToRefs, const bool convertOrderedLists,
const bool genTranslatedMD)
{
Expand Down Expand Up @@ -982,7 +1000,7 @@ void DescriptionOldLoader::load(const QString& inDir, const QString& poBaseDir,
translatedMDs[locale] = translateDescription(markdown, locale);
}

loadTranslationsOfNames(poBaseDir, cultureId, englishName);
loadTranslationsOfNames(poBaseDir, cultureId, englishName, consLoader);
}

bool DescriptionOldLoader::dumpMarkdown(const QString& outDir) const
Expand Down
6 changes: 4 additions & 2 deletions util/skyculture-converter/DescriptionOldLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QHash>
#include <QString>

class ConstellationOldLoader;
class DescriptionOldLoader
{
QString markdown;
Expand Down Expand Up @@ -35,12 +36,13 @@ class DescriptionOldLoader
QHash<QString/*locale*/, QString/*header*/> poHeaders;
bool dumpMarkdown(const QString& outDir) const;
void locateAndRelocateAllInlineImages(QString& html, bool saveToRefs);
void loadTranslationsOfNames(const QString& poBaseDir, const QString& cultureId, const QString& englishName);
void loadTranslationsOfNames(const QString& poBaseDir, const QString& cultureId, const QString& englishName,
const ConstellationOldLoader& consLoader);
QString translateSection(const QString& markdown, const qsizetype bodyStartPos, const qsizetype bodyEndPos, const QString& locale, const QString& sectionName) const;
QString translateDescription(const QString& markdown, const QString& locale) const;
public:
void load(const QString& inDir, const QString& poBaseDir, const QString& cultureId, const QString& englishName,
const QString& author, const QString& credit, const QString& license,
const QString& author, const QString& credit, const QString& license, const ConstellationOldLoader& consLoader,
bool fullerConversionToMarkdown, bool footnotesToRefs, bool convertOrderedLists, bool genTranslatedMD);
bool dump(const QString& outDir) const;
};
2 changes: 1 addition & 1 deletion util/skyculture-converter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ int main(int argc, char** argv)

DescriptionOldLoader dLoader;
license = convertLicense(license);
dLoader.load(inDir, poDir, cultureId, englishName, author, credit, license,
dLoader.load(inDir, poDir, cultureId, englishName, author, credit, license, cLoader,
fullerConversion, footnotesToRefs, convertOrderedLists, genTranslatedMD);
dLoader.dump(outDir);

Expand Down

0 comments on commit 99c3409

Please sign in to comment.