Skip to content

Commit

Permalink
Refactor to list
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Oct 22, 2024
1 parent 6c3481a commit c45055c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
20 changes: 8 additions & 12 deletions pkgs/messages_builder/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,12 @@ class MessageCallingCodeGenerator {
final resourcesInContext = assetList
.where((resource) => resource.message.context == messageList.context);

final localeToResourceInfo =
Map.fromEntries(resourcesInContext.map((resource) => MapEntry(
resource.message.locale ?? 'en_US',
(
id: 'package:${options.packageName}/${resource.path}',
hasch: resource.message.hash,
),
))
..sortedBy((element) => element.key));
final localeToResourceInfo = resourcesInContext.map((resource) => (
locale: resource.message.locale ?? 'en_US',
id: 'package:${options.packageName}/${resource.path}',
hasch: resource.message.hash,
))
..sortedBy((entry) => entry.locale);

printIncludeFilesNotification(messageList.context, localeToResourceInfo);
return LibraryGeneration(
Expand Down Expand Up @@ -148,14 +145,13 @@ class MessageCallingCodeGenerator {
/// in their assets.
void printIncludeFilesNotification(
String? context,
Map<String, ({String hasch, String id})> localeToResource,
Iterable<({String hasch, String id, String locale})> localeToResource,
) {
var contextMessage = 'The';
if (context != null) {
contextMessage = 'For the messages in $context, the';
}
final fileList =
localeToResource.entries.map((e) => '\t${e.value.id}').join('\n');
final fileList = localeToResource.map((e) => '\t${e.id}').join('\n');
print(
'''$contextMessage following files need to be declared in your assets:\n$fileList''');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import '../generation_options.dart';

class FieldGeneration {
final GenerationOptions options;
final Map<String, ({String id, String hasch})> localeToResourceInfo;
final Iterable<({String hasch, String id, String locale})>
localeToResourceInfo;
final String locale;

FieldGeneration(
Expand Down Expand Up @@ -42,8 +43,8 @@ class FieldGeneration {
);
final dataFiles = Field(
(fb) {
final paths = localeToResourceInfo.entries
.map((e) => "'${e.key}' : ('${e.value.id}', '${e.value.hasch}')")
final paths = localeToResourceInfo
.map((e) => "'${e.locale}' : ('${e.id}', '${e.hasch}')")
.join(',');
fb
..name = '_dataFiles'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class LibraryGeneration {
final String? context;
final String locale;
final List<MessageWithMetadata> messages;
final Map<String, ({String id, String hasch})> localeToResourceInfo;
final Iterable<({String hasch, String id, String locale})>
localeToResourceInfo;

LibraryGeneration(
this.options,
Expand Down

0 comments on commit c45055c

Please sign in to comment.