Commit f4a55f8
Changed files (2)
lib
model
test
lib/model/iso_lang_names.dart
@@ -3,24 +3,30 @@ import 'package:flutter/material.dart';
/// Selects the correct language name for a specific language code.
///
/// Does not account for dialects.
-String? getDisplayLanguage(Locale l) => switch(l.toLanguageTag()) {
+String getDisplayLanguage(Locale l) => switch(l.toLanguageTag()) {
'en' => 'English',
'en-US' => 'English (US)',
'de' => 'Deutsch',
- 'fr' => 'française',
+ 'fr' => 'Française',
'it' => 'Italiano',
'nb' => 'Norsk bokmål',
'pt' => 'Português',
- 'pt-BR' => 'português (Brasil)',
- 'ru' => 'русский',
+ 'pt-BR' => 'Português (Brasil)',
+ 'ru' => 'Русский',
'tr' => 'Türkçe',
'zh' => '中文 (简体)',
'zh-Hant' => '中文(繁體)',
// Websites with names for expanding when new languages get added:
// - https://chronoplexsoftware.com/localisation/help/languagecodes.htm
// - https://localizely.com/locale-code/zh-Hans/
+ //
+ // Names should be modified so they start with an upper case letter.
+ //
(_) => (){
- assert(false, l.toString());
+ debugPrint('Unlocalized language tag: $l');
+ debugPrintStack();
+ assert(false, 'Should only be called for localized strings and all '
+ 'localized strings are tested.');
return l.languageCode;
}()
};
test/model/iso_lang_names_test.dart
@@ -0,0 +1,41 @@
+import 'package:blood_pressure_app/model/iso_lang_names.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() {
+ group('getDisplayLanguage', () {
+ test('should have unique names for all languages provided in localizations', () {
+ final allNames = <String>[];
+ for (final locale in AppLocalizations.supportedLocales) {
+ final name = getDisplayLanguage(locale);
+ expect(allNames, isNot(contains(name)));
+ allNames.add(name);
+ }
+ });
+ test('should start all names in upper case', () {
+ for (final locale in AppLocalizations.supportedLocales) {
+ final firstChar = getDisplayLanguage(locale)[0];
+ expect(firstChar, equals(firstChar.toUpperCase()));
+ }
+ });
+ test('should not store names where no localization present', () {
+ final tmp = debugPrint;
+ int printCounts = 0;
+ debugPrint = (String? s, {int? wrapWidth}) {
+ printCounts += 1;
+ };
+ for (final c1 in 'abcdefghijklmnopqrstuvwxyz'.characters) {
+ for (final c2 in 'abcdefghijklmnopqrstuvwxyz'.characters) {
+ if (AppLocalizations.supportedLocales.where(
+ (e) => e.toLanguageTag() == '$c1$c2',).isNotEmpty) continue;
+ expect(() => getDisplayLanguage(Locale('$c1$c2')),
+ throwsAssertionError,);
+ expect(printCounts, greaterThan(1));
+ printCounts = 0;
+ }
+ }
+ debugPrint = tmp;
+ });
+ });
+}