Skip to content

Commit

Permalink
refactor: use weblate languages data
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Feb 27, 2021
1 parent 36a161c commit f64c02b
Show file tree
Hide file tree
Showing 3 changed files with 612 additions and 44 deletions.
26 changes: 0 additions & 26 deletions lib/models/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,6 @@ class DialogOption<T> {
DialogOption({this.value, this.widget});
}

class SupportedLocales {
static const en = 'en';
static const hi = 'hi';
static const es = 'es';
static const nb_NO = 'nb_NO';
static const pt_BR = 'pt_BR';
static const zh_Hans = 'zh_Hans';
static const values = [
SupportedLocales.en,
SupportedLocales.hi,
SupportedLocales.es,
SupportedLocales.nb_NO,
SupportedLocales.pt_BR,
SupportedLocales.zh_Hans,
];
static const Map<String, String> languageNameExpanded = {
'en': 'English',
'hi': 'हिन्दी',
'es': 'Español',
'nb_NO': 'Norsk bokmål (Norge) ',
'pt_BR': 'Portugues (brasil)',
'zh_Hans': '简体中文',
'zh_Hant': '正体中文'
};
}

class AppThemeType {
static const material = 0;
static const cupertino = 1;
Expand Down
32 changes: 14 additions & 18 deletions lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/code.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/scaffolds/single.dart';
import 'package:git_touch/utils/locale.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/action_button.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
Expand All @@ -15,16 +16,6 @@ import 'package:tuple/tuple.dart';
import 'package:flutter_gen/gen_l10n/S.dart';

class SettingsScreen extends StatelessWidget {
// After translation finished, add locale name here to display in settings
static const localeNameMap = {
'en': 'English',
'hi': 'हिन्दी',
'es': 'Español',
'nb_NO': 'Norsk bokmål (Norge)',
'pt_BR': 'Portugues (brasil)',
'zh_Hans': '简体中文',
};

@override
Widget build(BuildContext context) {
final theme = Provider.of<ThemeModel>(context);
Expand Down Expand Up @@ -81,22 +72,27 @@ class SettingsScreen extends StatelessWidget {
text: Text('App Language'),
rightWidget: Text(theme.locale == null
? AppLocalizations.of(context).followSystem
: localeNameMap[theme.locale] ?? 'Unknown'),
: localeNameMap[theme.locale] ?? theme.locale),
onTap: () {
theme.showActions(context, [
for (final e in [
MapEntry(null, AppLocalizations.of(context).followSystem),
...localeNameMap.entries
for (final key in [
null,
...AppLocalizations.supportedLocales
.map((l) => l.toString())
.where((key) => localeNameMap[key] != null)
])
ActionItem(
text: e.value,
text: key == null
? AppLocalizations.of(context).followSystem
: localeNameMap[key],
onTap: (_) async {
final res = await theme.showConfirm(
context,
Text('Reload the App to take effect'),
Text(
'The app will reload to make the language setting take effect'),
);
if (res && theme.locale != e.key) {
await theme.setLocale(e.key);
if (res && theme.locale != key) {
await theme.setLocale(key);
auth.reloadApp();
}
},
Expand Down

0 comments on commit f64c02b

Please sign in to comment.