Skip to content

Commit

Permalink
temp locale define
Browse files Browse the repository at this point in the history
  • Loading branch information
aprosail committed Jun 29, 2024
1 parent 43cdfe3 commit dc362f6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/src/locale.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'dart:ui' as r;

class Locale {
const Locale({required this.languageCode, this.areaCode});

factory Locale.from(String raw) {
final full = raw.toLowerCase();
for (final sep in ['-', '_']) {
if (full.contains(sep)) {
final parts = full.split(sep);
return Locale(languageCode: parts[0], areaCode: parts[1]);
}
}
return Locale(languageCode: full);
}

factory Locale.fromFrameLocale(r.Locale raw) =>
Locale(languageCode: raw.languageCode, areaCode: raw.countryCode);

final String languageCode;
final String? areaCode;

@override
String toString() =>
areaCode == null ? languageCode : '$languageCode-$areaCode';
}

0 comments on commit dc362f6

Please sign in to comment.