mirror of
https://github.com/vale981/tdesktop
synced 2025-03-04 17:21:40 -05:00
Use only lt_count in langpacks.
This commit is contained in:
parent
63a6893fda
commit
9a4fdb1530
15 changed files with 68 additions and 94 deletions
|
@ -112,8 +112,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_chat_status_unaccessible" = "group is inaccessible";
|
||||
"lng_chat_status_members#one" = "{count} member";
|
||||
"lng_chat_status_members#other" = "{count} members";
|
||||
"lng_chat_status_members_demical#one" = "{count_decimal} member";
|
||||
"lng_chat_status_members_demical#other" = "{count_decimal} members";
|
||||
"lng_chat_status_online#one" = "{count} online";
|
||||
"lng_chat_status_online#other" = "{count} online";
|
||||
"lng_chat_status_members_online" = "{members_count}, {online_count}";
|
||||
|
@ -121,9 +119,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_channel_status" = "channel";
|
||||
"lng_group_status" = "group";
|
||||
|
||||
"lng_channel_views#one" = "{count_short}";
|
||||
"lng_channel_views#other" = "{count_short}";
|
||||
|
||||
"lng_flood_error" = "Too many tries. Please try again later.";
|
||||
"lng_gif_error" = "An error has occurred while reading GIF animation :(";
|
||||
"lng_edit_error" = "You cannot edit this message";
|
||||
|
@ -1968,10 +1963,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_polls_closed" = "Final results";
|
||||
"lng_polls_votes_count#one" = "{count} vote";
|
||||
"lng_polls_votes_count#other" = "{count} votes";
|
||||
"lng_polls_votes_count_short#one" = "{count_short} vote";
|
||||
"lng_polls_votes_count_short#other" = "{count_short} votes";
|
||||
"lng_polls_votes_count_demical#one" = "{count_decimal} vote";
|
||||
"lng_polls_votes_count_demical#other" = "{count_decimal} votes";
|
||||
"lng_polls_votes_none" = "No votes";
|
||||
"lng_polls_retract" = "Retract vote";
|
||||
"lng_polls_stop" = "Stop poll";
|
||||
|
|
|
@ -790,7 +790,7 @@ ConfirmInviteBox::ConfirmInviteBox(
|
|||
const auto status = [&] {
|
||||
if (_participants.empty() || _participants.size() >= count) {
|
||||
if (count > 0) {
|
||||
return lng_chat_status_members_demical(lt_count_decimal, count);
|
||||
return lng_chat_status_members(lt_count_decimal, count);
|
||||
} else {
|
||||
return lang(_isChannel
|
||||
? lng_channel_status
|
||||
|
|
|
@ -382,7 +382,7 @@ void PeerListRow::refreshStatus() {
|
|||
if (!chat->amIn()) {
|
||||
setStatusText(lang(lng_chat_status_unaccessible));
|
||||
} else if (chat->count > 0) {
|
||||
setStatusText(lng_chat_status_members_demical(lt_count_decimal, chat->count));
|
||||
setStatusText(lng_chat_status_members(lt_count_decimal, chat->count));
|
||||
} else {
|
||||
setStatusText(lang(lng_group_status));
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1099,7 +1099,7 @@ void HistoryMessage::setViewsCount(int32 count) {
|
|||
const auto was = views->_viewsWidth;
|
||||
views->_views = count;
|
||||
views->_viewsText = (views->_views > 0)
|
||||
? lng_channel_views(lt_count_short, views->_views)
|
||||
? Lang::FormatCountToShort(views->_views).string
|
||||
: QString();
|
||||
views->_viewsWidth = views->_viewsText.isEmpty()
|
||||
? 0
|
||||
|
|
|
@ -387,7 +387,7 @@ void HistoryPoll::updateTotalVotes() {
|
|||
_totalVotes = _poll->totalVoters;
|
||||
const auto string = !_totalVotes
|
||||
? lang(lng_polls_votes_none)
|
||||
: lng_polls_votes_count_short(lt_count_short, _totalVotes);
|
||||
: lng_polls_votes_count(lt_count_short, _totalVotes);
|
||||
_totalVotesLabel.setText(st::msgDateTextStyle, string);
|
||||
}
|
||||
|
||||
|
@ -810,7 +810,7 @@ TextState HistoryPoll::textState(QPoint point, StateRequest request) const {
|
|||
using Flag = Text::StateRequest::Flag;
|
||||
if (request.flags & Flag::LookupCustomTooltip) {
|
||||
result.customTooltipText = answer.votes
|
||||
? lng_polls_votes_count_demical(lt_count_decimal, answer.votes)
|
||||
? lng_polls_votes_count(lt_count_decimal, answer.votes)
|
||||
: lang(lng_polls_votes_none);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1798,7 +1798,7 @@ void Message::initTime() {
|
|||
}
|
||||
if (const auto views = item->Get<HistoryMessageViews>()) {
|
||||
views->_viewsText = (views->_views > 0)
|
||||
? lng_channel_views(lt_count_short, views->_views)
|
||||
? Lang::FormatCountToShort(views->_views).string
|
||||
: QString();
|
||||
views->_viewsWidth = views->_viewsText.isEmpty()
|
||||
? 0
|
||||
|
|
|
@ -775,7 +775,7 @@ void TopBarWidget::updateOnlineDisplay() {
|
|||
} else if (chat->count <= 0) {
|
||||
text = lang(lng_group_status);
|
||||
} else {
|
||||
text = lng_chat_status_members_demical(lt_count_decimal, chat->count);
|
||||
text = lng_chat_status_members(lt_count_decimal, chat->count);
|
||||
}
|
||||
} else {
|
||||
const auto self = Auth().user();
|
||||
|
@ -788,11 +788,11 @@ void TopBarWidget::updateOnlineDisplay() {
|
|||
}
|
||||
}
|
||||
if (online > 0 && !onlyMe) {
|
||||
auto membersCount = lng_chat_status_members_demical(lt_count_decimal, chat->participants.size());
|
||||
auto membersCount = lng_chat_status_members(lt_count_decimal, chat->participants.size());
|
||||
auto onlineCount = lng_chat_status_online(lt_count, online);
|
||||
text = lng_chat_status_members_online(lt_members_count, membersCount, lt_online_count, onlineCount);
|
||||
} else if (chat->participants.size() > 0) {
|
||||
text = lng_chat_status_members_demical(lt_count_decimal, chat->participants.size());
|
||||
text = lng_chat_status_members(lt_count_decimal, chat->participants.size());
|
||||
} else {
|
||||
text = lang(lng_group_status);
|
||||
}
|
||||
|
@ -814,16 +814,16 @@ void TopBarWidget::updateOnlineDisplay() {
|
|||
}
|
||||
}
|
||||
if (online && !onlyMe) {
|
||||
auto membersCount = lng_chat_status_members_demical(lt_count_decimal, channel->membersCount());
|
||||
auto membersCount = lng_chat_status_members(lt_count_decimal, channel->membersCount());
|
||||
auto onlineCount = lng_chat_status_online(lt_count, online);
|
||||
text = lng_chat_status_members_online(lt_members_count, membersCount, lt_online_count, onlineCount);
|
||||
} else if (channel->membersCount() > 0) {
|
||||
text = lng_chat_status_members_demical(lt_count_decimal, channel->membersCount());
|
||||
text = lng_chat_status_members(lt_count_decimal, channel->membersCount());
|
||||
} else {
|
||||
text = lang(lng_group_status);
|
||||
}
|
||||
} else if (channel->membersCount() > 0) {
|
||||
text = lng_chat_status_members_demical(lt_count_decimal, channel->membersCount());
|
||||
text = lng_chat_status_members(lt_count_decimal, channel->membersCount());
|
||||
} else {
|
||||
text = lang(channel->isMegagroup() ? lng_group_status : lng_channel_status);
|
||||
}
|
||||
|
|
|
@ -802,7 +802,7 @@ object_ptr<Ui::RpWidget> SetupChannelMembers(
|
|||
auto membersText = MembersCountValue(
|
||||
channel
|
||||
) | rpl::map([](int count) {
|
||||
return lng_chat_status_members_demical(lt_count_decimal, count);
|
||||
return lng_chat_status_members(lt_count_decimal, count);
|
||||
});
|
||||
auto membersCallback = [controller, channel] {
|
||||
controller->showSection(Info::Memento(
|
||||
|
|
|
@ -126,11 +126,11 @@ bool SectionToggle::checkRippleStartPosition(QPoint position) const {
|
|||
}
|
||||
|
||||
auto MembersStatusText(int count) {
|
||||
return lng_chat_status_members_demical(lt_count_decimal, count);
|
||||
return lng_chat_status_members(lt_count_decimal, count);
|
||||
};
|
||||
|
||||
auto OnlineStatusText(int count) {
|
||||
return lng_chat_status_online(lt_count, count);
|
||||
return lng_chat_status_online(lt_count_decimal, count);
|
||||
};
|
||||
|
||||
auto ChatStatusText(int fullCount, int onlineCount, bool isGroup) {
|
||||
|
@ -139,7 +139,7 @@ auto ChatStatusText(int fullCount, int onlineCount, bool isGroup) {
|
|||
lt_members_count, MembersStatusText(fullCount),
|
||||
lt_online_count, OnlineStatusText(onlineCount));
|
||||
} else if (fullCount > 0) {
|
||||
return lng_chat_status_members_demical(lt_count_decimal, fullCount);
|
||||
return lng_chat_status_members(lt_count_decimal, fullCount);
|
||||
}
|
||||
return lang(isGroup
|
||||
? lng_group_status
|
||||
|
|
|
@ -166,7 +166,7 @@ object_ptr<Ui::FlatLabel> Members::setupTitle() {
|
|||
MembersCountValue(
|
||||
_peer
|
||||
) | rpl::map([](int count) {
|
||||
return lng_chat_status_members_demical(lt_count_decimal, count);
|
||||
return lng_chat_status_members(lt_count_decimal, count);
|
||||
}) | ToUpperValue(),
|
||||
st::infoBlockHeaderLabel);
|
||||
result->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
|
|
|
@ -914,48 +914,44 @@ int NonZeroPartToInt(QString value) {
|
|||
: (value.isEmpty() ? 0 : value.toInt());
|
||||
}
|
||||
|
||||
inline QString FormatCountToShort(int64 &number) {
|
||||
ShortenedCount FormatCountToShort(int64 number) {
|
||||
auto result = ShortenedCount{ number };
|
||||
const auto abs = std::abs(number);
|
||||
auto result = QString();
|
||||
const auto shorten = [&](int64 divider, char multiplier) {
|
||||
const auto sign = (number > 0) ? 1 : -1;
|
||||
const auto rounded = abs / (divider / 10);
|
||||
result = QString::number(sign * rounded / 10);
|
||||
result.string = QString::number(sign * rounded / 10);
|
||||
if (rounded % 10) {
|
||||
result += '.' + QString::number(rounded % 10) + multiplier;
|
||||
result.string += '.' + QString::number(rounded % 10) + multiplier;
|
||||
} else {
|
||||
result += multiplier;
|
||||
result.string += multiplier;
|
||||
}
|
||||
// Update given number.
|
||||
// E.g. 12345 will be 12000.
|
||||
number = rounded * divider;
|
||||
result.number = rounded * divider;
|
||||
};
|
||||
if (abs >= 1'000'000) {
|
||||
shorten(1'000'000, 'M');
|
||||
} else if (abs >= 10'000) {
|
||||
shorten(1'000, 'K');
|
||||
} else {
|
||||
result = QString::number(number);
|
||||
result.string = QString::number(number);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PluralResult Plural(
|
||||
ushort keyBase,
|
||||
float64 value,
|
||||
PluralType type) {
|
||||
|
||||
ushort keyBase,
|
||||
float64 value,
|
||||
lngtag_count type) {
|
||||
// To correctly select a shift for PluralType::Short
|
||||
// we must first round the number.
|
||||
int64 shortenedValue = 0;
|
||||
auto shortenedNumberString = QString();
|
||||
if (type == PluralType::Short) {
|
||||
shortenedValue = qRound(value);
|
||||
shortenedNumberString = FormatCountToShort(shortenedValue);
|
||||
}
|
||||
const auto shortened = (type == lt_count_short)
|
||||
? FormatCountToShort(qRound(value))
|
||||
: ShortenedCount();
|
||||
|
||||
// Simplified.
|
||||
const auto n = std::abs(shortenedValue ? float64(shortenedValue) : value);
|
||||
const auto n = std::abs(shortened.number ? float64(shortened.number) : value);
|
||||
const auto i = qFloor(n);
|
||||
const auto integer = (qCeil(n) == i);
|
||||
const auto formatted = integer ? QString() : FormatDouble(n);
|
||||
|
@ -979,9 +975,9 @@ PluralResult Plural(
|
|||
auto string = langpack.getValue(LangKey(keyBase + shift));
|
||||
if (integer) {
|
||||
const auto round = qRound(value);
|
||||
if (type == PluralType::Short) {
|
||||
return { string, shortenedNumberString };
|
||||
} else if (type == PluralType::DecimalSeparation) {
|
||||
if (type == lt_count_short) {
|
||||
return { string, shortened.string };
|
||||
} else if (type == lt_count_decimal) {
|
||||
return { string, QString("%L1").arg(round) };
|
||||
}
|
||||
return { string, QString::number(round) };
|
||||
|
|
|
@ -7,17 +7,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
enum lngtag_count : int;
|
||||
|
||||
namespace Lang {
|
||||
|
||||
constexpr auto kTagReplacementSize = 4;
|
||||
|
||||
int FindTagReplacementPosition(const QString &original, ushort tag);
|
||||
|
||||
enum class PluralType {
|
||||
None,
|
||||
Short,
|
||||
DecimalSeparation,
|
||||
struct ShortenedCount {
|
||||
int64 number = 0;
|
||||
QString string;
|
||||
};
|
||||
ShortenedCount FormatCountToShort(int64 number);
|
||||
|
||||
struct PluralResult {
|
||||
QString string;
|
||||
|
@ -26,7 +28,7 @@ struct PluralResult {
|
|||
PluralResult Plural(
|
||||
ushort keyBase,
|
||||
float64 value,
|
||||
PluralType type = PluralType::None);
|
||||
lngtag_count type);
|
||||
void UpdatePluralRules(const QString &languageId);
|
||||
|
||||
template <typename ResultString>
|
||||
|
|
Loading…
Add table
Reference in a new issue