diff --git a/assets/translations/de.json b/assets/translations/de.json index 354b8519..bffa69db 100644 --- a/assets/translations/de.json +++ b/assets/translations/de.json @@ -63,8 +63,8 @@ "change_application_theme": "Ihr Anwendungsdesign wechseln", "dangerous_settings": "Gefährliche Einstellungen", "reset_config_title": "Anwendungseinstellungen zurücksetzen", - "reset_config_description": "API Sclüssel und root Benutzer zurücksetzen.", - }, + "reset_config_description": "API Sclüssel und root Benutzer zurücksetzen." + }, "ssh": { "title": "SSH Schlüssel", "create": "SSH Schlüssel erstellen", diff --git a/lib/config/localization.dart b/lib/config/localization.dart index 64d734ee..697235b2 100644 --- a/lib/config/localization.dart +++ b/lib/config/localization.dart @@ -7,32 +7,63 @@ class Localization extends StatelessWidget { super.key, }); + // when adding new locale, add corresponding native language name to mapper + // below + static const supportedLocales = [ + Locale('ar'), + Locale('az'), + Locale('be'), + Locale('cs'), + Locale('de'), + Locale('en'), + Locale('es'), + Locale('et'), + Locale('fr'), + Locale('he'), + Locale('kk'), + Locale('lv'), + Locale('mk'), + Locale('pl'), + Locale('ru'), + Locale('sk'), + Locale('sl'), + Locale('th'), + Locale('uk'), + Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'), + ]; + + // https://en.wikipedia.org/wiki/IETF_language_tag#List_of_common_primary_language_subtags + static final _languageNames = { + const Locale('ar'): 'العربية', + const Locale('az'): 'Azərbaycan', + const Locale('be'): 'беларуская', + const Locale('cs'): 'čeština', + const Locale('de'): 'Deutsch', + const Locale('en'): 'English', + const Locale('es'): 'español', + const Locale('et'): 'eesti', + const Locale('fr'): 'français', + const Locale('he'): 'עברית', + const Locale('kk'): 'Қазақша', + const Locale('lv'): 'latviešu', + const Locale('mk'): 'македонски јазик', + const Locale('pl'): 'polski', + const Locale('ru'): 'русский', + const Locale('sk'): 'slovenčina', + const Locale('sl'): 'slovenski', + const Locale('th'): 'ไทย', + const Locale('uk'): 'Українська', + const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'): '中文', + }; + + static String getLanguageName(final Locale locale) => + _languageNames[locale] ?? locale.languageCode; + final Widget child; @override Widget build(final BuildContext context) => EasyLocalization( - supportedLocales: const [ - Locale('ar'), - Locale('az'), - Locale('be'), - Locale('cs'), - Locale('de'), - Locale('en'), - Locale('es'), - Locale('et'), - Locale('fr'), - Locale('he'), - Locale('kk'), - Locale('lv'), - Locale('mk'), - Locale('pl'), - Locale('ru'), - Locale('sk'), - Locale('sl'), - Locale('th'), - Locale('uk'), - Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'), - ], + supportedLocales: supportedLocales, path: 'assets/translations', fallbackLocale: const Locale('en'), useFallbackTranslations: true, diff --git a/lib/ui/pages/more/app_settings/app_settings.dart b/lib/ui/pages/more/app_settings/app_settings.dart index b96fd749..d429f2c0 100644 --- a/lib/ui/pages/more/app_settings/app_settings.dart +++ b/lib/ui/pages/more/app_settings/app_settings.dart @@ -3,6 +3,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:gap/gap.dart'; import 'package:selfprivacy/config/app_controller/inherited_app_controller.dart'; +import 'package:selfprivacy/config/localization.dart'; import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart'; import 'package:selfprivacy/ui/components/buttons/dialog_action_button.dart'; import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart'; diff --git a/lib/ui/pages/more/app_settings/language_picker.dart b/lib/ui/pages/more/app_settings/language_picker.dart index 75738ccc..e9b39747 100644 --- a/lib/ui/pages/more/app_settings/language_picker.dart +++ b/lib/ui/pages/more/app_settings/language_picker.dart @@ -12,7 +12,7 @@ class _LanguagePicker extends StatelessWidget { trailing: Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), child: Text( - context.locale.toString(), + Localization.getLanguageName(context.locale), style: Theme.of(context).textTheme.headlineSmall, ), ), @@ -42,12 +42,18 @@ class _LanguagePickerDialog extends StatelessWidget { for (final locale in InheritedAppController.of(context).supportedLocales) ListTile( - // TODO: add locale to language name matcher - title: Text(locale.toString()), + title: Text( + Localization.getLanguageName(locale), + style: TextStyle( + fontWeight: locale == context.locale + ? FontWeight.w800 + : FontWeight.w400, + ), + ), onTap: () { Navigator.of(context).pop(locale); }, - ) + ), ], ); }