Skip to content

Commit

Permalink
Merge pull request #108 from NobodyForNothing/FEAT-in-app-language-se…
Browse files Browse the repository at this point in the history
…lection

Added in-app language selection
  • Loading branch information
derdilla authored Jul 20, 2023
2 parents 2b02c7d + e993f68 commit 8f7e800
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/components/measurement_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:intl/intl.dart';
import 'package:provider/provider.dart';

class MeasurementList extends StatelessWidget {
late final _tableElementsSizes;
late final _sideFlex;
late final List<int> _tableElementsSizes;
late final int _sideFlex;

MeasurementList(BuildContext context, {super.key}) {
if (MediaQuery.of(context).size.width < 1000) {
Expand All @@ -37,7 +37,7 @@ class MeasurementList extends StatelessWidget {
),
Expanded(
flex: _tableElementsSizes[0],
child: Text(AppLocalizations.of(context)!.time, style: TextStyle(fontWeight: FontWeight.bold))),
child: Text(AppLocalizations.of(context)!.time, style: const TextStyle(fontWeight: FontWeight.bold))),
Expanded(
flex: _tableElementsSizes[1],
child: Text(AppLocalizations.of(context)!.sysShort, style: TextStyle(fontWeight: FontWeight.bold, color: settings.sysColor))),
Expand All @@ -49,7 +49,7 @@ class MeasurementList extends StatelessWidget {
child: Text(AppLocalizations.of(context)!.pulShort, style: TextStyle(fontWeight: FontWeight.bold, color: settings.pulColor))),
Expanded(
flex: _tableElementsSizes[4],
child: Text(AppLocalizations.of(context)!.notes, style: TextStyle(fontWeight: FontWeight.bold))),
child: Text(AppLocalizations.of(context)!.notes, style: const TextStyle(fontWeight: FontWeight.bold))),
Expanded(
flex: _sideFlex,
child: const SizedBox(),
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,6 @@
"@last30Days": {},
"allowMissingValues": "Allow missing values",
"@allowMissingValues": {},
"errTimeAfterNow": "The selected time of day is after this moment. We have automatically reset it to the current time. You can disable this validation in the settings!"
"errTimeAfterNow": "The selected time of day is after this moment. We have automatically reset it to the current time. You can disable this validation in the settings!",
"language": "Language"
}
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class AppRoot extends StatelessWidget {
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
locale: settings.language,
home: const AppHome(),
);
});
Expand Down
190 changes: 190 additions & 0 deletions lib/model/iso_lang_names.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import 'package:flutter/material.dart';

