mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-25 04:38:23 +00:00
Slightly refactored spellchecker_common.cpp.
- Moved LocaleFromLangId to lib_spellcheck.
This commit is contained in:
parent
9d98682089
commit
f377ac54fd
@ -63,16 +63,6 @@ private:
|
|||||||
base::unique_qptr<Loader> GlobalLoader;
|
base::unique_qptr<Loader> GlobalLoader;
|
||||||
rpl::event_stream<Loader*> GlobalLoaderValues;
|
rpl::event_stream<Loader*> GlobalLoaderValues;
|
||||||
|
|
||||||
QLocale LocaleFromLangId(int langId) {
|
|
||||||
if (langId > 1000) {
|
|
||||||
const auto l = langId / 1000;
|
|
||||||
const auto lang = static_cast<QLocale::Language>(l);
|
|
||||||
const auto country = static_cast<QLocale::Country>(langId - l * 1000);
|
|
||||||
return QLocale(lang, country);
|
|
||||||
}
|
|
||||||
return QLocale(static_cast<QLocale::Language>(langId));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetGlobalLoader(base::unique_qptr<Loader> loader) {
|
void SetGlobalLoader(base::unique_qptr<Loader> loader) {
|
||||||
GlobalLoader = std::move(loader);
|
GlobalLoader = std::move(loader);
|
||||||
GlobalLoaderValues.fire(GlobalLoader.get());
|
GlobalLoaderValues.fire(GlobalLoader.get());
|
||||||
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
|
|
||||||
#ifndef TDESKTOP_DISABLE_SPELLCHECK
|
#ifndef TDESKTOP_DISABLE_SPELLCHECK
|
||||||
|
|
||||||
|
#include "spellcheck/spellcheck_utils.h"
|
||||||
#include "base/zlib_help.h"
|
#include "base/zlib_help.h"
|
||||||
|
|
||||||
namespace Spellchecker {
|
namespace Spellchecker {
|
||||||
@ -17,6 +18,8 @@ namespace {
|
|||||||
|
|
||||||
using namespace Storage::CloudBlob;
|
using namespace Storage::CloudBlob;
|
||||||
|
|
||||||
|
constexpr auto kDictExtensions = { "dic", "aff" };
|
||||||
|
|
||||||
// Language With Country.
|
// Language With Country.
|
||||||
inline auto LWC(QLocale::Country country) {
|
inline auto LWC(QLocale::Country country) {
|
||||||
const auto l = QLocale::matchingLocales(
|
const auto l = QLocale::matchingLocales(
|
||||||
@ -70,16 +73,6 @@ const auto kDictionaries = {
|
|||||||
Dict{{ QLocale::Vietnamese, 52, 12'949, "\x54\x69\xe1\xba\xbf\x6e\x67\x20\x56\x69\xe1\xbb\x87\x74" }},
|
Dict{{ QLocale::Vietnamese, 52, 12'949, "\x54\x69\xe1\xba\xbf\x6e\x67\x20\x56\x69\xe1\xbb\x87\x74" }},
|
||||||
};
|
};
|
||||||
|
|
||||||
QLocale LocaleFromLangId(int langId) {
|
|
||||||
if (langId > 1000) {
|
|
||||||
const auto l = langId / 1000;
|
|
||||||
const auto lang = static_cast<QLocale::Language>(l);
|
|
||||||
const auto country = static_cast<QLocale::Country>(langId - l * 1000);
|
|
||||||
return QLocale(lang, country);
|
|
||||||
}
|
|
||||||
return QLocale(static_cast<QLocale::Language>(langId));
|
|
||||||
}
|
|
||||||
|
|
||||||
void EnsurePath() {
|
void EnsurePath() {
|
||||||
if (!QDir::current().mkpath(Spellchecker::DictionariesPath())) {
|
if (!QDir::current().mkpath(Spellchecker::DictionariesPath())) {
|
||||||
LOG(("App Error: Could not create dictionaries path."));
|
LOG(("App Error: Could not create dictionaries path."));
|
||||||
@ -93,15 +86,16 @@ std::initializer_list<const Dict> Dictionaries() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IsGoodPartName(const QString &name) {
|
bool IsGoodPartName(const QString &name) {
|
||||||
return name.endsWith(qsl(".dic"))
|
return ranges::find_if(kDictExtensions, [&](const auto &ext) {
|
||||||
|| name.endsWith(qsl(".aff"));
|
return name.endsWith(ext);
|
||||||
|
}) != end(kDictExtensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DictPathByLangId(int langId) {
|
QString DictPathByLangId(int langId) {
|
||||||
EnsurePath();
|
EnsurePath();
|
||||||
return qsl("%1/%2")
|
return qsl("%1/%2")
|
||||||
.arg(DictionariesPath())
|
.arg(DictionariesPath())
|
||||||
.arg(LocaleFromLangId(langId).name());
|
.arg(Spellchecker::LocaleFromLangId(langId).name());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DictionariesPath() {
|
QString DictionariesPath() {
|
||||||
@ -118,12 +112,11 @@ bool DictionaryExists(int langId) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const auto folder = DictPathByLangId(langId) + '/';
|
const auto folder = DictPathByLangId(langId) + '/';
|
||||||
const auto exts = { "dic", "aff" };
|
const auto bad = ranges::find_if(kDictExtensions, [&](const auto &ext) {
|
||||||
const auto bad = ranges::find_if(exts, [&](const QString &ext) {
|
const auto name = Spellchecker::LocaleFromLangId(langId).name();
|
||||||
const auto name = LocaleFromLangId(langId).name();
|
|
||||||
return !QFile(folder + name + '.' + ext).exists();
|
return !QFile(folder + name + '.' + ext).exists();
|
||||||
});
|
});
|
||||||
return (bad == exts.end());
|
return (bad == end(kDictExtensions));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteDefaultDictionary() {
|
bool WriteDefaultDictionary() {
|
||||||
|
Loading…
Reference in New Issue
Block a user