mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-30 22:16:14 +00:00
Use only lt_count in langpacks.
This commit is contained in:
@@ -110,7 +110,18 @@ constexpr auto kTagsCount = " << langpack_.tags.size() << ";\n\
|
||||
header_->popNamespace().newline();
|
||||
auto index = 0;
|
||||
for (auto &tag : langpack_.tags) {
|
||||
header_->stream() << "enum lngtag_" << tag.tag << " { lt_" << tag.tag << " = " << index++ << " };\n";
|
||||
if (tag.tag == kPluralTags[0]) {
|
||||
auto elements = QStringList();
|
||||
header_->stream()
|
||||
<< "enum lngtag_" << tag.tag << " : int { ";
|
||||
for (auto i = 0; i != kPluralTags.size(); ++i) {
|
||||
elements.push_back("lt_" + kPluralTags[i] + " = " + QString::number(index + i * 1000));
|
||||
}
|
||||
header_->stream() << elements.join(", ") << " };\n";
|
||||
++index;
|
||||
} else {
|
||||
header_->stream() << "enum lngtag_" << tag.tag << " : int { lt_" << tag.tag << " = " << index++ << " };\n";
|
||||
}
|
||||
}
|
||||
header_->stream() << "\
|
||||
\n\
|
||||
@@ -126,13 +137,6 @@ enum LangKey : int {\n";
|
||||
QString lang(LangKey key);\n\
|
||||
\n";
|
||||
|
||||
// Plural Type Map.
|
||||
std::map<QString, QString> pluralType {
|
||||
{ kPluralTag, QString("None") },
|
||||
{ kPluralShortTag, QString("Short") },
|
||||
{ kPluralDecimalSeparationTag, QString("DecimalSeparation") }
|
||||
};
|
||||
|
||||
for (auto &entry : langpack_.entries) {
|
||||
auto isPlural = !entry.keyBase.isEmpty();
|
||||
auto &key = entry.key;
|
||||
@@ -143,11 +147,11 @@ QString lang(LangKey key);\n\
|
||||
auto nonPluralTagFound = false;
|
||||
for (auto &tagData : entry.tags) {
|
||||
auto &tag = tagData.tag;
|
||||
auto isPluralTag = isPlural && (pluralType.find(tag) != pluralType.end());
|
||||
genericParams.push_back("lngtag_" + tag + ", " + (isPluralTag ? "float64 " : "const ResultString &") + tag + "__val");
|
||||
auto isPluralTag = isPlural && (tag == kPluralTags[0]);
|
||||
genericParams.push_back("lngtag_" + tag + (isPluralTag ? " type" : "") + ", " + (isPluralTag ? "float64 " : "const ResultString &") + tag + "__val");
|
||||
params.push_back("lngtag_" + tag + ", " + (isPluralTag ? "float64 " : "const QString &") + tag + "__val");
|
||||
if (isPluralTag) {
|
||||
plural = "\tauto plural = Lang::Plural(" + key + ", " + tag + "__val, Lang::PluralType::" + pluralType[tag] + ");\n";
|
||||
plural = "\tauto plural = Lang::Plural(" + key + ", " + tag + "__val, type);\n";
|
||||
applyTags.push_back("\tresult = Lang::ReplaceTag<ResultString>::Call(std::move(result), lt_" + tag + ", Lang::StartReplacements<ResultString>::Call(std::move(plural.replacement)));\n");
|
||||
} else {
|
||||
nonPluralTagFound = true;
|
||||
|
@@ -75,15 +75,11 @@ const std::array<QString, kPluralPartCount> kPluralParts = { {
|
||||
"other",
|
||||
} };
|
||||
|
||||
const QString kPluralTag = "count";
|
||||
const QString kPluralShortTag = kPluralTag + "_short";
|
||||
const QString kPluralDecimalSeparationTag = kPluralTag + "_decimal";
|
||||
|
||||
const std::set<QString> pluralTypeSet {
|
||||
kPluralTag,
|
||||
kPluralShortTag,
|
||||
kPluralDecimalSeparationTag
|
||||
};
|
||||
const std::array<QString, kPluralTagsCount> kPluralTags = { {
|
||||
"count",
|
||||
"count_short",
|
||||
"count_decimal",
|
||||
} };
|
||||
|
||||
QString ComputePluralKey(const QString &base, int index) {
|
||||
return base + "__plural" + QString::number(index);
|
||||
@@ -153,7 +149,7 @@ void ParsedFile::fillPluralTags() {
|
||||
}
|
||||
}
|
||||
logAssert(!tags.empty());
|
||||
logAssert(pluralTypeSet.find(tags.front().tag) != pluralTypeSet.end());
|
||||
logAssert(tags.front().tag == kPluralTags[0]);
|
||||
|
||||
// Set this tags list to all plural variants.
|
||||
for (auto j = i; j != i + kPluralPartCount; ++j) {
|
||||
@@ -217,15 +213,6 @@ QString ParsedFile::extractTagData(const QString &tagText, LangPack *to) {
|
||||
logErrorBadString() << "duplicate found for tag '" << tagText.toStdString() << "'";
|
||||
return QString();
|
||||
}
|
||||
//Don't use both plural tags in one string.
|
||||
if (previousTag.tag.startsWith(kPluralTag) && tag.startsWith(kPluralTag)) {
|
||||
logErrorBadString() <<
|
||||
"duplicate found for count tag '" <<
|
||||
previousTag.tag.toStdString() <<
|
||||
"' and '" <<
|
||||
tag.toStdString() << "'";
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
auto index = 0;
|
||||
auto tagIndex = result_.tags.size();
|
||||
@@ -326,20 +313,13 @@ void ParsedFile::addEntity(QString key, const QString &value) {
|
||||
realEntry.value = entry.value;
|
||||
|
||||
// Add all new tags to the existing ones.
|
||||
realEntry.tags = std::vector<LangPack::Tag>(0);
|
||||
realEntry.tags = std::vector<LangPack::Tag>(1, LangPack::Tag{ kPluralTags[0] });
|
||||
|
||||
for (auto &tag : entry.tags) {
|
||||
if (std::find(realEntry.tags.begin(), realEntry.tags.end(), tag) == realEntry.tags.end()) {
|
||||
if (pluralTypeSet.find(tag.tag) != pluralTypeSet.end()) {
|
||||
realEntry.tags.insert(realEntry.tags.begin(), tag);
|
||||
} else {
|
||||
realEntry.tags.push_back(tag);
|
||||
}
|
||||
realEntry.tags.push_back(tag);
|
||||
}
|
||||
}
|
||||
if (realEntry.tags.empty()) {
|
||||
realEntry.tags.push_back(LangPack::Tag { kPluralTag });
|
||||
}
|
||||
} else {
|
||||
result_.entries.push_back(entry);
|
||||
for (auto &pluralEntry : tagsData.entries) {
|
||||
|
@@ -20,9 +20,10 @@ namespace lang {
|
||||
|
||||
constexpr auto kPluralPartCount = 6;
|
||||
extern const std::array<QString, kPluralPartCount> kPluralParts;
|
||||
extern const QString kPluralTag;
|
||||
extern const QString kPluralShortTag;
|
||||
extern const QString kPluralDecimalSeparationTag;
|
||||
|
||||
constexpr auto kPluralTagsCount = 3;
|
||||
extern const std::array<QString, kPluralTagsCount> kPluralTags;
|
||||
|
||||
QString ComputePluralKey(const QString &base, int index);
|
||||
|
||||
struct LangPack {
|
||||
|
Reference in New Issue
Block a user