final _isoLangs = {
"ab": "аҧсуа",
"aa": "Afaraf",
"af": "Afrikaans",
"ak": "Akan",
"sq": "Shqip",
"am": "አማርኛ",
"ar": "العربية",
"an": "Aragonés",
"hy": "Հայերեն",
"as": "অসমীয়া",
"av": "авар мацӀ, магӀарул мацӀ",
"ae": "avesta",
"ay": "aymar aru",
"az": "azərbaycan dili",
"bm": "bamanankan",
"ba": "башҡорт теле",
"eu": "euskara, euskera",
"be": "Беларуская",
"bn": "বাংলা",
"bh": "भोजपुरी",
"bi": "Bislama",
"bs": "bosanski jezik",
"br": "brezhoneg",
"bg": "български език",
"my": "ဗမာစာ",
"ca": "Català",
"ch": "Chamoru",
"ce": "нохчийн мотт",
"ny": "chiCheŵa, chinyanja",
"zh": "中文 (Zhōngwén)",
"cv": "чӑваш чӗлхи",
"kw": "Kernewek",
"co": "corsu, lingua corsa",
"cr": "ᓀᐦᐃᔭᐍᐏᐣ",
"hr": "hrvatski",
"cs": "česky, čeština",
"da": "dansk",
"dv": "ދިވެހި",
"nl": "Nederlands, Vlaams",
"en": "English",
"eo": "Esperanto",
"et": "eesti, eesti keel",
"ee": "Eʋegbe",
"fo": "føroyskt",
"fj": "vosa Vakaviti",
"fi": "suomi, suomen kieli",
"fr": "française",
"ff": "Fulfulde, Pulaar, Pular",
"gl": "Galego",
"ka": "ქართული",
"de": "Deutsch",
"el": "Ελληνικά",
"gn": "Avañeẽ",
"gu": "ગુજરાતી",
"ht": "Kreyòl ayisyen",
"ha": "Hausa, هَوُسَ",
"he": "עברית",
"hz": "Otjiherero",
"hi": "हिन्दी, हिंदी",
"ho": "Hiri Motu",
"hu": "Magyar",
"ia": "Interlingua",
"id": "Bahasa Indonesia",
"ie": "Occidental (Interlingue)",
"ga": "Gaeilge",
"ig": "Asụsụ Igbo",
"ik": "Iñupiaq, Iñupiatun",
"io": "Ido",
"is": "Íslenska",
"it": "Italiano",
"iu": "ᐃᓄᒃᑎᑐᑦ",
"ja": "日本語 (にほんご/にっぽんご)",
"jv": "basa Jawa",
"kl": "kalaallisut, kalaallit oqaasii",
"kn": "ಕನ್ನಡ",
"kr": "Kanuri",
"ks": "कश्मीरी, كشميري‎",
"kk": "Қазақ тілі",
"km": "ភាសាខ្មែរ",
"ki": "Gĩkũyũ",
"rw": "Ikinyarwanda",
"ky": "кыргыз тили",
"kv": "коми кыв",
"kg": "KiKongo",
"ko": "한국어 (韓國語), 조선말 (朝鮮語)",
"ku": "Kurdî, كوردی‎",
"kj": "Kuanyama",
"la": "latine, lingua latina",
"lb": "Lëtzebuergesch",
"lg": "Luganda",
"li": "Limburgs",
"ln": "Lingála",
"lo": "ພາສາລາວ",
"lt": "lietuvių kalba",
"lu": "",
"lv": "latviešu valoda",
"gv": "Gaelg, Gailck",
"mk": "македонски јазик",
"mg": "Malagasy fiteny",
"ms": "bahasa Melayu, بهاس ملايو‎",
"ml": "മലയാളം",
"mt": "Malti",
"mi": "te reo Māori",
"mr": "मराठी",
"mh": "Kajin M̧ajeļ",
"mn": "монгол",
"na": "Ekakairũ Naoero",
"nv": "Diné bizaad, Dinékʼehǰí",
"nb": "Norsk bokmål",
"nd": "isiNdebele",
"ne": "नेपाली",
"ng": "Owambo",
"nn": "Norsk nynorsk",
"no": "Norsk",
"ii": "ꆈꌠ꒿ Nuosuhxop",
"nr": "isiNdebele",
"oc": "Occitan",
"oj": "ᐊᓂᔑᓈᐯᒧᐎᓐ",
"cu": "ѩзыкъ словѣньскъ",
"om": "Afaan Oromoo",
"or": "ଓଡ଼ିଆ",
"os": "ирон æвзаг",
"pa": "ਪੰਜਾਬੀ, پنجابی‎",
"pi": "पाऴि",
"fa": "فارسی",
"pl": "polski",
"ps": "پښتو",
"pt": "Português",
"qu": "Runa Simi, Kichwa",
"rm": "rumantsch grischun",
"rn": "kiRundi",
"ro": "română",
"ru": "русский язык",
"sa": "संस्कृतम्",
"sc": "sardu",
"sd": "सिन्धी, سنڌي، سندھی‎",
"se": "Davvisámegiella",
"sm": "gagana faa Samoa",
"sg": "yângâ tî sängö",
"sr": "српски језик",
"gd": "Gàidhlig",
"sn": "chiShona",
"si": "සිංහල",
"sk": "slovenčina",
"sl": "slovenščina",
"so": "Soomaaliga, af Soomaali",
"st": "Sesotho",
"es": "español, castellano",
"su": "Basa Sunda",
"sw": "Kiswahili",
"ss": "SiSwati",
"sv": "svenska",
"ta": "தமிழ்",
"te": "తెలుగు",
"tg": "тоҷикӣ, toğikī, تاجیکی‎",
"th": "ไทย",
"ti": "ትግርኛ",
"bo": "བོད་ཡིག",
"tk": "Türkmen, Түркмен",
"tl": "Wikang Tagalog, ᜏᜒᜃᜅ᜔ ᜆᜄᜎᜓᜄ᜔",
"tn": "Setswana",
"to": "faka Tonga",
"tr": "Türkçe",
"ts": "Xitsonga",
"tt": "татарча, tatarça, تاتارچا‎",
"tw": "Twi",
"ty": "Reo Tahiti",
"ug": "Uyƣurqə, ئۇيغۇرچە‎",
"uk": "українська",
"ur": "اردو",
"uz": "zbek, Ўзбек, أۇزبېك‎",
"ve": "Tshivenḓa",
"vi": "Tiếng Việt",
"vo": "Volapük",
"wa": "Walon",
"cy": "Cymraeg",
"wo": "Wollof",
"fy": "Frysk",
"xh": "isiXhosa",
"yi": "ייִדיש",
"yo": "Yorùbá",
"za": "Saɯ cueŋƅ, Saw cuengh"
};

