8

I am trying to make my app support localization. I want my app to work in 2 languages: English & Hindi. So i added the following package in my pubspec.yaml:

flutter_localizations:
    sdk: flutter
  intl: ^0.17.0 # Add this line

Then i made a l10n.yaml file and added this:

arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart

I also made the app_en.arb file like this:

{
    "helloWorld": "Hello World!",
    "@helloWorld": {
      "description": "The conventional newborn programmer greeting"
    }
}

When i am running this code, it gives me an error:

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 file

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
    .
  }
}

4
  • please post your main.dart file where you have configured localization Commented Apr 22, 2022 at 6:09
  • @Dev Added main.dart file, please check. Commented Apr 22, 2022 at 6:29
  • what is the location of l10n.yaml base dir or inside lib? It should be base dir. Commented Apr 22, 2022 at 6:44
  • I could not fix that issue using flutter v2.10.5. this issue still remained after an update to v3.0.0. however: i was at the beginning of my project. so i iremoved everything and created a new project. now it is working using v3.0.0. i don't know whether this in option for you. but i guess there was a bug/problem in flutter when creating the project intially in the older flutter-version, which was now fixed in v3.0.0. Commented May 14, 2022 at 13:46

10 Answers 10

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

I got the same issue because I copied a yaml file to create the "app_en.arb" file. I think the issue happened when I renamed it and then the extension .yaml wasn't display. I was seeing "app_en.arb" but in reality it was "app_en.arb.yaml"... Hope this will help some of you.

Comments

1

I deleted the file l10n.yaml then I ran the command "flutter gen-l10n" that fixed my problem. it generated a flutter_gen folder in the .dart_tool. then as soon as your folder is created, re-create the file l10n.yaml and execute the command flutter gen-l10n normally it fixes the problem

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
1

use this command flutter pub global run intl_utils:generate instead of f̶l̶u̶t̶t̶e̶r̶ ̶g̶e̶n̶-̶l̶1̶0̶n

Comments

1

Removing the .dart_tool-folder did the trick for me.

Comments

0

The error is showing here

C:\Users\Crosslynx25\Desktop\SW_Mobile_Platform\lib/l10n\app_en.arb

You are on Windows so you should use \ and not / in path. So I think modifying your l10n.yaml like this

arb-dir: lib\l10n

will do the trick.

2 Comments

Does not fix the issue for me. Did you test this fix? Did it work on your system using your fix-description? I get ...\lib%5Csrc%5Clocalization'', does not exist. And even if it would work, it would only be a workaound because you probably want to be able to work together, no matter if the developer use Windows or Linux.
Hi, did you find solution for this?
0

I don't know why this caused after copy from pub.dev (app_en.arb ) but if you start to refactor --> rename, you can see your file has one empty space after the file format Look at the empty space

enter image description here

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

In my case, it happened after I implemented localization with Flutter Intl instead of raw l10n with app_en.arb file. So I had intl_en.arb instead of app_en.arb after I removed app_en.arb.

Solution is to remove l10n.yaml file from project folder if you do not need to use app_en.arb file any more. Flutter Intl is definitly more user friendly and easy to implement.

Comments

0

I just got the same issue and i checked the official site and writing just "flutter run" and i try and it's solved. Files is created.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

I was able to fix this error by running dart fix --apply

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.