Skip to content

Commit

Permalink
Also output code in dart run
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Oct 22, 2024
1 parent 7b0865c commit 2dd1e25
Show file tree
Hide file tree
Showing 31 changed files with 209 additions and 147 deletions.
31 changes: 25 additions & 6 deletions pkgs/messages/bin/messages.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import 'dart:io';

import 'package:messages_builder/builder.dart';
import 'package:messages_builder/generation_options.dart';
import 'package:messages_builder/message_data_builder.dart';

Future<void> main(List<String> args) async {
await MessagesDataBuilder().run(
inputFolder: Directory.fromUri(
Directory.current.uri.resolve('assets/').resolve('l10n/')),
outputFolder: Directory.fromUri(Directory.current.uri.resolve('assets/')),
libOutput: 'lib/messages.g.dart',
);
final generationOptions = await _generationOptions();
final inputFolder = Directory.fromUri(
Directory.current.uri.resolve('assets/').resolve('l10n/'));
final outputFolder =
Directory.fromUri(Directory.current.uri.resolve('assets/'));

final mapping = await MessageDataFileBuilder(
inputFolder: inputFolder,
outputFolder: outputFolder,
generationOptions: generationOptions,
).run();

await MessageCallingCodeGenerator(
mapping: mapping,
options: generationOptions,
).build();
}

Future<GenerationOptions> _generationOptions() async {
final pubspecUri = Directory.current.uri.resolve('pubspec.yaml');
final file = File.fromUri(pubspecUri);
final pubspecContents = await file.readAsString();
return await GenerationOptions.fromPubspec(pubspecContents);
}
2 changes: 1 addition & 1 deletion pkgs/messages/example/assets/l10n/testarb.arb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
}
},
"helloAndWelcome2": "Welcome {firstName} von {lastName}!"
}
}
2 changes: 1 addition & 1 deletion pkgs/messages/example/assets/l10n/testarb_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"helloAndWelcome2": "Willkommen {firstName} von {lastName} 2",
"newMessages": "testde {newMessages, plural, =0 {No new messages} =1 {One new message} two{Two new Messages} other {test {newMessages} new messages}}",
"newMessages2": "testdse is just a simple message"
}
}
2 changes: 1 addition & 1 deletion pkgs/messages/example/assets/l10n/testarbctx2.arb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
}
}
}
}
}
3 changes: 2 additions & 1 deletion pkgs/messages/example/assets/l10n/testarbctx2_fr.arb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"@@context": "AboutPage",
"@@locale": "fr",
"helloAndWelcome": "Welcome {firstName} von {lastName} <",
"otherMsg": "other",
"aboutMessage": "Sur {websitename}",
"newMessages": "test {newMessages, plural, =0 {No new messages} =1 {One new message} two{Two new Messages} other {test {newMessages} new messages}}",
"newMessages2": "test {gender, select,male {No new messages} female {One new message} other{Two new Messages} other {test {gender} new messages of type {newVar}}}"
}
}
1 change: 1 addition & 0 deletions pkgs/messages/example/assets/testarb.arb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0,"en","dr9Md951",1,null,["helloAndWelcome","Welcome von !",[8,0],[13,1]],["helloAndWelcome2","Welcome von !",[8,0],[13,1]],[6,"newMessages","test ",[3,0,["test new messages",[5,0]],[0,"No new messages",1,"One new message","w2","Two new Messages"]]],[6,"newMessages2","test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]]]
1 change: 0 additions & 1 deletion pkgs/messages/example/assets/testarb.json

This file was deleted.

1 change: 1 addition & 0 deletions pkgs/messages/example/assets/testarb_de.arb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0,"de","hbDN1MhX",1,null,["helloAndWelcome","Willkommen von ",[11,0],[16,1]],["helloAndWelcome2","Willkommen von 2",[11,0],[16,1]],[6,"newMessages","testde ",[3,0,["test new messages",[5,0]],[0,"No new messages",1,"One new message","w2","Two new Messages"]]],["newMessages2","testdse is just a simple message"]]
1 change: 0 additions & 1 deletion pkgs/messages/example/assets/testarb_de.json

This file was deleted.

1 change: 1 addition & 0 deletions pkgs/messages/example/assets/testarbctx2.arb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0,"en","QrwRSsOy",1,null,["aboutMessage","About ",[6,0]],["helloAndWelcome","Welcome von <",[8,0],[13,1]],[6,"newMessages","test ",[3,0,["test new messages",[5,0]],[0,"No new messages",1,"One new message","w2","Two new Messages"]]],[6,"newMessages2","test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]],["otherMsg","other"]]
1 change: 0 additions & 1 deletion pkgs/messages/example/assets/testarbctx2.json

This file was deleted.

1 change: 1 addition & 0 deletions pkgs/messages/example/assets/testarbctx2_fr.arb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0,"fr","390XWry3",1,null,["aboutMessage","Sur ",[4,0]],["helloAndWelcome","Welcome von <",[8,0],[13,1]],[6,"newMessages","test ",[3,0,["test new messages",[5,0]],[0,"No new messages",1,"One new message","w2","Two new Messages"]]],[6,"newMessages2","test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]],["otherMsg","other"]]
1 change: 0 additions & 1 deletion pkgs/messages/example/assets/testarbctx2_fr.json

This file was deleted.

Empty file.
22 changes: 18 additions & 4 deletions pkgs/messages/example/lib/messages.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions pkgs/messages/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ dev_dependencies:

package_options:
messages_builder:
generateMethods: true
generateFindById: false
generateFindBy: integer
pluralSelector: intl
generate_methods: true
generate_find_by_id: true
generate_find_by: integer
plural_selector: intl
arb_input_folder: assets/l10n/
message_output_folder: assets/
generated_code_file: lib/messages.g.dart
Empty file.
11 changes: 7 additions & 4 deletions pkgs/messages/examples/my_application/lib/my_application.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:io';

import 'package:my_shopping_cart/my_shopping_cart.dart';

import 'messages.g.dart';
import 'src/messages.g.dart';

Future<String> items() async {
var myShoppingCart = MyShoppingCart();
Expand All @@ -9,9 +11,10 @@ Future<String> items() async {
}

Future<String> sale() async {
var myShoppingCart = MyAppMessages();
await myShoppingCart.loadAllLocales();
return myShoppingCart.current_sale_name(
var appMessages = MyAppMessages(
(id) => File(id.substring(id.indexOf('/') + 1)).readAsString());
await appMessages.loadAllLocales();
return appMessages.current_sale_name(
DateTime.now().month < 4 || DateTime.now().month > 10 ? 'winter' : 'summer',
);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'dart:io';

import 'messages.g.dart';

class MyShoppingCart {
final _messages = ShoppingCartMessages();
final _messages = ShoppingCartMessages(
(id) => File(id.substring(id.indexOf('/') + 1)).readAsString());
Future<void> loadMessages() async => await _messages.loadAllLocales();

String itemsInCart(int number) => _messages.itemsInCart(number);
Expand Down
6 changes: 6 additions & 0 deletions pkgs/messages/examples/my_shopping_cart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ dependencies:
dev_dependencies:
lints: ^4.0.0
test: ^1.24.0

package_options:
messages_builder:
arb_input_folder: assets/l10n/
message_output_folder: assets/
generated_code_file: lib/src/messages.g.dart
Loading

0 comments on commit 2dd1e25

Please sign in to comment.