Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cannot generate Applocalization.g.dart file from running "dart pub run build_runner build --delete-conflicting-outputs" command #33

Open
maazoly1 opened this issue Jan 22, 2025 · 5 comments

Comments

@maazoly1
Copy link

I want to use this package to dynamically parse translation key.
So i have followed Every step
I Got error when i try to install this package from vscode,
So then i copy and paste the name of package in pubspec.yaml

After I run this command "dart pub global activate l10n_mapper_generator" which was successfull.
Then I saw that app_localizations.g.dart file is not generated so I run this command
"dart pub run build_runner build --delete-conflicting-outputs"

So Here i got this error,
Deprecated. Use dart run instead.
[INFO] Generating build script completed, took 187ms
[WARNING] Invalidated precompiled build script due to missing asset graph.
[INFO] Precompiling build script... completed, took 815ms
[SEVERE] Conflicting outputs
Both source_gen:combining_builder and l10n_mapper_generator:l10n_mapper_builder may output lib/config/environment_config.g.dart. Potential outputs must be unique across all builders. See https://github.com/dart-lang/build/blob/master/docs/faq.md#why-do-builders-need-unique-outputs

So i have made a build.yaml file and add this lines of code

build.yaml

targets:
$default:
builders:
l10n_mapper_generator:l10n_mapper_builder:
enabled: true # enables or disables the builder
options:
l10n: true # optional default - true
locale: true # optional default - true
parseL10n: true # optional default - true
message: "Translation key not found!" # optional default - null

again i run flutter gen-l10n and after this i run this "dart pub run build_runner build --delete-conflicting-outputs" again with same error

This is my pubspec.yaml file all dependecies,
dependencies:
flutter:
sdk: flutter
provider:
http:
google_maps_flutter:
google_places_flutter:
intl:
flutter_flavor:
image_picker:
permission_handler:
mime:
geolocator:
location:
onesignal_flutter:
shared_preferences:
url_launcher:
isar:
version: *isar_version
hosted: https://pub.isar-community.dev/
isar_flutter_libs: # contains Isar Core
version: *isar_version
hosted: https://pub.isar-community.dev/
path_provider:
webview_flutter:
lottie:
open_file:
flutter_contacts:
git:
url: https://github.com/Tradewind-apps/flutter_contacts
ref: pb/fix-incompatible-java-version-target
carousel_slider:
pin_code_fields:
format:
flutter_localizations:
sdk: flutter
amplitude_flutter:
app_tracking_transparency:
gif:
flutter_dotenv:
flutter_speed_dial:
path:
appsflyer_sdk:

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^4.0.0
flutter_launcher_icons:
isar_generator:
version: *isar_version
hosted: https://pub.isar-community.dev/
build_runner: any
flutter_native_splash:
l10n_mapper_generator:

Please Help me i want to parse translation keys dynamically like context.parseL10n('signingUp') but i can't because its telling me
The method 'parseL10n' isn't defined for the type 'BuildContext'.
Try correcting the name to the name of an existing method, or defining a method named 'parseL10n'.dartundefined_method
Type: InvalidType

@kwado-tech
Copy link
Owner

Hey @maazoly1, are you able to run the example project in the package?
Try running this following the documentation and indicate if you encounter issues

@maazoly1
Copy link
Author

Hello Brother @kwado-tech thanks for reply!
Brother i have followed the documentation and whatever errors that iam getting i have define those errors on my issues, But i think it gets mixed with my other Issues as well so for i will put my First issues here.

Then I saw that app_localizations.g.dart file is not generated so I run this command
"dart pub run build_runner build --delete-conflicting-outputs"

So Here i got this error,
Deprecated. Use dart run instead.
[INFO] Generating build script completed, took 187ms
[WARNING] Invalidated precompiled build script due to missing asset graph.
[INFO] Precompiling build script... completed, took 815ms
[SEVERE] Conflicting outputs
Both source_gen:combining_builder and l10n_mapper_generator:l10n_mapper_builder may output lib/config/environment_config.g.dart. Potential outputs must be unique across all builders. See https://github.com/dart-lang/build/blob/master/docs/faq.md#why-do-builders-need-unique-outputs

@kwado-tech
Copy link
Owner

@maazoly1 the error you mentioned means theres a conflict generating multiple files.

You can create a simple reproducible example uploaded to github for me to take a look.

@maazoly1
Copy link
Author

maazoly1 commented Jan 28, 2025

Platform: Macbook M1 Air
MacOS Version: macOS Sequoia 15.1.1
Flutter Version: 3.27.1
Code Editor: VS Code

  1. First of all, Add the above dependencies and dev dependencies in pubspec.yaml and run this command in terminal
    flutter pub get

  2. Create folder l10n under lib folder and add these file in this folder
    app_ar.arb
    { "signInSignUp": "تسجيل الدخول / الاشتراك", "signIn": "تسجيل الدخول", }
    app_en.arb
    { "signInSignUp": "Sign in / Sign up", "email": "Email", }

  3. Create file l10n.yaml Add these lines of code,

arb-dir: lib/presentation/localization/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
  1. Run this command in terminal
    flutter gen-l10n

  2. then check in folder .dart_tool > flutter_gen > gen_l10n to find app_localization.g.dart file.
    If you dont find then run this command in terminal

flutter pub run build_runner build --delete-conflicting-outputs

After this iam getting this error
So Here i got this error, Deprecated. Use dart run instead. [INFO] Generating build script completed, took 187ms [WARNING] Invalidated precompiled build script due to missing asset graph. [INFO] Precompiling build script... completed, took 815ms [SEVERE] Conflicting outputs Both source_gen:combining_builder and l10n_mapper_generator:l10n_mapper_builder may output lib/config/environment_config.g.dart. Potential outputs must be unique across all builders. See https://github.com/dart-lang/build/blob/master/docs/faq.md#why-do-builders-need-unique-outputs

@kwado-tech
Copy link
Owner

kwado-tech commented Feb 1, 2025

Hey @maazoly1, l10n_mapper package does not support generation for synthetic package i.e when the file is generated in the .dart_tool directory.

We can change this to generate localization files in the same directory as translations by including the following in the l10n.yaml file

Add to existing l10n.yaml

synthetic-package: false
output-dir: lib/presentation/localization/gen_l10n

Contents of l10n.yaml

arb-dir: lib/presentation/localization/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
synthetic-package: false
output-dir: lib/presentation/localization/gen_l10n

This means all generated localization files will reside in gen_l10n instead.

Indicate if this resolves your issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants