feat: sort languages in selection menu (#1071)

## Summary

* **What is the goal of this PR?** (e.g., Implements the new feature for
file uploading.)

Currently we are displaying the languages in the order they were added
(as in the `Language` enum). However, as new languages are coming in,
this will quickly be confusing to the users.

But we can't just change the ordering of the enum if we want to respect
bakwards compatibility.

So my proposal is to add a mapping of the alphabetical order of the
languages. I've made it so that it's generated by the `gen_i18n.py`
script, which will be used when a new language is added.


* **What changes are included?**

Added the array from the python script and changed
`LanguageSelectActivity` to use the indices from there. Also commited
the generated `I18nKeys.h`

## Additional Context

* Add any other information that might be helpful for the reviewer
(e.g., performance implications, potential risks,
  specific areas to focus on).

I was wondering if there is a better way to sort it. Currently, it's by
unicode value and Czech and Russian are last, which I don't know it it's
the most intuitive.

The current order is:
`Català, Deutsch, English, Español, Français, Português (Brasil),
Română, Svenska, Čeština, Русский`

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**< PARTIALLY >**_
This commit is contained in:
ariel-lindemann
2026-02-25 17:44:17 +01:00
committed by GitHub
parent b695a48af6
commit 7e214ea760
19 changed files with 68 additions and 34 deletions

View File

@@ -3,16 +3,22 @@
#include <GfxRenderer.h>
#include <I18n.h>
#include <algorithm>
#include <iterator>
#include "I18nKeys.h"
#include "MappedInputManager.h"
#include "fontIds.h"
void LanguageSelectActivity::onEnter() {
Activity::onEnter();
totalItems = getLanguageCount();
// Set current selection based on current language
selectedIndex = static_cast<int>(I18N.getLanguage());
const auto currentLang = static_cast<uint8_t>(I18N.getLanguage());
const auto* begin = std::begin(SORTED_LANGUAGE_INDICES);
const auto* end = std::end(SORTED_LANGUAGE_INDICES);
const auto* it = std::find(begin, end, currentLang);
selectedIndex = (it != end) ? std::distance(begin, it) : 0;
requestUpdate();
}
@@ -45,7 +51,7 @@ void LanguageSelectActivity::loop() {
void LanguageSelectActivity::handleSelection() {
{
RenderLock lock(*this);
I18N.setLanguage(static_cast<Language>(selectedIndex));
I18N.setLanguage(static_cast<Language>(SORTED_LANGUAGE_INDICES[selectedIndex]));
}
// Return to previous page
@@ -61,13 +67,16 @@ void LanguageSelectActivity::render(Activity::RenderLock&&) {
GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_LANGUAGE));
// Current language marker
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing;
const int currentLang = static_cast<int>(I18N.getLanguage());
const auto currentLang = static_cast<uint8_t>(I18N.getLanguage());
GUI.drawList(
renderer, Rect{0, contentTop, pageWidth, contentHeight}, totalItems, selectedIndex,
[this](int index) { return I18N.getLanguageName(static_cast<Language>(index)); }, nullptr, nullptr,
[this, currentLang](int index) { return index == currentLang ? tr(STR_SET) : ""; }, true);
[this](int index) { return I18N.getLanguageName(static_cast<Language>(SORTED_LANGUAGE_INDICES[index])); },
nullptr, nullptr,
[this, currentLang](int index) { return SORTED_LANGUAGE_INDICES[index] == currentLang ? tr(STR_SET) : ""; },
true);
// Button hints
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), tr(STR_DIR_UP), tr(STR_DIR_DOWN));

View File

@@ -31,5 +31,5 @@ class LanguageSelectActivity final : public Activity {
std::function<void()> onBack;
ButtonNavigator buttonNavigator;
int selectedIndex = 0;
int totalItems = 0;
constexpr static uint8_t totalItems = getLanguageCount();
};