-
Notifications
You must be signed in to change notification settings - Fork 191
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
intl: Migrate from package:flutter_gen
; include generated files
#1058
Conversation
4fc031a
to
cc0ceec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Looks good to me overall! Left some small comments.
lib/model/localizations.dart
Outdated
@@ -1,4 +1,4 @@ | |||
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; | |||
import '/generated/l10n/zulip_localizations.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use relative path like we do in the other files, or is it needed for other reasons?
tools/check
Outdated
@@ -241,6 +241,19 @@ should_run_build_runner() { | |||
return 1 | |||
} | |||
|
|||
run_l10n() { | |||
files_check lib/generated/l10n/'*'.dart \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: like
local schema_dir=test/model/schemas/
we can extract a local variable for the output path
ead0ef8
to
a3bccfd
Compare
Thanks for the review @PIG208! Pushed a new revision. CI is failing because Flutter upstream changed the generated header for localization files in flutter/flutter@dca37ad, resulting in following diff: diff --git a/lib/generated/l10n/zulip_localizations_ar.dart b/lib/generated/l10n/zulip_localizations_ar.dart
index fedc8b74..b7c1ed6d 100644
--- a/lib/generated/l10n/zulip_localizations_ar.dart
+++ b/lib/generated/l10n/zulip_localizations_ar.dart
@@ -1,5 +1,5 @@
+// ignore: unused_import
import 'package:intl/intl.dart' as intl;
-
import 'zulip_localizations.dart';
// ignore_for_file: type=lint
…
… Added a head commit to update Flutter, and regenerated the files, that should fix the CI now. |
a3bccfd
to
6758fd5
Compare
LGTM! Tested on Android and it works for me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rajveermalviya for taking care of this! And thanks @PIG208 for the previous review (and @chrisbobbe for the review on the predecessor PR #1057).
Generally this all looks great; a few comments below. All nits except there's one logic error in the new tools/check l10n
suite.
.gitattributes
Outdated
# Generated file for localizations. | ||
lib/generated/l10n/*.dart -diff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: plural because it's several files
# Generated file for localizations. | |
lib/generated/l10n/*.dart -diff | |
# Generated files for localizations. | |
lib/generated/l10n/*.dart -diff |
@@ -54,12 +54,8 @@ changes to the ARB file. | |||
|
|||
### Using a translated string in the code | |||
|
|||
To use in our widgets, you need to import the generated bindings: | |||
``` | |||
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: the main migration commit should update this line, because otherwise the instruction is incorrect as of that commit
(then the later commit can delete, like in this revision, along with that nice commit message explaining why it used to be needed and no longer is)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
+import '/generated/l10n/zulip_localizations.dart';
If this nit were the only thing remaining in this revision I'd probably just go ahead and merge it, but since we have another round anyway: this (temporary) advice should match what we actually do in the source files 🙂, which follows #1058 (comment) .
tools/check
Outdated
@@ -241,6 +241,21 @@ should_run_build_runner() { | |||
return 1 | |||
} | |||
|
|||
run_l10n() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move this above should_run_build_runner
, which is a helper function specific to run_build_runner
, so as not to split those from each other
(alternatively, move this suite after the build_runner
suite)
tools/check
Outdated
local output_path=lib/generated/l10n | ||
|
||
files_check "${output_path}"/'*'.dart \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: pull the whole pathspec lib/generated/l10n/'*'.dart
out as a local variable
That way there's a natural place for a comment clarifying that this string is meant as a Git pathspec. Otherwise it looks an awful lot like a shell glob (which it would be if the *
weren't escaped with those single quotes), which would have somewhat different semantics. See run_pigeon
for an example (though that example also makes it an array, which isn't needed here since there's just one pathspec).
tools/check
Outdated
local output_path=lib/generated/l10n | ||
|
||
files_check "${output_path}"/'*'.dart \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check is too narrow and will miss some cases where this suite should run.
For examples, look back at the other files_check
call sites.
This should also include an "Omitted from this check" comment like the ones at those other call sites, listing all the other files in the repo that would belong in a 100% version of this check (because changes to them could affect whether this suite passes) but which we're choosing to leave out as described at the files_check
doc comment. I put those there partly as a way of making sure I explicitly thought through what files could matter to each check, to try to avoid this class of bug 🙂
6758fd5
to
b04510c
Compare
This pulls in: flutter/flutter@dca37ad which slightly changed the generated header for localization files.
b04510c
to
f21a59c
Compare
Thanks for the review @gnprice. Pushed a new revision, PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the revision! Comments below.
tools/check
Outdated
# Omitted from this check: | ||
# pubspec.{yaml,lock} tools/check | ||
files_check assets/l10n/ "${output_files}" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about l10n.yaml
?
tools/check
Outdated
@@ -277,6 +277,23 @@ run_build_runner() { | |||
check_no_changes "updates to *.g.dart files" '*.g.dart' | |||
} | |||
|
|||
run_l10n() { | |||
local output_files=lib/generated/l10n/zulip_localizations'*'.dart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't love calling this "files" — it makes it sound like it's an actual path (or list of actual paths) to some files. As mentioned at #1058 (comment) , I'd like to make explicit that this is instead a Git pathspec.
This would do it:
local output_files=lib/generated/l10n/zulip_localizations'*'.dart | |
local output_pathspec=lib/generated/l10n/zulip_localizations'*'.dart |
@@ -54,12 +54,8 @@ changes to the ARB file. | |||
|
|||
### Using a translated string in the code | |||
|
|||
To use in our widgets, you need to import the generated bindings: | |||
``` | |||
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
+import '/generated/l10n/zulip_localizations.dart';
If this nit were the only thing remaining in this revision I'd probably just go ahead and merge it, but since we have another round anyway: this (temporary) advice should match what we actually do in the source files 🙂, which follows #1058 (comment) .
`flutter` tool deprecated the `package:flutter_gen` synthetic package: https://flutter.dev/to/flutter-gen-deprecation The generated localization source files are now included in the repository and referenced directly. Without this change, `flutter run` generates the following warning: Synthetic package output (package:flutter_gen) is deprecated: https://flutter.dev/to/flutter-gen-deprecation. In a future release, synthetic-package will default to `false` and will later be removed entirely.
Previously with `package:flutter_gen`, a manual import of the bindings file was required because editor/IDE plugins didn't automatically suggest imports for the `ZulipLocalizations` class. See: https://github.com/dart-lang/linter/issues/ 3308 https://github.com/Dart-Code/Dart-Code/issues/ 3948 https://github.com/flutter/flutter-intellij/issues/ 4869 Now that the generated files are located in `lib/generated/l10n`, IDE plugins provide auto-import suggestions, making the manual import instruction unnecessary.
This package is no longer used.
f21a59c
to
d03ec1e
Compare
Thanks for the review @gnprice! Pushed a new revision, PTAL. |
Thanks! Looks good; merging. |
Hmmm, the commits I merged earlier today looked like this: Spot the error 🙂 Nothing else has been merged since then, and it looks like there aren't even any PRs that have been updated since this was merged. So I think it's not too late to fix it; I'll go and do so. |
OK, done. Now the corresponding commits in main are: (If it were just the broken links themselves, I'd leave them there; the reader who wants to follow them always could, just with a small amount of annoyance. But the big capital-letters "TODO" right in the summary line would have kept bugging me into the future when looking at the history. 🙂) |
flutter
tool deprecated thepackage:flutter_gen
synthetic package:https://flutter.dev/to/flutter-gen-deprecation
The generated localization source files are now included in the
repository and referenced directly.
Without this change,
flutter run
generates the following warning: