From 52e647b44477568b5d65a2e78aecdaa553b04c25 Mon Sep 17 00:00:00 2001 From: Tien Do Nam Date: Sat, 19 Oct 2024 12:26:18 +0200 Subject: [PATCH] feat: add underscoreTag --- slang/lib/src/api/locale.dart | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/slang/lib/src/api/locale.dart b/slang/lib/src/api/locale.dart index 7553f1c6..7a9eb314 100644 --- a/slang/lib/src/api/locale.dart +++ b/slang/lib/src/api/locale.dart @@ -86,10 +86,19 @@ abstract mixin class BaseAppLocale, static final BaseAppLocale undefinedLocale = FakeAppLocale(languageCode: 'und'); - String get languageTag => [languageCode, scriptCode, countryCode] + /// Concatenates language, script and country code with dashes. + /// Resembles [Locale.toLanguageTag] of dart:ui. + late final String languageTag = [languageCode, scriptCode, countryCode] .where((element) => element != null) .join('-'); + /// For whatever reason, the intl package uses underscores instead of dashes + /// that contradicts https://www.unicode.org/reports/tr35/ + /// that is used by the Locale class in dart:ui. + late final String underscoreTag = [languageCode, scriptCode, countryCode] + .where((element) => element != null) + .join('_'); + bool sameLocale(BaseAppLocale other) { return languageCode == other.languageCode && scriptCode == other.scriptCode && @@ -123,12 +132,7 @@ class FakeAppLocale extends BaseAppLocale { PluralResolver? cardinalResolver, PluralResolver? ordinalResolver, }) async => - FakeTranslations( - FakeAppLocale( - languageCode: languageCode, - scriptCode: scriptCode, - countryCode: countryCode, - ), + buildSync( overrides: overrides, cardinalResolver: cardinalResolver, ordinalResolver: ordinalResolver,