由于flutter_localizations
from SDK 的每个版本都依赖于intl 0.17.0
fstore 依赖于intl ^0.16.1
,因此禁止使用来自 SDK 的 flutter_localizations。
因此,由于 fstore 依赖于 SDK 中的任何 flutter_localizations,因此版本解析失败。pub get failed (1; 所以,因为 fstore 依赖于任何来自 sdk 的 flutter_localizations,版本解决失败。)
visual-studio dart flutter flutter-dependencies flutter-localizations
目前,在 AppLocalizations 上调出 Android Studio 快速修复菜单(Opt/Alt+Enter 键盘快捷键)并不建议导入生成的文件。
AppLocalizations 类位于.dart_tool/flutter_gen/gen_l10n/app_localizations.dart
,这也是一个 Git 忽略的目录。
结果我必须手动输入导入语句。其他 Flutter 类名称通常建议通过“快速修复”菜单导入相关文件。
我期待“快速修复”菜单建议导入生成的 AppLocalizations 文件。当我单击导入建议时,它应该将其与其他导入语句一起插入到文件顶部。
如何让导入建议出现在 AppLocalizations 的“快速修复”菜单中?我是否需要帮助 Dart 分析器“了解”目录中生成的文件.dart_tool
?我可以将生成的文件包含在我的“项目”中,同时仍然 Git 忽略它吗?我是否需要在我的 pubspec 文件中链接到它?
android-studio dart-analyzer flutter pubspec flutter-localizations
我们如何在 arb 文件中使用嵌套对象?如果存在嵌套对象,Flutter gen 将不起作用。
\nl10n.yaml
arb-dir: lib/l10n\ntemplate-arb-file: app_en.arb\noutput-localization-file: app_localizations.dart\noutput-class: AppLocalizations\nsynthetic-package: false\n
Run Code Online (Sandbox Code Playgroud)\npubspec.yaml
flutter:\n generate: true\n
Run Code Online (Sandbox Code Playgroud)\napp_en.arb
"clients": {\n "label": "Client",\n "title": {\n "add": "New Client",\n "details": "Client Details",\n "edit": "Edit Client",\n "manage": "Manage Clients"\n }\n },\n
Run Code Online (Sandbox Code Playgroud)\napp_bn.arb
"clients": {\n "label": "\xe0\xa6\x95\xe0\xa7\x8d\xe0\xa6\xb2\xe0\xa6\xbe\xe0\xa6\xaf\xe0\xa6\xbc\xe0\xa7\x87\xe0\xa6\xa8\xe0\xa7\x8d\xe0\xa6\x9f",\n "title": {\n "add": "\xe0\xa6\xa8\xe0\xa6\xa4\xe0\xa7\x81\xe0\xa6\xa8 \xe0\xa6\x95\xe0\xa7\x8d\xe0\xa6\xb2\xe0\xa6\xbe\xe0\xa6\xaf\xe0\xa6\xbc\xe0\xa7\x87\xe0\xa6\xa8\xe0\xa7\x8d\xe0\xa6\x9f",\n "details": "\xe0\xa6\x95\xe0\xa7\x8d\xe0\xa6\xb2\xe0\xa6\xbe\xe0\xa6\xaf\xe0\xa6\xbc\xe0\xa7\x87\xe0\xa6\xa8\xe0\xa7\x8d\xe0\xa6\x9f \xe0\xa6\xa1\xe0\xa6\xbf\xe0\xa6\x9f\xe0\xa7\x87\xe0\xa6\xb2\xe0\xa6\xb8",\n "edit": "\xe0\xa6\x8f\xe0\xa6\xa1\xe0\xa6\xbf\xe0\xa6\x9f \xe0\xa6\x95\xe0\xa7\x8d\xe0\xa6\xb2\xe0\xa6\xbe\xe0\xa6\xaf\xe0\xa6\xbc\xe0\xa7\x87\xe0\xa6\xa8\xe0\xa7\x8d\xe0\xa6\x9f",\n "manage": "\xe0\xa6\x95\xe0\xa7\x8d\xe0\xa6\xb2\xe0\xa6\xbe\xe0\xa6\xaf\xe0\xa6\xbc\xe0\xa7\x87\xe0\xa6\xa8\xe0\xa7\x8d\xe0\xa6\x9f \xe0\xa6\xaa\xe0\xa6\xb0\xe0\xa6\xbf\xe0\xa6\x9a\xe0\xa6\xbe\xe0\xa6\xb2\xe0\xa6\xa8\xe0\xa6\xbe"\n }\n },\n
Run Code Online (Sandbox Code Playgroud)\n如果我运行文件来生成翻译,flutter 会引发异常。
\n\n\n例外:“clients”的值不是字符串。
\n
找不到任何带有 arb 文件中嵌套对象的解决方案。我找到了一些使用 JSON 文件来做到这一点的方法。但我想使用 arb …
localization internationalization flutter flutter-localizations
我正在使用flutter_localizations
本地化我的应用程序。
自从更新到Flutter 3.7以来,我收到此错误:
ICU 语法错误:应为“标识符”,但找到了“}”。
这显然 =|(){}[]
This =|\(){}[] obviously
是我的.arb文件中的文本。
我知道花括号“{}”有特殊含义,应该转义,但我找不到正确转义它们的方法,有人设法这样做吗?
重现该问题的一种简单方法是按照此处添加本地化支持的步骤操作,然后编写包含字符“”的任何内容,而不是hello world{
字符串。
PS: Github 上有一个相关的问题尚未解决。请务必去那里检查更新!
void main() async {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => LanguageCubit(),
child: BlocBuilder<LanguageCubit, Locale>(builder: (context, lang) {
return MaterialApp(
locale: lang,
title: 'Localizations Sample App',
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''), // English, no country code
const Locale('es', ''), // Spanish, no country code
const Locale('tr', ''),
const Locale('it', ''),
],
home: Home(),
);
}),
);
} …
Run Code Online (Sandbox Code Playgroud) 我想本地化通知,并且我发现有相应的属性,例如 title_loc_key、body_loc_key
用于本地化 (I18N) 通知标题和正文的 FCM 字段不起作用。例如:
{
"android" : {
"priority" : "normal",
"notification" : {
"title_loc_key": "notify_title",
"body_loc_key": "notify_body"
}
}
}
Run Code Online (Sandbox Code Playgroud)
FCM 文档指出这些字段用于本地化“应用程序的字符串资源”中的文本,但 Flutter 没有 res/values/strings.xml 文件。我正在使用 flutter_localizations 库,并根据 Flutter 的国际化要求维护 res/values/strings_.arb 文件,但我无法告诉 firebase_messaging 使用这些资源。
谢谢
push-notification flutter firebase-cloud-messaging flutter-localizations
当我使用 GetX 状态管理时,Flutter 默认本地化不起作用。它向我显示一个错误,例如
Undefined name 'AppLocalizations'.
Try correcting the name to one that is defined, or defining the name.
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
localization flutter flutter-getx flutter-localizations applocalizations
我想创建一个 Flutter 应用程序,它将根据用户设备本地化支持不同的语言。
我想通过 Firebase 远程配置存储所有翻译文本。这样,远程更改将适用于所有用户,而无需更新应用程序。
现在,我的应用程序可以根据官方文档进行本地化。但这样所有文本都是硬编码的,因此用户必须更新应用程序才能获得新的文本更改。
我读过一篇关于创建自定义的文章LocalizationsDelegate
,也许这样我就可以从 Firebase 和运行时加载所有文本。
我还阅读了有关easy_localization包的信息,但不幸的是,它似乎仅支持开箱即用的硬编码文本。
在 Firebase 配置中实现动态本地化的最佳方法是什么?
我希望有一个例子
firebase flutter firebase-remote-config google-cloud-firestore flutter-localizations
我正在尝试使用 flutter_localizations 并且遵循了这个指南
当我在 vscode 上保存 pubspec.yaml 时,会运行 pub get 。
之后 vscode 找不到 app_localizations.dart 文件。
但是当我重新打开 vscode 时,这个错误消息就会消失。
有人和我一样有这样的问题吗?
谢谢。
我的项目中有两个 .arb 文件,一切正常,但今天我添加了两个字符串,并且在执行以下操作时收到此错误flutter pub get
:
Generating synthetic localizations package failed with 1 error:
Exception: The arb file C:\Users\KarolW\Documents\git\partyfinder-mobile\lib/l10n\app_en.arb has the following formatting issue:
FormatException: Unexpected character (at line 439, character 1)
}
Run Code Online (Sandbox Code Playgroud)
我尝试删除添加的字符串,尝试删除所有字符串,尝试执行此操作flutter clean
,但错误仍然存在,我不知道为什么。
我正在发布我的所有 .arb 文件,我在文件末尾添加了“from”和“to”:
{
"@@locale": "en",
"appName": "Partyfinder",
"@appName": {},
"pageLoginMessage": "Sign in",
"@pageLoginMessage": {},
"facebookPageLoginMessage": "Sign in with Facebook",
"@facebookPageLoginMessage": {},
"email": "Email",
"@email": {},
"password": "Password",
"@password": {},
"forgotPassword": "Forgot Password?",
"@forgotPassword": {},
"noAccountMessage": "Don't have an account?",
"@noAccountMessage": {}, …
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试在我的 Flutter 应用程序中实现本地化,但每当我尝试添加 的依赖项时flutter_localization
,我都会收到以下错误消息:
由于定时器依赖的SDK不存在(在Flutter SDK中
flutter_localization
找不到包),版本解析失败。flutter_localization
我还在 Android Studio 中正确添加了 flutter 和 dart SDK 的路径。
这是我的pubspec.yaml
文件:
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: '>=2.18.2 <3.0.0'
dependencies:
flutter:
sdk: flutter
intl: ^0.17.0-nullsafety.2
cupertino_icons: ^1.0.2
sqflite: any
shared_preferences: ^2.0.15
path_provider: any
flutter_localization:
sdk: flutter
flutter_cupertino_localizations: ^1.0.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
uses-material-design: true
Run Code Online (Sandbox Code Playgroud)
如果没有 flutter_localization,我无法访问 GlobalMaterialLocalizations,显然,这是最简单的解决方案。我已经尝试过许多解决方案,例如检查版本兼容性和更新所有依赖项。你们能帮我吗?
提前致谢!
升级SDK、升级依赖、重新安装flutter和Dart等
在主方法中设置所有.json
文件、文件和初始化后,当我尝试通过调用从终端pubspec
创建文件时codegen_loader.g.dart
flutter pub run easy_localization:generate
时,它无法通过。甚至没有收到错误消息。
下面是命令行的片段:
PS C:\Users\Prosanto\Desktop\Android Dev\localization> flutter pub run easy_localization:generate -h
PS C:\Users\Prosanto\Desktop\Android Dev\localization> flutter pub run easy_localization:generate -S "assets/translations" -O "lib/translations"
PS C:\Users\Prosanto\Desktop\Android Dev\localization>
Run Code Online (Sandbox Code Playgroud)
什么也没发生,任何帮助或建议都是非常有帮助的。
flutter ×12
dart ×6
localization ×3
android ×1
dependencies ×1
firebase ×1
flutter-bloc ×1
flutter-getx ×1
pubspec ×1