mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/i18n] Added default country for languages
After choosing a language at onboarding, the country menu now has a specific country selected by default (Spain for Spanish, Italy for Italian...) Default countries are specified in apps/language_preferences.csv Change-Id: Ia6392aceb9bebf7e62a692c5a79eb8c4d7b71a9d
This commit is contained in:
committed by
Émilie Feral
parent
ec6ee82b81
commit
df6383d2d8
@@ -56,6 +56,7 @@ $(call object_for,apps/apps_container_storage.cpp apps/apps_container.cpp apps/m
|
||||
# I18n file generation
|
||||
|
||||
country_preferences = apps/country_preferences.csv
|
||||
language_preferences = apps/language_preferences.csv
|
||||
|
||||
# The header is refered to as <apps/i18n.h> so make sure it's findable this way
|
||||
SFLAGS += -I$(BUILD_DIR)
|
||||
@@ -73,7 +74,7 @@ $(eval $(call rule_for, \
|
||||
I18N, \
|
||||
apps/i18n.cpp, \
|
||||
$(i18n_files), \
|
||||
$$(PYTHON) apps/i18n.py --codepoints $(code_points) --countrypreferences $(country_preferences) --header $$(subst .cpp,.h,$$@) --implementation $$@ --locales $$(EPSILON_I18N) --countries $$(EPSILON_COUNTRIES) --files $$^ --generateISO6391locales $$(EPSILON_GETOPT), \
|
||||
$$(PYTHON) apps/i18n.py --codepoints $(code_points) --countrypreferences $(country_preferences) --languagepreferences $(language_preferences) --header $$(subst .cpp,.h,$$@) --implementation $$@ --locales $$(EPSILON_I18N) --countries $$(EPSILON_COUNTRIES) --files $$^ --generateISO6391locales $$(EPSILON_GETOPT), \
|
||||
global \
|
||||
))
|
||||
|
||||
|
||||
38
apps/i18n.py
38
apps/i18n.py
@@ -21,6 +21,7 @@ parser.add_argument('--locales', nargs='+', help='locale to actually generate')
|
||||
parser.add_argument('--countries', nargs='+', help='countries to actually generate')
|
||||
parser.add_argument('--codepoints', help='the code_points.h file')
|
||||
parser.add_argument('--countrypreferences', help='the country_preferences.csv file')
|
||||
parser.add_argument('--languagepreferences', help='the language_preferences.csv file')
|
||||
parser.add_argument('--files', nargs='+', help='an i18n file')
|
||||
parser.add_argument('--generateISO6391locales', type=int, nargs='+', help='whether to generate the ISO6391 codes for the languages (for instance "en" for english)')
|
||||
|
||||
@@ -117,17 +118,32 @@ def parse_codepoints(file):
|
||||
|
||||
codepoints = parse_codepoints(args.codepoints)
|
||||
|
||||
def parse_csv_with_header(file):
|
||||
res = []
|
||||
with io.open(file, 'r', encoding='utf-8') as csvfile:
|
||||
csvreader = csv.reader(csvfile, delimiter=',')
|
||||
for row in csvreader:
|
||||
res.append(row)
|
||||
return (res[0], res[1:])
|
||||
|
||||
def parse_country_preferences(file):
|
||||
countryPreferences = {}
|
||||
with io.open(file, "r", encoding="utf-8") as csvfile:
|
||||
csvreader = csv.reader(csvfile, delimiter=',')
|
||||
headers = next(csvreader, None)
|
||||
for row in csvreader:
|
||||
countryPreferences[row[0]] = [headers[i] + "::" + row[i] for i in range(1, len(row))]
|
||||
header, records = parse_csv_with_header(file)
|
||||
for record in records:
|
||||
countryPreferences[record[0]] = [header[i] + "::" + record[i] for i in range(1, len(record))]
|
||||
return countryPreferences
|
||||
|
||||
countryPreferences = parse_country_preferences(args.countrypreferences)
|
||||
|
||||
def parse_language_preferences(file):
|
||||
languagePreferences = {}
|
||||
header, records = parse_csv_with_header(file)
|
||||
for record in records:
|
||||
languagePreferences[record[0]] = (header[1], record[1])
|
||||
return languagePreferences
|
||||
|
||||
languagePreferences = parse_language_preferences(args.languagepreferences)
|
||||
|
||||
def print_block_from_list(target, header, data, beautify=lambda arg: arg, prefix=" ", footer="};\n\n"):
|
||||
target.write(header)
|
||||
for i in range(len(data)):
|
||||
@@ -179,6 +195,7 @@ def print_header(data, path, locales, countries):
|
||||
"enum class Country : uint8_t {\n",
|
||||
countries,
|
||||
lambda arg: arg.upper())
|
||||
defaultCountry = countries[-1]
|
||||
|
||||
# Country names
|
||||
print_block_from_list(f,
|
||||
@@ -187,10 +204,19 @@ def print_header(data, path, locales, countries):
|
||||
lambda arg: arg.upper(),
|
||||
" Message::Country")
|
||||
|
||||
# Language preferences
|
||||
f.write("constexpr static Country DefaultCountryForLanguage[NumberOfLanguages] = {\n")
|
||||
for language in locales:
|
||||
key = language if (language in languagePreferences) else '??'
|
||||
header, country = languagePreferences[key]
|
||||
line = " " + header + "::" + (country if country in countries else defaultCountry)
|
||||
f.write(line + ",\n")
|
||||
f.write("};\n\n")
|
||||
|
||||
# Country preferences
|
||||
f.write("constexpr static CountryPreferences CountryPreferencesArray[] = {\n")
|
||||
for country in countries:
|
||||
key = country if (country in countryPreferences) else 'inl'
|
||||
key = country if (country in countryPreferences) else defaultCountry
|
||||
line = " CountryPreferences("
|
||||
for param in countryPreferences[key]:
|
||||
line += param + ", "
|
||||
|
||||
9
apps/language_preferences.csv
Normal file
9
apps/language_preferences.csv
Normal file
@@ -0,0 +1,9 @@
|
||||
Language,I18n::Country
|
||||
en,US
|
||||
fr,FR
|
||||
nl,NL
|
||||
pt,PT
|
||||
it,IT
|
||||
de,DE
|
||||
es,ES
|
||||
??,WW
|
||||
|
@@ -1,9 +1,16 @@
|
||||
#include "localization_controller.h"
|
||||
#include <algorithm>
|
||||
#include <apps/apps_container.h>
|
||||
#include <apps/global_preferences.h>
|
||||
|
||||
namespace OnBoarding {
|
||||
|
||||
int LocalizationController::indexOfCellToSelectOnReset() const {
|
||||
return mode() == Mode::Language ?
|
||||
0 :
|
||||
IndexOfCountry(I18n::DefaultCountryForLanguage[static_cast<uint8_t>(GlobalPreferences::sharedGlobalPreferences()->language())]);
|
||||
}
|
||||
|
||||
bool LocalizationController::handleEvent(Ion::Events::Event event) {
|
||||
if (Shared::LocalizationController::handleEvent(event)) {
|
||||
if (mode() == Mode::Language) {
|
||||
|
||||
@@ -10,8 +10,8 @@ class LocalizationController : public Shared::LocalizationController {
|
||||
public:
|
||||
using Shared::LocalizationController::LocalizationController;
|
||||
|
||||
bool shouldDisplayTitle() override { return mode() == Mode::Country; }
|
||||
bool shouldResetSelectionToTopCell() override { return true; }
|
||||
int indexOfCellToSelectOnReset() const override;
|
||||
bool shouldDisplayTitle() const override { return mode() == Mode::Country; }
|
||||
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
#include "localization_controller.h"
|
||||
#include <apps/global_preferences.h>
|
||||
|
||||
|
||||
namespace Settings {
|
||||
|
||||
int LocalizationController::indexOfCellToSelectOnReset() const {
|
||||
return mode() == Mode::Language ?
|
||||
static_cast<int>(GlobalPreferences::sharedGlobalPreferences()->language()) :
|
||||
IndexOfCountry(GlobalPreferences::sharedGlobalPreferences()->country());
|
||||
}
|
||||
|
||||
bool LocalizationController::handleEvent(Ion::Events::Event event) {
|
||||
if (Shared::LocalizationController::handleEvent(event) || event == Ion::Events::Left) {
|
||||
static_cast<StackViewController *>(parentResponder())->pop();
|
||||
|
||||
@@ -10,8 +10,8 @@ class LocalizationController : public Shared::LocalizationController {
|
||||
public:
|
||||
using Shared::LocalizationController::LocalizationController;
|
||||
|
||||
bool shouldDisplayTitle() override { return false; }
|
||||
bool shouldResetSelectionToTopCell() override { return false; }
|
||||
int indexOfCellToSelectOnReset() const override;
|
||||
bool shouldDisplayTitle() const override { return false; }
|
||||
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
TELEMETRY_ID("Localization");
|
||||
|
||||
@@ -127,7 +127,7 @@ LocalizationController::LocalizationController(Responder * parentResponder, KDCo
|
||||
|
||||
void LocalizationController::resetSelection() {
|
||||
selectableTableView()->deselectTable();
|
||||
selectCellAtLocation(0, (shouldResetSelectionToTopCell()) ? 0 : (mode() == Mode::Language) ? static_cast<int>(GlobalPreferences::sharedGlobalPreferences()->language()) : IndexOfCountry(GlobalPreferences::sharedGlobalPreferences()->country()));
|
||||
selectCellAtLocation(0, indexOfCellToSelectOnReset());
|
||||
}
|
||||
|
||||
void LocalizationController::setMode(LocalizationController::Mode mode) {
|
||||
|
||||
@@ -22,9 +22,9 @@ public:
|
||||
Mode mode() const { return m_mode; }
|
||||
void setMode(Mode mode);
|
||||
|
||||
virtual bool shouldDisplayTitle() = 0;
|
||||
virtual bool shouldResetSelectionToTopCell() = 0;
|
||||
bool shouldDisplayWarning() { return mode() == Mode::Country; }
|
||||
virtual int indexOfCellToSelectOnReset() const = 0;
|
||||
virtual bool shouldDisplayTitle() const = 0;
|
||||
bool shouldDisplayWarning() const { return mode() == Mode::Country; }
|
||||
|
||||
View * view() override { return &m_contentView; }
|
||||
const char * title() override;
|
||||
|
||||
Reference in New Issue
Block a user