我正在尝试使我的应用程序支持本地化。我希望我的应用程序可以使用2种语言:English
& Hindi
.所以我在我的pubspec.yaml
中添加了以下包:
flutter_localizations:
sdk: flutter
intl: ^0.17.0 # Add this line
然后我做了一个l10n.yaml
文件,并添加了以下内容:
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
我还创建了如下app_en.arb
文件:
{
"helloWorld": "Hello World!",
"@helloWorld": {
"description": "The conventional newborn programmer greeting"
}
}
当我运行这段代码时,它给我一个错误:
Generating synthetic localizations package failed with 1 error:
Exception: The 'template-arb-file', LocalFile: 'C:\Users\Crosslynx25\Desktop\SW_Mobile_Platform\lib/l10n\app_en.arb', is not readable.
Please ensure that the user has read permissions.
main.dart
文件
import 'package:ble_app_flutter/screens/home_screen.dart';
import 'package:ble_app_flutter/screens/otp_screen.dart';
import 'package:ble_app_flutter/screens/splash_screen.dart';
import 'package:ble_app_flutter/utils/colors.dart';
import 'package:ble_app_flutter/l10n/L10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:lottie/lottie.dart';
import 'country_codes.dart'
as CountryCodes;
import 'screens/driver/driver_home_screen.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
State < MyApp > createState() => _MyAppState();
}
Map < int, Color > myTheme = {
50: Color.fromRGBO(9, 65, 155, .1),
100: Color.fromRGBO(9, 65, 155, .2),
};
class _MyAppState extends State < MyApp > {
// This widget is the root of your application.
MaterialColor myColor = MaterialColor(0xFF09419b, myTheme);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'BLE App gkhglkjhkl',
debugShowCheckedModeBanner: false,
supportedLocales: L10n.all,
// localizationsDelegates: [
// AppLocalizations.delegate, // Add this line
// GlobalMaterialLocalizations.delegate,
// GlobalWidgetsLocalizations.delegate,
// GlobalCupertinoLocalizations.delegate,
// ],
theme: ThemeData(
primarySwatch: myColor,
),
home: new Login(),
);
}
}
class Login extends StatefulWidget {
@override
State < Login > createState() => _LoginState();
}
class _LoginState extends State < Login > {
// const Login({
var selectedCountry = "91";
var phoneNumber = "";
@override
Widget build(BuildContext context) {
.
. //some code
.
}
}
6条答案
按热度按时间d5vmydt91#
此处显示错误
你是在Windows上,所以你应该使用
\
,而不是/
。就可以了。
nxagd54h2#
This happened with me, then I discovered that the file is actually
app_en.arb
(with a space before the name). This caused it not to be found.You can test it by copying the written path in the log, and see if Windows can find the file.
An issue has been created for the misleading message in here .
col17t5w3#
我遇到了同样的问题,因为我复制了一个yaml文件来创建“app_en.arb”文件。我想这个问题发生在我重命名它的时候,然后扩展名.yaml没有显示。我看到的是“app_en.arb”,但实际上它是“app_en.arb.yaml”...希望这能帮助你们中的一些人。
6tqwzwtp4#
我不知道为什么从pub.dev(app_en.arb)复制后会出现这种情况,但如果您开始重构--〉重命名,您可以看到文件格式Look at the empty space后有一个空格
enter image description here
cpjpxq1n5#
我删除了l10n.yaml文件,然后运行了命令“flutter gen-l10 n”,它修复了我的问题。它在.dart_tool中生成了flutter_gen文件夹。然后,一旦创建了文件夹,就重新创建l10n.yaml文件并执行命令flutter gen-l10 n,通常它修复了问题
ar7v8xwq6#
在我的例子中,在我用Flutter Intl而不是用app_en.arb文件的raw l10n实现本地化之后,发生了这种情况。因此,在我删除app_en. arb之后,我有了intl_en.arb而不是app_en. arb。
解决方案是从项目文件夹中删除l10n.yaml文件,如果你不需要再使用app_en.arb文件。Flutter Intl无疑更用户友好,更容易实现。