解决使用flutter_intl出现警告No @@locale or _locale field found in intl_en

简介: 解决使用flutter_intl出现警告No @@locale or _locale field found in intl_en

Flutter中使用flutter_intl插件做国际化时,每次修改arb文件后,就会在Message窗口出现以下提示。对于强迫症患者非常难受,必须解决掉!

/Users/ado/Developer/develop_env/flutter_2.10.5/bin/flutter --no-color pub global run intl_utils:generate
INFO: No @@locale or _locale field found in intl_en, assuming 'en' based on the file name.
Process finished with exit code 0

解决方案

ARB介绍

首先我们需要了解arb文件是什么

ARB详细说明:https://github.com/google/app-resource-bundle

ARB全称Application Resource Bundle 是一种基于JSON的本地化格式文件。

根据Google的介绍,@@开头的字段属于Global attributes,必须加在arb文件json格式的最上面。

@@locale用于标记存储在当前arb文件中的字符串属于哪种语言环境。

添加@@locale

通过查看谷歌的说明,我们已经知道了只需要在Json的顶部加上一个字段即可。@@locale或者__locale都可以。推荐使用@@locale,更加符合标准。

值为对应的语言简称。因为我修改的是intl_en.arb文件,所以值为en。

如果是intl_zh.arb,那对应的值就是zh。

{
  "@@locale": "en",
  "appName": "Flutter App",
  ......
}

保存后等插件自动运行,提示就不会出现了。


相关文章
|
4月前
|
缓存 iOS开发
Flutter run出现No Provisioning Profile was found for your project‘s Bundle Identifier or your device
Flutter run出现No Provisioning Profile was found for your project‘s Bundle Identifier or your device
61 2
|
4月前
|
开发工具 Android开发
Flutter: Android SDK not found at this location,Android Studio not found at xxx
Flutter: Android SDK not found at this location,Android Studio not found at xxx
166 2
|
4月前
|
API
Flutter 解决Type ‘MouseCursor‘ not found.
Flutter 解决Type ‘MouseCursor‘ not found.
47 0
【错误记录】Flutter 使用 MediaQuery 适配全面屏报错 ( No MediaQuery widget ancestor found. )
【错误记录】Flutter 使用 MediaQuery 适配全面屏报错 ( No MediaQuery widget ancestor found. )
871 0
【错误记录】Flutter 使用 MediaQuery 适配全面屏报错 ( No MediaQuery widget ancestor found. )
【错误记录】Flutter 界面报错 ( No MediaQuery widget ancestor found. | Scaffold widgets require a MediaQuery )
【错误记录】Flutter 界面报错 ( No MediaQuery widget ancestor found. | Scaffold widgets require a MediaQuery )
398 0
【错误记录】Flutter 界面报错 ( No MediaQuery widget ancestor found. | Scaffold widgets require a MediaQuery )
|
Dart 开发工具
【错误记录】Flutter 构建报错 ( Error: Method not found: ‘CupertinoModalPopupRoute‘. | 下载最新 Flutter SDK 版本 )
【错误记录】Flutter 构建报错 ( Error: Method not found: ‘CupertinoModalPopupRoute‘. | 下载最新 Flutter SDK 版本 )
239 0
【错误记录】Flutter 构建报错 ( Error: Method not found: ‘CupertinoModalPopupRoute‘. | 下载最新 Flutter SDK 版本 )
|
API 开发工具 Android开发
【错误记录】Flutter / Android 报错 ( AAPT: error: attribute android:requestLegacyExternalStorage not found )
【错误记录】Flutter / Android 报错 ( AAPT: error: attribute android:requestLegacyExternalStorage not found )
721 0
【错误记录】Flutter / Android 报错 ( AAPT: error: attribute android:requestLegacyExternalStorage not found )
flutter No Material widget found.
flutter No Material widget found.
307 0
【错误记录】Flutter 组件报错 ( No Directionality widget found. | RichText widgets require a Directionality )
【错误记录】Flutter 组件报错 ( No Directionality widget found. | RichText widgets require a Directionality )
628 0
|
2月前
|
Android开发 iOS开发 容器
鸿蒙harmonyos next flutter混合开发之开发FFI plugin
鸿蒙harmonyos next flutter混合开发之开发FFI plugin