diff --git a/Telegram/SourceFiles/codegen/lang/generator.cpp b/Telegram/SourceFiles/codegen/lang/generator.cpp index 87c6d90b5..400a5638c 100644 --- a/Telegram/SourceFiles/codegen/lang/generator.cpp +++ b/Telegram/SourceFiles/codegen/lang/generator.cpp @@ -279,22 +279,11 @@ inline constexpr phrase<" << tags.join(", ") << "> " << (isPlural ? entry.keyBas header_->newline(); } -void Generator::writeSourceLangKeyConstants() { - source_->newline(); - auto index = 0; - for (auto &entry : langpack_.entries) { - source_->stream() << "constexpr auto " << getFullKey(entry) << " = ushort(" << (index++) << ");\n"; - } - source_->newline(); -} - bool Generator::writeSource() { source_ = std::make_unique(basePath_ + ".cpp", project_); source_->include("lang/lang_keys.h").pushNamespace("Lang").pushNamespace(); - writeSourceLangKeyConstants(); - source_->stream() << "\ QChar DefaultData[] = {"; auto count = 0; @@ -359,6 +348,19 @@ ushort GetKeyIndex(QLatin1String key) {\n\ auto size = key.size();\n\ auto data = key.data();\n"; + auto index = 0; + auto indices = std::map(); + for (auto &entry : langpack_.entries) { + indices.emplace(getFullKey(entry), QString::number(index++)); + } + const auto indexOfKey = [&](const QString &full) { + const auto i = indices.find(full); + if (i == indices.end()) { + return QString(); + } + return i->second; + }; + auto taggedKeys = std::map(); auto keysSet = std::set>(); for (auto &entry : langpack_.entries) { @@ -379,7 +381,8 @@ ushort GetKeyIndex(QLatin1String key) {\n\ writeSetSearch(keysSet, [&](const QString &key) { auto it = taggedKeys.find(key); - return (it != taggedKeys.end()) ? it->second : key; + const auto name = (it != taggedKeys.end()) ? it->second : key; + return indexOfKey(name); }, "kKeysCount"); header_->popNamespace().newline(); @@ -401,11 +404,11 @@ bool IsTagReplaced(ushort key, ushort tag) {\n\ lastWrittenPluralEntry = entry.keyBase; for (auto i = 0; i != kPluralPartCount; ++i) { source_->stream() << "\ - case " << ComputePluralKey(entry.keyBase, i) << ":" << ((i + 1 == kPluralPartCount) ? " {" : "") << "\n"; + case " << indexOfKey(ComputePluralKey(entry.keyBase, i)) << ":" << ((i + 1 == kPluralPartCount) ? " {" : "") << "\n"; } } else { source_->stream() << "\ - case " << getFullKey(entry) << ": {\n"; + case " << indexOfKey(getFullKey(entry)) << ": {\n"; } source_->stream() << "\ switch (tag) {\n"; diff --git a/Telegram/SourceFiles/codegen/lang/generator.h b/Telegram/SourceFiles/codegen/lang/generator.h index 91ec94c73..e60e370c2 100644 --- a/Telegram/SourceFiles/codegen/lang/generator.h +++ b/Telegram/SourceFiles/codegen/lang/generator.h @@ -37,8 +37,6 @@ private: void writeHeaderProducersInterface(); void writeHeaderProducersInstances(); - void writeSourceLangKeyConstants(); - QString getFullKey(const LangPack::Entry &entry); template