mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-19 07:09:14 +00:00
feat: native language names for locale picker
This commit is contained in:
parent
c70edb957d
commit
0ee46e1c1e
|
@ -63,7 +63,7 @@
|
|||
"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",
|
||||
|
|
|
@ -7,11 +7,9 @@ class Localization extends StatelessWidget {
|
|||
super.key,
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) => EasyLocalization(
|
||||
supportedLocales: const [
|
||||
// when adding new locale, add corresponding native language name to mapper
|
||||
// below
|
||||
static const supportedLocales = [
|
||||
Locale('ar'),
|
||||
Locale('az'),
|
||||
Locale('be'),
|
||||
|
@ -32,7 +30,40 @@ class Localization extends StatelessWidget {
|
|||
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: supportedLocales,
|
||||
path: 'assets/translations',
|
||||
fallbackLocale: const Locale('en'),
|
||||
useFallbackTranslations: true,
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
)
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue