mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
[core] Respect system language order
Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
committed by
Yannik Bloscheck
parent
b37572000f
commit
dd949925f6
@@ -6,6 +6,7 @@
|
|||||||
#include "indexer/ftypes_matcher.hpp"
|
#include "indexer/ftypes_matcher.hpp"
|
||||||
#include "indexer/scales.hpp"
|
#include "indexer/scales.hpp"
|
||||||
|
|
||||||
|
#include "platform/preferred_languages.hpp"
|
||||||
#include "platform/localization.hpp"
|
#include "platform/localization.hpp"
|
||||||
#include "platform/distance.hpp"
|
#include "platform/distance.hpp"
|
||||||
|
|
||||||
@@ -124,6 +125,14 @@ bool IsNativeLang(feature::RegionData const & regionData, int8_t deviceLang)
|
|||||||
vector<int8_t> MakeLanguagesPriorityList(int8_t deviceLang, bool preferDefault)
|
vector<int8_t> MakeLanguagesPriorityList(int8_t deviceLang, bool preferDefault)
|
||||||
{
|
{
|
||||||
vector<int8_t> langPriority = {deviceLang};
|
vector<int8_t> langPriority = {deviceLang};
|
||||||
|
for (auto const & lang : languages::GetPreferredLangIndexes())
|
||||||
|
{
|
||||||
|
if (find(langPriority.begin(), langPriority.end(), lang) == langPriority.end())
|
||||||
|
{
|
||||||
|
langPriority.push_back(lang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (preferDefault)
|
if (preferDefault)
|
||||||
langPriority.push_back(StrUtf8::kDefaultCode);
|
langPriority.push_back(StrUtf8::kDefaultCode);
|
||||||
|
|
||||||
|
|||||||
@@ -188,6 +188,22 @@ std::string GetCurrentMapLanguage()
|
|||||||
return languageCode;
|
return languageCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<int8_t> GetPreferredLangIndexes()
|
||||||
|
{
|
||||||
|
std::vector<int8_t> langs = {};
|
||||||
|
for (auto const & systemLanguage : GetSystemPreferred())
|
||||||
|
{
|
||||||
|
auto normalizedLang = Normalize(systemLanguage);
|
||||||
|
int8_t lang = StringUtf8Multilang::GetLangIndex(normalizedLang);
|
||||||
|
if (lang != StringUtf8Multilang::kUnsupportedLanguageCode
|
||||||
|
&& find(langs.begin(), langs.end(), lang) == langs.end())
|
||||||
|
{
|
||||||
|
langs.push_back(lang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return langs;
|
||||||
|
}
|
||||||
|
|
||||||
std::string GetTwine(std::string const & lang)
|
std::string GetTwine(std::string const & lang)
|
||||||
{
|
{
|
||||||
// Special cases for different Chinese variations.
|
// Special cases for different Chinese variations.
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ std::string GetCurrentMapTwine();
|
|||||||
std::string Normalize(std::string_view lang);
|
std::string Normalize(std::string_view lang);
|
||||||
std::string GetCurrentNorm();
|
std::string GetCurrentNorm();
|
||||||
std::string GetCurrentMapLanguage();
|
std::string GetCurrentMapLanguage();
|
||||||
|
std::vector<int8_t> GetPreferredLangIndexes();
|
||||||
|
|
||||||
buffer_vector<std::string, 4> const & GetSystemPreferred();
|
buffer_vector<std::string, 4> const & GetSystemPreferred();
|
||||||
} // namespace languages
|
} // namespace languages
|
||||||
|
|||||||
Reference in New Issue
Block a user