ZaStoGram_desktop/Telegram/SourceFiles/chat_helpers/spellchecker_locale_ids.cpp

743 lines
11 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "chat_helpers/spellchecker_locale_ids.h"
#include <QtCore/QLocale>
#include <QtCore/QtGlobal>
#include <limits>
namespace Spellchecker {
namespace {
constexpr auto kFactor = 1000;
struct IdPair {
int qt5 = 0;
int qt6 = 0;
};
constexpr IdPair kLanguages[] = {
{ 3, 220 },
{ 4, 3 },
{ 5, 4 },
{ 6, 9 },
{ 7, 11 },
{ 8, 14 },
{ 9, 17 },
{ 10, 18 },
{ 11, 24 },
{ 12, 25 },
{ 13, 32 },
{ 14, 33 },
{ 15, 30 },
{ 16, 73 },
{ 18, 39 },
{ 19, 43 },
{ 20, 45 },
{ 21, 46 },
{ 22, 35 },
{ 23, 135 },
{ 24, 48 },
{ 25, 58 },
{ 26, 64 },
{ 27, 66 },
{ 28, 67 },
{ 29, 68 },
{ 30, 72 },
{ 31, 75 },
{ 32, 77 },
{ 33, 78 },
{ 34, 81 },
{ 35, 82 },
{ 36, 84 },
{ 37, 85 },
{ 38, 318 },
{ 39, 88 },
{ 40, 90 },
{ 41, 93 },
{ 42, 94 },
{ 43, 96 },
{ 44, 127 },
{ 45, 97 },
{ 46, 98 },
{ 47, 101 },
{ 48, 103 },
{ 49, 105 },
{ 50, 107 },
{ 51, 108 },
{ 52, 112 },
{ 53, 114 },
{ 54, 115 },
{ 55, 116 },
{ 56, 117 },
{ 57, 118 },
{ 58, 119 },
{ 59, 120 },
{ 60, 121 },
{ 61, 130 },
{ 62, 132 },
{ 63, 133 },
{ 64, 138 },
{ 65, 150 },
{ 66, 142 },
{ 67, 148 },
{ 68, 238 },
{ 69, 153 },
{ 70, 154 },
{ 71, 155 },
{ 72, 158 },
{ 73, 160 },
{ 74, 169 },
{ 75, 174 },
{ 76, 176 },
{ 77, 175 },
{ 78, 177 },
{ 79, 181 },
{ 80, 183 },
{ 81, 184 },
{ 82, 191 },
{ 83, 196 },
{ 84, 199 },
{ 85, 209 },
{ 86, 214 },
{ 87, 215 },
{ 88, 227 },
{ 89, 228 },
{ 90, 230 },
{ 91, 231 },
{ 92, 233 },
{ 93, 234 },
{ 94, 236 },
{ 95, 235 },
{ 96, 239 },
{ 97, 244 },
{ 98, 245 },
{ 99, 247 },
{ 100, 252 },
{ 101, 222 },
{ 102, 268 },
{ 103, 297 },
{ 104, 254 },
{ 105, 259 },
{ 106, 260 },
{ 107, 274 },
{ 108, 262 },
{ 109, 263 },
{ 110, 265 },
{ 111, 270 },
{ 112, 272 },
{ 113, 273 },
{ 114, 275 },
{ 115, 249 },
{ 116, 282 },
{ 117, 283 },
{ 118, 286 },
{ 119, 287 },
{ 120, 289 },
{ 121, 290 },
{ 122, 292 },
{ 123, 295 },
{ 124, 296 },
{ 125, 298 },
{ 126, 299 },
{ 127, 279 },
{ 128, 306 },
{ 129, 303 },
{ 130, 305 },
{ 131, 307 },
{ 132, 310 },
{ 133, 311 },
{ 134, 316 },
{ 135, 320 },
{ 136, 321 },
{ 137, 323 },
{ 138, 324 },
{ 139, 326 },
{ 140, 327 },
{ 141, 210 },
{ 142, 42 },
{ 143, 69 },
{ 144, 180 },
{ 145, 63 },
{ 146, 6 },
{ 147, 141 },
{ 148, 89 },
{ 149, 110 },
{ 150, 129 },
{ 151, 277 },
{ 152, 40 },
{ 153, 92 },
{ 154, 143 },
{ 155, 257 },
{ 156, 21 },
{ 157, 291 },
{ 158, 122 },
{ 159, 86 },
{ 160, 309 },
{ 161, 79 },
{ 162, 319 },
{ 163, 102 },
{ 164, 301 },
{ 165, 212 },
{ 166, 83 },
{ 167, 276 },
{ 168, 255 },
{ 169, 146 },
{ 170, 163 },
{ 171, 269 },
{ 172, 207 },
{ 173, 206 },
{ 174, 284 },
{ 175, 99 },
{ 176, 281 },
{ 177, 87 },
{ 178, 137 },
{ 179, 243 },
{ 180, 251 },
{ 181, 208 },
{ 182, 237 },
{ 183, 278 },
{ 184, 125 },
{ 185, 213 },
{ 186, 37 },
{ 187, 312 },
{ 188, 28 },
{ 189, 74 },
{ 190, 55 },
{ 191, 192 },
{ 192, 173 },
{ 193, 152 },
{ 194, 91 },
{ 195, 36 },
{ 196, 124 },
{ 197, 188 },
{ 198, 128 },
{ 199, 195 },
{ 200, 170 },
{ 201, 61 },
{ 202, 185 },
{ 203, 264 },
{ 204, 168 },
{ 205, 20 },
{ 206, 288 },
{ 207, 241 },
{ 208, 145 },
{ 209, 240 },
{ 210, 166 },
{ 211, 57 },
{ 212, 50 },
{ 213, 144 },
{ 214, 253 },
{ 215, 41 },
{ 216, 22 },
{ 217, 53 },
{ 218, 54 },
{ 219, 59 },
{ 220, 60 },
{ 221, 65 },
{ 222, 100 },
{ 223, 104 },
{ 224, 106 },
{ 225, 131 },
{ 226, 139 },
{ 227, 140 },
{ 228, 147 },
{ 229, 157 },
{ 230, 164 },
{ 231, 167 },
{ 232, 197 },
{ 233, 198 },
{ 234, 216 },
{ 235, 225 },
{ 236, 313 },
{ 237, 5 },
{ 238, 31 },
{ 239, 325 },
{ 240, 71 },
{ 241, 123 },
{ 242, 80 },
{ 243, 26 },
{ 244, 172 },
{ 245, 193 },
{ 246, 149 },
{ 247, 211 },
{ 248, 242 },
{ 249, 246 },
{ 251, 285 },
{ 252, 308 },
{ 253, 314 },
{ 254, 322 },
{ 255, 23 },
{ 256, 19 },
{ 257, 202 },
{ 258, 126 },
{ 259, 189 },
{ 260, 201 },
{ 261, 15 },
{ 262, 7 },
{ 263, 12 },
{ 264, 13 },
{ 265, 16 },
{ 266, 27 },
{ 267, 29 },
{ 268, 34 },
{ 269, 44 },
{ 272, 52 },
{ 274, 62 },
{ 275, 70 },
{ 279, 95 },
{ 281, 113 },
{ 289, 178 },
{ 290, 179 },
{ 293, 217 },
{ 294, 218 },
{ 295, 219 },
{ 297, 223 },
{ 299, 229 },
{ 304, 248 },
{ 305, 250 },
{ 309, 280 },
{ 311, 302 },
{ 312, 8 },
{ 313, 151 },
{ 314, 271 },
{ 315, 182 },
{ 316, 51 },
{ 317, 162 },
{ 318, 304 },
{ 319, 134 },
{ 320, 190 },
{ 321, 204 },
{ 322, 232 },
{ 323, 136 },
{ 324, 267 },
{ 325, 165 },
{ 326, 111 },
{ 327, 261 },
{ 328, 315 },
{ 330, 187 },
{ 335, 156 },
{ 339, 171 },
{ 341, 10 },
{ 343, 38 },
{ 345, 159 },
{ 346, 186 },
{ 348, 200 },
{ 349, 205 },
{ 350, 224 },
{ 351, 226 },
{ 353, 293 },
{ 354, 294 },
{ 355, 300 },
{ 357, 47 },
{ 358, 221 },
{ 360, 109 },
{ 361, 161 },
{ 362, 256 },
{ 363, 266 },
{ 364, 317 },
{ 365, 49 },
{ 366, 76 },
{ 367, 56 },
{ 368, 194 },
{ 369, 258 },
{ 370, 203 },
};
constexpr IdPair kCountries[] = {
{ 2, 3 },
{ 3, 4 },
{ 4, 5 },
{ 5, 6 },
{ 6, 7 },
{ 7, 8 },
{ 8, 9 },
{ 9, 10 },
{ 10, 11 },
{ 11, 12 },
{ 12, 13 },
{ 13, 15 },
{ 14, 16 },
{ 15, 17 },
{ 16, 18 },
{ 17, 19 },
{ 18, 20 },
{ 19, 21 },
{ 20, 22 },
{ 21, 23 },
{ 22, 24 },
{ 23, 25 },
{ 24, 26 },
{ 25, 27 },
{ 26, 28 },
{ 27, 29 },
{ 28, 30 },
{ 29, 31 },
{ 30, 32 },
{ 31, 33 },
{ 32, 35 },
{ 33, 36 },
{ 34, 37 },
{ 35, 38 },
{ 36, 39 },
{ 37, 40 },
{ 38, 41 },
{ 39, 43 },
{ 40, 45 },
{ 41, 46 },
{ 42, 48 },
{ 43, 49 },
{ 44, 50 },
{ 45, 51 },
{ 46, 53 },
{ 47, 54 },
{ 48, 55 },
{ 49, 57 },
{ 50, 56 },
{ 51, 58 },
{ 52, 59 },
{ 53, 118 },
{ 54, 60 },
{ 55, 61 },
{ 56, 63 },
{ 57, 64 },
{ 58, 65 },
{ 59, 67 },
{ 60, 68 },
{ 61, 69 },
{ 62, 232 },
{ 63, 70 },
{ 64, 71 },
{ 65, 72 },
{ 66, 73 },
{ 67, 74 },
{ 68, 75 },
{ 69, 77 },
{ 70, 80 },
{ 71, 81 },
{ 72, 82 },
{ 73, 83 },
{ 74, 84 },
{ 75, 100 },
{ 76, 85 },
{ 77, 86 },
{ 78, 87 },
{ 79, 88 },
{ 80, 89 },
{ 81, 90 },
{ 82, 91 },
{ 83, 92 },
{ 84, 93 },
{ 85, 94 },
{ 86, 95 },
{ 87, 96 },
{ 88, 97 },
{ 89, 98 },
{ 90, 99 },
{ 91, 102 },
{ 92, 101 },
{ 93, 103 },
{ 94, 104 },
{ 95, 105 },
{ 96, 106 },
{ 97, 107 },
{ 98, 108 },
{ 99, 109 },
{ 100, 110 },
{ 101, 111 },
{ 102, 112 },
{ 103, 113 },
{ 104, 114 },
{ 105, 116 },
{ 106, 117 },
{ 107, 119 },
{ 108, 120 },
{ 109, 122 },
{ 110, 123 },
{ 111, 124 },
{ 112, 125 },
{ 113, 174 },
{ 114, 218 },
{ 115, 127 },
{ 116, 128 },
{ 117, 129 },
{ 118, 131 },
{ 119, 132 },
{ 120, 133 },
{ 121, 134 },
{ 122, 135 },
{ 123, 136 },
{ 124, 137 },
{ 125, 138 },
{ 126, 139 },
{ 127, 140 },
{ 128, 141 },
{ 129, 142 },
{ 130, 143 },
{ 131, 144 },
{ 132, 145 },
{ 133, 146 },
{ 134, 147 },
{ 135, 148 },
{ 136, 149 },
{ 137, 150 },
{ 138, 151 },
{ 139, 152 },
{ 140, 153 },
{ 141, 154 },
{ 142, 155 },
{ 143, 156 },
{ 144, 158 },
{ 145, 159 },
{ 146, 160 },
{ 147, 161 },
{ 148, 162 },
{ 149, 163 },
{ 150, 164 },
{ 151, 165 },
{ 152, 62 },
{ 153, 166 },
{ 154, 167 },
{ 155, 168 },
{ 156, 170 },
{ 157, 169 },
{ 158, 171 },
{ 159, 172 },
{ 160, 173 },
{ 161, 175 },
{ 162, 176 },
{ 163, 178 },
{ 164, 179 },
{ 165, 180 },
{ 166, 181 },
{ 167, 182 },
{ 168, 183 },
{ 169, 184 },
{ 170, 185 },
{ 171, 186 },
{ 172, 187 },
{ 173, 188 },
{ 174, 189 },
{ 175, 190 },
{ 176, 191 },
{ 177, 192 },
{ 178, 193 },
{ 179, 194 },
{ 180, 197 },
{ 181, 198 },
{ 182, 201 },
{ 183, 202 },
{ 184, 203 },
{ 185, 204 },
{ 186, 205 },
{ 187, 206 },
{ 188, 208 },
{ 189, 209 },
{ 190, 210 },
{ 191, 212 },
{ 192, 213 },
{ 193, 214 },
{ 194, 215 },
{ 195, 216 },
{ 196, 217 },
{ 197, 220 },
{ 198, 221 },
{ 199, 196 },
{ 201, 222 },
{ 202, 223 },
{ 203, 224 },
{ 204, 76 },
{ 205, 225 },
{ 206, 226 },
{ 207, 227 },
{ 208, 228 },
{ 209, 229 },
{ 210, 230 },
{ 211, 231 },
{ 212, 233 },
{ 213, 234 },
{ 214, 235 },
{ 215, 236 },
{ 216, 238 },
{ 217, 239 },
{ 218, 240 },
{ 219, 241 },
{ 220, 242 },
{ 221, 243 },
{ 222, 244 },
{ 223, 245 },
{ 224, 246 },
{ 225, 248 },
{ 226, 247 },
{ 227, 250 },
{ 228, 251 },
{ 229, 252 },
{ 230, 253 },
{ 231, 254 },
{ 232, 255 },
{ 233, 34 },
{ 234, 249 },
{ 235, 256 },
{ 236, 257 },
{ 237, 259 },
{ 238, 42 },
{ 239, 260 },
{ 240, 261 },
{ 241, 52 },
{ 242, 157 },
{ 243, 207 },
{ 244, 195 },
{ 245, 199 },
{ 246, 130 },
{ 247, 14 },
{ 248, 2 },
{ 249, 66 },
{ 250, 47 },
{ 251, 115 },
{ 252, 121 },
{ 253, 237 },
{ 254, 219 },
{ 255, 44 },
{ 256, 211 },
{ 257, 126 },
{ 258, 79 },
{ 259, 177 },
{ 260, 258 },
{ 261, 78 },
};
constexpr int kRemovedQt5Languages[] = {
17,
250,
270,
271,
273,
276,
277,
278,
280,
282,
283,
284,
285,
286,
287,
288,
291,
292,
296,
298,
300,
301,
302,
303,
306,
307,
308,
310,
329,
331,
332,
333,
334,
336,
337,
338,
340,
342,
344,
347,
352,
356,
359,
};
[[nodiscard]] int Convert(
const auto &table,
int value,
int fromScheme,
int toScheme) {
const auto from = (fromScheme == 5) ? &IdPair::qt5 : &IdPair::qt6;
const auto to = (toScheme == 5) ? &IdPair::qt5 : &IdPair::qt6;
for (const auto &pair : table) {
if ((pair.*from) == value) {
return (pair.*to);
}
}
return 0;
}
[[nodiscard]] bool IsRemovedQt5Language(int language) {
for (const auto removed : kRemovedQt5Languages) {
if (removed == language) {
return true;
}
}
return false;
}
[[nodiscard]] bool KnownScheme(int scheme) {
return (scheme == 5) || (scheme == 6);
}
} // namespace
int LocalIdScheme() {
return QT_VERSION_MAJOR;
}
int ConvertLangId(int langId, int fromScheme, int toScheme) {
if (fromScheme == toScheme) {
return langId;
} else if (langId <= 0
|| !KnownScheme(fromScheme)
|| !KnownScheme(toScheme)) {
return 0;
}
const auto language = (langId < kFactor) ? langId : (langId / kFactor);
if (fromScheme == 5 && IsRemovedQt5Language(language)) {
return 0;
}
const auto country = (langId < kFactor) ? 0 : (langId % kFactor);
auto converted = Convert(kLanguages, language, fromScheme, toScheme);
if (!converted) {
converted = language;
}
if (!country) {
return converted;
}
auto region = Convert(kCountries, country, fromScheme, toScheme);
if (!region) {
region = country;
}
return (converted * kFactor) + region;
}
int RecoverLangIdFromSerialized(quint64 raw, int scheme) {
if (!raw || raw > quint64(std::numeric_limits<int>::max())) {
return 0;
}
const auto value = int(raw);
const auto converted = ConvertLangId(
value,
scheme,
LocalIdScheme());
const auto language = (value < kFactor) ? value : (value / kFactor);
if (!converted
&& scheme == 5
&& IsRemovedQt5Language(language)) {
return 0;
}
const auto candidate = converted ? converted : value;
if (candidate <= 1 || candidate > int(QLocale::LastLanguage)) {
return 0;
}
return candidate;
}
} // namespace Spellchecker