Files
ai_chat_assistant/packages/basic_intl/lib/src/intl.dart

33 lines
792 B
Dart
Raw Normal View History

import 'dart:ui';
class Intl {
static String _currentLocale = 'zh_CN';
/// 获取当前语言环境
static String getCurrentLocale() {
// 尝试从系统获取语言环境
try {
final systemLocale = PlatformDispatcher.instance.locale;
_currentLocale = '${systemLocale.languageCode}_${systemLocale.countryCode ?? 'CN'}';
} catch (e) {
_currentLocale = 'zh_CN';
}
return _currentLocale;
}
/// 设置当前语言环境
static void setCurrentLocale(String locale) {
_currentLocale = locale;
}
/// 判断是否为中文环境
static bool isChineseLocale() {
return getCurrentLocale().startsWith('zh');
}
/// 判断是否为英文环境
static bool isEnglishLocale() {
return getCurrentLocale().startsWith('en');
}
}