flutter_localization:基于 Flutter 的应用内本地化工具包

暂无描述

分支5Tags4
文件最后提交记录最后更新时间
7 个月前
7 个月前
3 年前
7 个月前
3 年前
3 年前
2 个月前
3 年前
2 年前
3 年前
7 个月前
1 年前
3 年前
2 年前
2 个月前
2 个月前
1 年前
7 个月前
2 个月前
7 个月前
7 个月前

flutter_localization

本项目基于 flutter_localization 开发。

1. 安装与使用

1.1 安装方式

进入到工程目录并在 pubspec.yaml 中添加以下依赖:

pubspec.yaml

...

dependencies:
  flutter_localization:
    git:
      url: https://gitcode.com/CPF-Flutter/flutter_localization.git
      ref: br_v0.3.3_ohos
...

执行命令

flutter pub get

1.2 使用案例

使用案例详见 example

2. 约束与限制

2.1 兼容性

在以下版本中已测试通过:

  1. Flutter: 3.7.12-ohos-1.1.3; SDK: 5.0.0(12); IDE: DevEco Studio: 5.1.0.828; ROM: 5.1.0.130 SP8;
  2. Flutter: 3.22.1-ohos-1.0.3; SDK: 5.0.0(12); IDE: DevEco Studio: 5.1.0.828; ROM: 5.1.0.130 SP8;
  3. Flutter: 3.27.5-ohos-1.0.1; SDK: 6.0.1(21); IDE: DevEco Studio: 6.0.1.251; ROM: 6.0.0.120 SP6;
  4. Flutter: 3.35.7-ohos-0.0.1; SDK: 6.0.1(21); IDE: DevEco Studio: 6.0.1.260; ROM: 6.0.0.120 SP6;

3. API

"ohos Support"列为 yes 表示 ohos 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。

FlutterLocalization API

Name Description Type Input Output ohos Support
init 初始化应用启动时的mapLocale列表(参见[MapLocale]模型)和initLanguageCode代码。这两个字段是必需的。 function { required List mapLocales, required String initLanguageCode } Future yes
translate 在需要翻译应用时调用此函数,例如通过点击按钮或其他操作。 function String languageCode, { bool save = true } void yes
getLanguageName 该方法仅调用[FlutterLocalizationTranslator]类中的getName()函数,通过语言代码获取完整的语言名称。 function { String? languageCode } String yes

4. 属性

"ohos Support"列为 yes 表示 ohos 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。

FlutterLocalization Filters

Name Description Type Input Output ohos Support
onTranslatedLanguage 翻译的回调函数。在[translate]函数调用后触发。 TranslatorCallback? / / yes
supportedLanguageCodes 获取由[init]函数提供的受支持语言代码列表。 List / / yes
currentLocale 获取应用的当前区域设置(Locale)。 Locale? / / yes
supportedLocales 生成应用支持的区域设置(Locales)列表。 Iterable / / yes
localizationsDelegates 为应用程序应用所有必需的委托以及包委托。 Iterable<LocalizationsDelegate> / / yes
fontFamily 根据当前区域设置的语言代码提供字体名称。 String? / / yes

MapLocale Filters

Name Description Type Input Output ohos Support
languageCode 语言代码。用于检查受支持语言代码并与本地化数据匹配。 String / / yes
mapData 用于本地化的键值对数据集合。 Map<String, dynamic> / / yes
countryCode 区域子标签(Locale)的国家代码。 String? / / yes
fontFamily 该语言对应的字体族名称。 String? / / yes
scriptCode 区域设置(Locale)的脚本子标签代码。 String? / / yes
locale 通过当前MapLocale对象生成对应的Locale对象。 Locale / / yes

5. 遗留问题

6. 其他

7. 开源协议

本项目基于 The BSD-3-Clause (license),请自由地享受和参与开源。