Skip to content

Commit

Permalink
Merge pull request #174 from enrique-lozano/feat/add-ukranian-lang
Browse files Browse the repository at this point in the history
Add ukranian language
  • Loading branch information
enrique-lozano authored Jul 14, 2024
2 parents 56b3f71 + f7983a5 commit c56459b
Show file tree
Hide file tree
Showing 7 changed files with 9,495 additions and 3,226 deletions.
50 changes: 37 additions & 13 deletions lib/app/settings/appearance_settings_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:monekin/app/settings/widgets/language_selector.dart';
import 'package:monekin/app/settings/widgets/supported_locales.dart';
import 'package:monekin/core/database/services/user-setting/user_setting_service.dart';
import 'package:monekin/core/extensions/color.extensions.dart';
import 'package:monekin/core/presentation/widgets/color_picker/color_picker.dart';
Expand Down Expand Up @@ -106,20 +108,42 @@ class _AdvancedSettingsPageState extends State<AdvancedSettingsPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
createListSeparator(context, t.settings.lang_section),
buildSelector(
title: t.settings.lang_title,
dialogDescr: t.settings.lang_descr,
items: [
SelectItem(value: 'es', label: t.lang.es),
SelectItem(value: 'en', label: t.lang.en)
],
selected: LocaleSettings.currentLocale.languageTag,
onChanged: (value) {
LocaleSettings.setLocaleRaw(value, listenToDeviceLocale: true);
ListTile(
title: Text(t.settings.lang_title),
subtitle: Text(
appSupportedLocales
.firstWhere((element) =>
element.locale.languageTag ==
LocaleSettings.currentLocale.languageTag)
.label,
),
onTap: () async {
final snackbarDisplayer =
ScaffoldMessenger.of(context).showSnackBar;

final newLang = await showLanguageSelectorBottomSheet(
context,
LanguageSelector(
selectedLangTag:
LocaleSettings.currentLocale.languageTag),
);

if (newLang == null) {
return;
}

LocaleSettings.setLocaleRaw(newLang,
listenToDeviceLocale: true);

UserSettingService.instance
.setSetting(SettingKey.appLanguage, value)
.then((value) => null);
try {
await UserSettingService.instance
.setSetting(SettingKey.appLanguage, newLang);
} catch (e) {
snackbarDisplayer(const SnackBar(
content: Text(
'There was an error persisting this setting on your device. Contact the developers for more information'),
));
}
},
),
createListSeparator(context, t.settings.theme_and_colors),
Expand Down
60 changes: 60 additions & 0 deletions lib/app/settings/widgets/language_selector.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';
import 'package:monekin/app/settings/widgets/supported_locales.dart';
import 'package:monekin/core/presentation/widgets/modal_container.dart';
import 'package:monekin/i18n/translations.g.dart';

Future<String?> showLanguageSelectorBottomSheet(
BuildContext context, LanguageSelector langSelector) {
return showModalBottomSheet<String>(
context: context,
showDragHandle: true,
isScrollControlled: true,
builder: (context) {
return langSelector;
},
);
}

class LanguageSelector extends StatelessWidget {
const LanguageSelector({super.key, required this.selectedLangTag});

/// Lang ID of the selected locale ("en", "zh-TW"...)
final String selectedLangTag;

Widget _langRadioTile(BuildContext context,
{required SupportedLocale supportedLocale}) {
return RadioListTile(
value: supportedLocale.locale.languageTag,
title: Text(supportedLocale.label),
groupValue: selectedLangTag,
onChanged: (value) {
if (value == null) {
return;
}

Navigator.of(context).pop(value);
},
);
}

@override
Widget build(BuildContext context) {
final t = Translations.of(context);

return ModalContainer(
title: t.settings.lang_title,
subtitle: t.settings.lang_descr,
responseToKeyboard: false,
body: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
...appSupportedLocales
.map((e) => _langRadioTile(context, supportedLocale: e)),
const SizedBox(height: 12)
],
),
),
);
}
}
14 changes: 14 additions & 0 deletions lib/app/settings/widgets/supported_locales.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:monekin/i18n/translations.g.dart';

class SupportedLocale {
final AppLocale locale;
final String label;

const SupportedLocale({required this.locale, required this.label});
}

const appSupportedLocales = [
SupportedLocale(locale: AppLocale.es, label: 'Español'),
SupportedLocale(locale: AppLocale.en, label: 'English'),
SupportedLocale(locale: AppLocale.uk, label: 'українська'),
];
4 changes: 0 additions & 4 deletions lib/i18n/strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,5 @@
"donate.err": "Oops! It seems there was an error receiving your payment",
"report": "Report bugs, leave suggestions..."
}
},
"LANG": {
"es": "Spanish",
"en": "English"
}
}
4 changes: 0 additions & 4 deletions lib/i18n/strings_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,5 @@
"donate.err": "Ups! Parece que ha habido un error a la hora de recibir tu pago",
"report": "Reporta errores, deja sugerencias..."
}
},
"LANG": {
"es": "Español",
"en": "Inglés"
}
}
Loading

0 comments on commit c56459b

Please sign in to comment.