一使用 flutter Intl
Android studio需要添加插件 flutter Intl
路径 File>>Settings>>Plugins>>Marketplace>>flutter Intl>>Install
安装插件重新启动Android studio
Android studio 创建一个flutter测试的新项目
在项目文件中配置 ** 添加完成需要flutter pub get
pubspec.yaml
#国际化配置 1
flutter_localizations:
sdk: flutter
#
intl: ^0.19.0
#生成文件
intl_utils: ^2.0.0
使用插件生成配置文件
1.Tools>>Flutter lIntl>>Initialize for the Project
2.Tools>>Flutter lIntl>>Add Locale
中文zh 英文 en
看到{lib>>|10n}生成相关文件,文件内容{}
填写文件
中文
{
"appName": "zq国际化{name}",
"autoBySystem": "跟随系统",
"theme": "色彩主题",
"settingLanguage": "多语言",
"darkMode": "黑夜模式",
"language": "语言",
"settingFont": "字体"
}
中文
{
"appName": "zqinternational{name}",
"autoBySystem": "Auto",
"theme": "Theme",
"settingLanguage": "Language",
"darkMode": "Dark Mode",
"language": "Language",
"settingFont": "System Font"
}
重点 “appName”: “zq国际化{name}”,
{name}是一个占位符可以加入动态的字符,配置时都需要配置
执行 flutter pub run intl_utils:generate 生成相关文件
PS F:\project\android_flutter\language> flutter pub run intl_utils:generate
Flutter assets will be downloaded from https://mirrors.tuna.tsinghua.edu.cn/flutter. Make sure you trust this source!
Deprecated. Use `dart run` instead.
Building package executable... (5.0s)
Built intl_utils:generate.
INFO: No @@locale or _locale field found in intl_en, assuming 'en' based on the file name.
INFO: No @@locale or _locale field found in intl_zh, assuming 'zh' based on the file name.
PS F:\project\android_flutter\language>
在项目文件目录 lib>>generated>>|10n.dart 看到如下文件
....
....
/// `zqinternational{name}`
String appName(Object name) {
return Intl.message(
'zqinternational$name',
name: 'appName',
desc: '',
args: [name],
);
}
/// `Auto`
String get autoBySystem {
return Intl.message(
'Auto',
name: 'autoBySystem',
desc: '',
args: [],
);
}
....
....
使用 区别 有占位符
S.of(context)!.appName(‘${你好}’)
S.of(context)!.autoBySystem
下载地址 https://download.csdn.net/download/ZQ200720/90057955
项目下载地址
0积分