2017-04-13 17:59:05 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-04-13 17:59:05 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-04-13 17:59:05 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "lang_auto.h"
|
2023-01-30 10:10:42 +00:00
|
|
|
#include "base/const_string.h"
|
2017-11-30 17:33:27 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2017-04-13 17:59:05 +00:00
|
|
|
|
|
|
|
namespace Lang {
|
|
|
|
|
2021-08-30 17:38:11 +00:00
|
|
|
inline constexpr auto kChoosingStickerReplacement = "oo"_cs;
|
|
|
|
|
2018-11-13 09:14:22 +00:00
|
|
|
struct Language {
|
|
|
|
QString id;
|
|
|
|
QString pluralId;
|
|
|
|
QString baseId;
|
|
|
|
QString name;
|
|
|
|
QString nativeName;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator==(const Language &a, const Language &b) {
|
|
|
|
return (a.id == b.id) && (a.name == b.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const Language &a, const Language &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
2018-08-20 11:31:40 +00:00
|
|
|
QString CloudLangPackName();
|
2018-10-22 11:13:48 +00:00
|
|
|
QString CustomLanguageId();
|
2018-11-13 09:14:22 +00:00
|
|
|
Language DefaultLanguage();
|
2017-04-18 17:37:14 +00:00
|
|
|
|
|
|
|
class Instance;
|
2020-09-30 09:11:44 +00:00
|
|
|
Instance &GetInstance();
|
2017-04-18 17:37:14 +00:00
|
|
|
|
2018-10-22 11:13:48 +00:00
|
|
|
enum class Pack {
|
|
|
|
None,
|
|
|
|
Current,
|
|
|
|
Base,
|
|
|
|
};
|
|
|
|
|
2017-05-30 17:58:25 +00:00
|
|
|
class Instance {
|
2018-10-22 11:13:48 +00:00
|
|
|
struct PrivateTag;
|
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
public:
|
2018-10-22 11:13:48 +00:00
|
|
|
Instance();
|
|
|
|
Instance(not_null<Instance*> derived, const PrivateTag &);
|
|
|
|
|
2018-11-13 09:14:22 +00:00
|
|
|
void switchToId(const Language &language);
|
2017-04-18 15:21:03 +00:00
|
|
|
void switchToCustomFile(const QString &filePath);
|
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
Instance(const Instance &other) = delete;
|
|
|
|
Instance &operator=(const Instance &other) = delete;
|
|
|
|
Instance(Instance &&other) = default;
|
|
|
|
Instance &operator=(Instance &&other) = default;
|
|
|
|
|
2017-05-30 09:31:32 +00:00
|
|
|
QString systemLangCode() const;
|
2018-08-20 11:31:40 +00:00
|
|
|
QString langPackName() const;
|
2018-10-22 11:13:48 +00:00
|
|
|
QString cloudLangCode(Pack pack) const;
|
|
|
|
QString id() const;
|
2019-06-19 11:22:25 +00:00
|
|
|
rpl::producer<QString> idChanges() const;
|
2018-10-22 11:13:48 +00:00
|
|
|
QString baseId() const;
|
2018-11-13 09:14:22 +00:00
|
|
|
QString name() const;
|
|
|
|
QString nativeName() const;
|
2018-10-22 11:13:48 +00:00
|
|
|
QString id(Pack pack) const;
|
|
|
|
bool isCustom() const;
|
|
|
|
int version(Pack pack) const;
|
2017-04-13 17:59:05 +00:00
|
|
|
|
|
|
|
QByteArray serialize() const;
|
2018-10-22 11:13:48 +00:00
|
|
|
void fillFromSerialized(const QByteArray &data, int dataAppVersion);
|
2017-04-13 17:59:05 +00:00
|
|
|
|
2021-08-30 17:38:11 +00:00
|
|
|
bool supportChoosingStickerReplacement() const;
|
2021-08-30 18:45:56 +00:00
|
|
|
int rightIndexChoosingStickerReplacement(bool named) const;
|
2021-08-30 17:38:11 +00:00
|
|
|
|
2018-10-22 11:13:48 +00:00
|
|
|
void applyDifference(
|
|
|
|
Pack pack,
|
|
|
|
const MTPDlangPackDifference &difference);
|
2019-06-19 15:42:16 +00:00
|
|
|
static std::map<ushort, QString> ParseStrings(
|
2018-08-20 11:31:40 +00:00
|
|
|
const MTPVector<MTPLangPackString> &strings);
|
2020-09-30 09:11:44 +00:00
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<> updated() const {
|
|
|
|
return _updated.events();
|
2017-04-18 15:21:03 +00:00
|
|
|
}
|
2017-04-13 17:59:05 +00:00
|
|
|
|
2019-06-19 15:42:16 +00:00
|
|
|
QString getValue(ushort key) const {
|
2019-06-21 08:58:31 +00:00
|
|
|
Expects(key < _values.size());
|
2018-08-20 11:31:40 +00:00
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
return _values[key];
|
|
|
|
}
|
2018-08-20 12:40:41 +00:00
|
|
|
QString getNonDefaultValue(const QByteArray &key) const;
|
2019-06-19 15:42:16 +00:00
|
|
|
bool isNonDefaultPlural(ushort key) const {
|
2019-06-21 08:58:31 +00:00
|
|
|
Expects(key + 5 < _nonDefaultSet.size());
|
2018-08-20 11:31:40 +00:00
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
return _nonDefaultSet[key]
|
|
|
|
|| _nonDefaultSet[key + 1]
|
|
|
|
|| _nonDefaultSet[key + 2]
|
|
|
|
|| _nonDefaultSet[key + 3]
|
|
|
|
|| _nonDefaultSet[key + 4]
|
2018-10-22 11:13:48 +00:00
|
|
|
|| _nonDefaultSet[key + 5]
|
|
|
|
|| (_base && _base->isNonDefaultPlural(key));
|
2017-06-02 11:46:02 +00:00
|
|
|
}
|
2017-04-13 17:59:05 +00:00
|
|
|
|
|
|
|
private:
|
2018-10-22 11:13:48 +00:00
|
|
|
void setBaseId(const QString &baseId, const QString &pluralId);
|
2017-05-30 09:31:40 +00:00
|
|
|
|
2018-10-22 11:13:48 +00:00
|
|
|
void applyDifferenceToMe(const MTPDlangPackDifference &difference);
|
2017-04-13 17:59:05 +00:00
|
|
|
void applyValue(const QByteArray &key, const QByteArray &value);
|
|
|
|
void resetValue(const QByteArray &key);
|
2018-11-13 09:14:22 +00:00
|
|
|
void reset(const Language &language);
|
2018-10-22 11:13:48 +00:00
|
|
|
void fillFromCustomContent(
|
|
|
|
const QString &absolutePath,
|
|
|
|
const QString &relativePath,
|
|
|
|
const QByteArray &content);
|
|
|
|
bool loadFromCustomFile(const QString &filePath);
|
2017-04-13 17:59:05 +00:00
|
|
|
void loadFromContent(const QByteArray &content);
|
2018-08-20 11:31:40 +00:00
|
|
|
void loadFromCustomContent(
|
|
|
|
const QString &absolutePath,
|
|
|
|
const QString &relativePath,
|
|
|
|
const QByteArray &content);
|
2017-06-02 11:46:02 +00:00
|
|
|
void updatePluralRules();
|
2021-08-30 18:45:56 +00:00
|
|
|
void updateChoosingStickerReplacement();
|
2017-04-13 17:59:05 +00:00
|
|
|
|
2018-10-22 11:13:48 +00:00
|
|
|
Instance *_derived = nullptr;
|
|
|
|
|
|
|
|
QString _id, _pluralId;
|
2019-06-19 11:22:25 +00:00
|
|
|
rpl::event_stream<QString> _idChanges;
|
2018-11-13 09:14:22 +00:00
|
|
|
QString _name, _nativeName;
|
2017-04-13 17:59:05 +00:00
|
|
|
QString _customFilePathAbsolute;
|
|
|
|
QString _customFilePathRelative;
|
|
|
|
QByteArray _customFileContent;
|
|
|
|
int _version = 0;
|
2020-09-30 09:11:44 +00:00
|
|
|
rpl::event_stream<> _updated;
|
2017-04-18 15:21:03 +00:00
|
|
|
|
2021-08-30 18:45:56 +00:00
|
|
|
struct {
|
|
|
|
bool support = false;
|
|
|
|
int rightIndex = 0;
|
|
|
|
int rightIndexNamed = 0;
|
|
|
|
} _choosingStickerReplacement;
|
2021-08-30 17:38:11 +00:00
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
mutable QString _systemLanguage;
|
|
|
|
|
|
|
|
std::vector<QString> _values;
|
2017-06-02 11:46:02 +00:00
|
|
|
std::vector<uchar> _nonDefaultSet;
|
2017-04-13 17:59:05 +00:00
|
|
|
std::map<QByteArray, QByteArray> _nonDefaultValues;
|
|
|
|
|
2018-10-22 11:13:48 +00:00
|
|
|
std::unique_ptr<Instance> _base;
|
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
};
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
namespace details {
|
|
|
|
|
2019-06-19 15:42:16 +00:00
|
|
|
QString Current(ushort key);
|
2020-09-30 09:11:44 +00:00
|
|
|
rpl::producer<QString> Value(ushort key);
|
2019-06-18 12:16:43 +00:00
|
|
|
|
|
|
|
} // namespace details
|
2017-04-13 17:59:05 +00:00
|
|
|
} // namespace Lang
|