2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-30 22:16:14 +00:00

Added generation of string with decimal separated numbers.

- Added new plural tag "kPluralDecimalSeparationTag".
 - Added Lang::PluralType for default, shorted and decimal separated numbers.
 - Replaced members and votes count with decimal separated type.
This commit is contained in:
23rd
2019-05-03 16:12:23 +03:00
committed by John Preston
parent 5d321f7c59
commit 5901b42a83
13 changed files with 57 additions and 28 deletions

View File

@@ -126,6 +126,13 @@ 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;
@@ -136,12 +143,11 @@ QString lang(LangKey key);\n\
auto nonPluralTagFound = false;
for (auto &tagData : entry.tags) {
auto &tag = tagData.tag;
auto isPluralTag = isPlural && (tag == kPluralTag || tag == kPluralShortTag);
auto isPluralTag = isPlural && (pluralType.find(tag) != pluralType.end());
genericParams.push_back("lngtag_" + tag + ", " + (isPluralTag ? "float64 " : "const ResultString &") + tag + "__val");
params.push_back("lngtag_" + tag + ", " + (isPluralTag ? "float64 " : "const QString &") + tag + "__val");
if (isPluralTag) {
const auto isShortTag = (tag == kPluralShortTag) ? ("true") : ("false");
plural = "\tauto plural = Lang::Plural(" + key + ", " + tag + "__val, " + isShortTag + ");\n";
plural = "\tauto plural = Lang::Plural(" + key + ", " + tag + "__val, Lang::PluralType::" + pluralType[tag] + ");\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;

View File

@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "codegen/lang/parsed_file.h"
#include <iostream>
#include <set>
#include <QtCore/QMap>
#include <QtCore/QDir>
#include <QtCore/QRegularExpression>
@@ -76,6 +77,13 @@ const std::array<QString, kPluralPartCount> kPluralParts = { {
const QString kPluralTag = "count";
const QString kPluralShortTag = kPluralTag + "_short";
const QString kPluralDecimalSeparationTag = kPluralTag + "_decimal";
const std::set<QString> pluralTypeSet {
kPluralTag,
kPluralShortTag,
kPluralDecimalSeparationTag
};
QString ComputePluralKey(const QString &base, int index) {
return base + "__plural" + QString::number(index);
@@ -145,7 +153,7 @@ void ParsedFile::fillPluralTags() {
}
}
logAssert(!tags.empty());
logAssert(tags.front().tag == kPluralTag || tags.front().tag == kPluralShortTag);
logAssert(pluralTypeSet.find(tags.front().tag) != pluralTypeSet.end());
// Set this tags list to all plural variants.
for (auto j = i; j != i + kPluralPartCount; ++j) {
@@ -322,7 +330,7 @@ void ParsedFile::addEntity(QString key, const QString &value) {
for (auto &tag : entry.tags) {
if (std::find(realEntry.tags.begin(), realEntry.tags.end(), tag) == realEntry.tags.end()) {
if (tag.tag == kPluralTag || tag.tag == kPluralShortTag) {
if (pluralTypeSet.find(tag.tag) != pluralTypeSet.end()) {
realEntry.tags.insert(realEntry.tags.begin(), tag);
} else {
realEntry.tags.push_back(tag);

View File

@@ -22,6 +22,7 @@ constexpr auto kPluralPartCount = 6;
extern const std::array<QString, kPluralPartCount> kPluralParts;
extern const QString kPluralTag;
extern const QString kPluralShortTag;
extern const QString kPluralDecimalSeparationTag;
QString ComputePluralKey(const QString &base, int index);
struct LangPack {