Skip to content

Commit 13c3691

Browse files
committed
Always prefer the first langauge in layout instead of find an alpha 2 code.
It has been confusing that tibetan is shown as Chinese since we prefer alpha 2 code in a latter field. Usually, the first is the most accurate language code. Since we will make configtool to always use iso639 language, it shouldn't be a problem that alpha3 is used when there's no alpha 2. fcitx/fcitx5-configtool#92
1 parent 5b12bf2 commit 13c3691

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/im/keyboard/keyboard.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "keyboard.h"
99
#include <strings.h>
10+
#include <algorithm>
1011
#include <cstddef>
1112
#include <filesystem>
1213
#include <functional>
@@ -20,6 +21,7 @@
2021
#include <utility>
2122
#include <vector>
2223
#include <format>
24+
#include <span>
2325
#include <xkbcommon/xkbcommon.h>
2426
#include "fcitx-config/iniparser.h"
2527
#include "fcitx-config/rawconfig.h"
@@ -79,7 +81,8 @@ std::string findBestLanguage(const IsoCodes &isocodes, const std::string &hint,
7981
*/
8082
const IsoCodes639Entry *bestEntry = nullptr;
8183
int bestScore = 0;
82-
for (const auto &language : languages) {
84+
for (const auto &language : std::span(languages).subspan(
85+
0, std::min(static_cast<size_t>(1), languages.size()))) {
8386
const auto *entry = isocodes.entry(language);
8487
if (!entry) {
8588
continue;
@@ -127,7 +130,7 @@ std::string findBestLanguage(const IsoCodes &isocodes, const std::string &hint,
127130
}
128131
return bestEntry->iso_639_2B_code;
129132
}
130-
return {};
133+
return languages.empty() ? "" : languages[0];
131134
}
132135

133136
class KeyboardCandidateWord : public CandidateWord {

0 commit comments

Comments
 (0)