#51 new: custom language

This commit is contained in:
lollipopkit
2023-05-27 17:47:48 +08:00
parent 371f60c68a
commit b04c2a9693
12 changed files with 110 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
extension LocaleX on Locale {
String get name {
if (countryCode == null) {
return languageCode;
}
return '${languageCode}_$countryCode';
}
}
extension String2Locale on String {
Locale get toLocale {
final parts = split('_');
if (parts.length == 1) {
return Locale(parts[0]);
}
return Locale(parts[0], parts[1]);
}
}