8 #include "i18nstring.h" 17 const std::string &I18NString::match(
const std::string &locale_)
const {
18 std::string locale = locale_;
19 if (locale ==
"system") {
20 std::optional<std::string> lc;
21 if constexpr (isAndroid() || isApple() || isWindows()) {
30 lc = getEnvironment(
"FCITX_LOCALE");
33 auto *lcMessages = setlocale(LC_ALL,
nullptr);
35 auto *lcMessages = setlocale(LC_MESSAGES,
nullptr);
42 locale = std::move(*lc);
56 std::string normalizedLocale;
57 size_t languageLength = 0;
58 size_t territoryLength = 0;
60 auto i = locale.begin();
61 auto e = locale.end();
63 while (i != e && !charutils::isspace(*i) && *i !=
'_' && *i !=
'.' &&
65 normalizedLocale.push_back(*i++);
68 if (i == locale.begin()) {
72 languageLength = normalizedLocale.size();
74 if (i != e && *i ==
'_') {
75 normalizedLocale.push_back(
'_');
77 while (i != e && charutils::isupper(*i)) {
78 normalizedLocale.push_back(*i);
82 territoryLength = normalizedLocale.size();
85 if (i != e && *i ==
'.') {
89 (charutils::isupper(*i) || charutils::islower(*i) ||
90 charutils::isdigit(*i) || *i ==
'_' || *i ==
'-')) {
95 if (i != e && *i ==
'@') {
96 normalizedLocale.push_back(
'@');
99 normalizedLocale.push_back(*i);
106 normalizedLocale.clear();
107 territoryLength = languageLength = 0;
110 if (normalizedLocale.empty()) {
113 auto iter = map_.find(normalizedLocale);
114 if (territoryLength && iter == map_.end()) {
115 iter = map_.find(normalizedLocale.substr(0, territoryLength));
117 if (languageLength && iter == map_.end()) {
118 iter = map_.find(normalizedLocale.substr(0, languageLength));
120 if (iter != map_.end()) {
Local independent API to detect character type.