## 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 >**_
43 lines
929 B
C++
43 lines
929 B
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#include "I18nKeys.h"
|
|
/**
|
|
* Internationalization (i18n) system for CrossPoint Reader
|
|
*/
|
|
|
|
class I18n {
|
|
public:
|
|
static I18n& getInstance();
|
|
|
|
// Disable copy
|
|
I18n(const I18n&) = delete;
|
|
I18n& operator=(const I18n&) = delete;
|
|
|
|
// Get localized string by ID
|
|
const char* get(StrId id) const;
|
|
|
|
const char* operator[](StrId id) const { return get(id); }
|
|
|
|
Language getLanguage() const { return _language; }
|
|
void setLanguage(Language lang);
|
|
const char* getLanguageName(Language lang) const;
|
|
|
|
void saveSettings();
|
|
void loadSettings();
|
|
|
|
// Get all unique characters used in a specific language
|
|
// Returns a sorted string of unique characters
|
|
static const char* getCharacterSet(Language lang);
|
|
|
|
private:
|
|
I18n() : _language(Language::EN) {}
|
|
|
|
Language _language;
|
|
};
|
|
|
|
// Convenience macros
|
|
#define tr(id) I18n::getInstance().get(StrId::id)
|
|
#define I18N I18n::getInstance()
|