介绍
多语言方案:GetX版,需要手动自定义字符串引用常量,优点不需要自己管理状态。
目录
运行效果
一、安装 GetX
dependencies:
get: ^4.6.6
二、使用
1.语言配置 在lib/core下创建一个language文件夹,文件夹下创建一个local.dart文件
class Local {
static const String appName = 'BraveComponent';
static const String helloWorld = '你好,世界';
static const String followerSystemLanguage = '跟随系统语言';
static const String simplifiedChinese = '简体中文';
static const String traditionalChinese = '繁体中文';
static const String english = '英文';
static const String setting = '设置';
static const String multiLanguage = '多语言';
static const String theme = '主题';
}
2.language文件夹下创建一个messages.dart文件
import 'package:get/get.dart';
import 'local.dart';
class Messages extends Translations {
@override
Map<String, Map<String, String>> get keys => {
'zh_CN': {
Local.appName: 'BraveComponent',
Local.helloWorld: '你好,世界',
Local.followerSystemLanguage: '跟随系统语言',
Local.simplifiedChinese: '简体中文',
Local.traditionalChinese: '繁体中文',
Local.english: '英文',
Local.setting: '设置',
Local.multiLanguage: '多语言',
Local.theme: '主题',
},
'zh_HK': {
Local.appName: 'BraveComponent',
Local.helloWorld: '妳好,世界',
Local.followerSystemLanguage: '跟隨系統語言',
Local.simplifiedChinese: '簡體中文',
Local.traditionalChinese: '繁體中文',
Local.english: '英文',
Local.setting: '設置',
Local.multiLanguage: '多語言',
Local.theme: '主題',
},
'en_US': {
Local.appName: 'BraveComponent',
Local.helloWorld: 'HelloWorld',
Local.followerSystemLanguage: 'FollowerSystemLanguage',
Local.simplifiedChinese: 'SimplifiedChinese',
Local.traditionalChinese: 'TraditionalChinese',
Local.english: 'English',