String? getDisplayLanguage(Locale l) {
return _isoLangs[l.languageCode];
}
10 changes: 10 additions & 0 deletions lib/model/ram_only_implementations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class RamSettings extends ChangeNotifier implements Settings {
String _defaultExportDir = '';
bool _exportAfterEveryEntry = false;
bool _allowMissingValues = false;
Locale? _language;

RamSettings() {
_accentColor = createMaterialColor(0xFF009688);
Expand Down Expand Up @@ -363,6 +364,15 @@ class RamSettings extends ChangeNotifier implements Settings {
notifyListeners();
}

@override
Locale? get language => _language;

@override
set language(Locale? value) {
_language = value;
notifyListeners();
}

@override
void changeStepSize(TimeStep value) {
graphStepSize = value;
Expand Down
11 changes: 11 additions & 0 deletions lib/model/settings_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,17 @@ class Settings extends ChangeNotifier {
_prefs.setBool('exportAfterEveryEntry', value);
notifyListeners();
}

Locale? get language {
final value = _prefs.getString('language');
if (value?.isEmpty ?? true) return null;
return Locale(value ?? 'en');
}

set language (Locale? value) {
_prefs.setString('language', value?.languageCode ?? '');
notifyListeners();
}
}

enum TimeStep {
Expand Down
15 changes: 15 additions & 0 deletions lib/screens/settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:blood_pressure_app/components/consistent_future_builder.dart';
import 'package:blood_pressure_app/components/settings_widgets.dart';
import 'package:blood_pressure_app/model/blood_pressure.dart';
import 'package:blood_pressure_app/model/iso_lang_names.dart';
import 'package:blood_pressure_app/model/settings_store.dart';
import 'package:blood_pressure_app/screens/subsettings/enter_timeformat.dart';
import 'package:blood_pressure_app/screens/subsettings/export_import_screen.dart';
Expand Down Expand Up @@ -79,6 +80,20 @@ class SettingsPage extends StatelessWidget {
}
},
),
DropDownSettingsTile<Locale?>(
key: const Key('language'),
leading: const Icon(Icons.language),
title: Text(AppLocalizations.of(context)!.language),
value: settings.language,
items: [
DropdownMenuItem(value: null, child: Text(AppLocalizations.of(context)!.system)),
for (final l in AppLocalizations.supportedLocales)
DropdownMenuItem(value: l, child: Text(getDisplayLanguage(l) ?? l.languageCode)),
],
onChanged: (Locale? value) {
settings.language = value;
},
),
SliderSettingsTile(
key: const Key('iconSize'),
title: Text(AppLocalizations.of(context)!.iconSize),
Expand Down
15 changes: 12 additions & 3 deletions test/model/settings_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:blood_pressure_app/model/ram_only_implementations.dart';
import 'package:blood_pressure_app/model/settings_store.dart';
import 'package:file_saver/file_saver.dart';
Expand Down Expand Up @@ -47,6 +49,7 @@ void main() {
expect(s.defaultExportDir.isEmpty, true);
expect(s.exportAfterEveryEntry, false);
expect(s.allowMissingValues, false);
expect(s.language, null);
});

test('setting fields should save changes', () async {
Expand Down Expand Up @@ -91,6 +94,7 @@ void main() {
s.defaultExportDir = '/storage/emulated/0/Android/data/com.derdilla.bloodPressureApp/files/file.csv';
s.exportAfterEveryEntry = true;
s.allowMissingValues = true;
s.language = const Locale('de');

expect(s.displayDataStart, DateTime.fromMillisecondsSinceEpoch(10000));
expect(s.displayDataEnd, DateTime.fromMillisecondsSinceEpoch(200000));
Expand Down Expand Up @@ -118,6 +122,7 @@ void main() {
expect(s.defaultExportDir, '/storage/emulated/0/Android/data/com.derdilla.bloodPressureApp/files/file.csv');
expect(s.exportAfterEveryEntry, true);
expect(s.allowMissingValues, true);
expect(s.language, const Locale('de'));
});

test('setting fields should notify listeners and change values', () async {
Expand Down Expand Up @@ -156,8 +161,9 @@ void main() {
s.defaultExportDir = '/storage/emulated/0/Android/data/com.derdilla.bloodPressureApp/files/file.csv';
s.exportAfterEveryEntry = true;
s.allowMissingValues = true;
s.language = const Locale('de');

expect(i, 28);
expect(i, 29);
});
});

Expand Down Expand Up @@ -199,6 +205,7 @@ void main() {
expect(s.defaultExportDir.isEmpty, true);
expect(s.exportAfterEveryEntry, false);
expect(s.allowMissingValues, false);
expect(s.language, null);
});

test('setting fields should save changes', () async {
Expand Down Expand Up @@ -243,6 +250,7 @@ void main() {
s.defaultExportDir = '/storage/emulated/0/Android/data/com.derdilla.bloodPressureApp/files/file.csv';
s.exportAfterEveryEntry = true;
s.allowMissingValues = true;
s.language = const Locale('de');

expect(s.displayDataStart, DateTime.fromMillisecondsSinceEpoch(10000));
expect(s.displayDataEnd, DateTime.fromMillisecondsSinceEpoch(200000));
Expand Down Expand Up @@ -270,7 +278,7 @@ void main() {
expect(s.defaultExportDir, '/storage/emulated/0/Android/data/com.derdilla.bloodPressureApp/files/file.csv');
expect(s.exportAfterEveryEntry, true);
expect(s.allowMissingValues, true);

expect(s.language, const Locale('de'));
});

test('setting fields should notify listeners and change values', () async {
Expand Down Expand Up @@ -309,8 +317,9 @@ void main() {
s.defaultExportDir = '/storage/emulated/0/Android/data/com.derdilla.bloodPressureApp/files/file.csv';
s.exportAfterEveryEntry = true;
s.allowMissingValues = true;
s.language = const Locale('de');

expect(i, 28);
expect(i, 29);
});
});
}

0 comments on commit 8f7e800

Please sign in to comment.