Skip to content

Commit

Permalink
feat: add underscoreTag
Browse files Browse the repository at this point in the history
  • Loading branch information
Tienisto committed Oct 19, 2024
1 parent 0b55a71 commit 52e647b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions slang/lib/src/api/locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,19 @@ abstract mixin class BaseAppLocale<E extends BaseAppLocale<E, T>,
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 &&
Expand Down Expand Up @@ -123,12 +132,7 @@ class FakeAppLocale extends BaseAppLocale<FakeAppLocale, FakeTranslations> {
PluralResolver? cardinalResolver,
PluralResolver? ordinalResolver,
}) async =>
FakeTranslations(
FakeAppLocale(
languageCode: languageCode,
scriptCode: scriptCode,
countryCode: countryCode,
),
buildSync(
overrides: overrides,
cardinalResolver: cardinalResolver,
ordinalResolver: ordinalResolver,
Expand Down

0 comments on commit 52e647b

Please sign in to comment.