diff --git a/pkgs/messages/CHANGELOG.md b/pkgs/messages/CHANGELOG.md index a0712a79..822f95b0 100644 --- a/pkgs/messages/CHANGELOG.md +++ b/pkgs/messages/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.1 + +- Update README. + ## 0.1.0 - Initial version. diff --git a/pkgs/messages/README.md b/pkgs/messages/README.md index 331eb44d..60688da0 100644 --- a/pkgs/messages/README.md +++ b/pkgs/messages/README.md @@ -34,9 +34,15 @@ The `builder` to generate the named methods and data files from the input `arb` The logic for serializing `arb` message files into data files. ## Example +Add `package:messages` and `package:messages_builder` to your dependencies: +```bash +dart pub add messages +dart pub add dev:messages_builder +``` -Given translation message files such as these `.arb`s: - +Given translation message files in two languages: +`en.arb` +This reference file is written by the developer. ```json { "@@locale":"en", @@ -51,7 +57,8 @@ Given translation message files such as these `.arb`s: } } ``` - +and `fr.arb` +This translated file was created by a translator given the reference `en.arb`. ```json { "@@locale":"fr", @@ -59,13 +66,16 @@ Given translation message files such as these `.arb`s: "aboutMessage": "À propos de {website}", } ``` +you can then run -insert the message in your Dart application through +`dart run build_runner build -d` + +This will generate both code to call your messages, as well as data files which will be shipped with your application. You can then use these generated files by importing the generated files: ```dart import 'dart:io'; -import 'package:example/aboutpage_arb_file.g.dart'; +import 'package:example/aboutpage_arb_file.g.dart'; // <-- This was generated right now import 'package:messages/messages_native.dart'; import 'package:messages/package_intl_object.dart'; @@ -79,4 +89,20 @@ void main() { aboutPageMessages.loadLocale('en'); print(aboutPageMessages.aboutMessage(website: 'mywebsite.com')); // 'About mywebsite.com' } +``` + +Optionally, add options to your `pubspec.yaml` by specifying any of these keys: +```yaml +package_options: + messages_builder: + generateMethods: true # whether to generate named methods + generateFindById: false # whether to allow messages to be retrieved by ID + generateFindBy: integer # {none, integer, enumerate}, the type of key to use + header: | # the custom header message. Will always be prefixed by // in the generated code. + Generated by flutter_messages. + + // Some custom + // multi + // line + // header ``` \ No newline at end of file diff --git a/pkgs/messages/pubspec.yaml b/pkgs/messages/pubspec.yaml index 77001970..7ccaf862 100644 --- a/pkgs/messages/pubspec.yaml +++ b/pkgs/messages/pubspec.yaml @@ -1,6 +1,6 @@ name: messages description: A lightweight modular library for localization (l10n) functionality. -version: 0.1.0 +version: 0.1.1 repository: https://github.com/dart-lang/i18n/tree/main/pkgs/messages environment: diff --git a/pkgs/messages_builder/CHANGELOG.md b/pkgs/messages_builder/CHANGELOG.md index a0712a79..9ee6d8df 100644 --- a/pkgs/messages_builder/CHANGELOG.md +++ b/pkgs/messages_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.1 + +- Add `header` to `GenerationOptions`. + ## 0.1.0 - Initial version. diff --git a/pkgs/messages_builder/lib/code_generation/library_generation.dart b/pkgs/messages_builder/lib/code_generation/library_generation.dart index 12eacb97..4af39339 100644 --- a/pkgs/messages_builder/lib/code_generation/library_generation.dart +++ b/pkgs/messages_builder/lib/code_generation/library_generation.dart @@ -56,7 +56,7 @@ class LibraryGeneration extends Generation { return [ Library((b) => b - ..comments.add('Generated by package:messages_builder') + ..comments.add(options.header) ..directives.addAll(imports) ..body.addAll(classes)) ]; diff --git a/pkgs/messages_builder/lib/generation_options.dart b/pkgs/messages_builder/lib/generation_options.dart index c2128609..e9e2616b 100644 --- a/pkgs/messages_builder/lib/generation_options.dart +++ b/pkgs/messages_builder/lib/generation_options.dart @@ -36,12 +36,15 @@ class GenerationOptions { /// dart native code. final DeserializationType deserialization; + final String header; + GenerationOptions({ required this.serialization, required this.deserialization, required this.messageCalls, required this.findById, required this.indexType, + required this.header, }); static Future fromPubspec(BuildStep buildStep) async { @@ -60,6 +63,8 @@ class GenerationOptions { type.name == messagesOptions?['generateFindBy'] as String?) .firstOrNull ?? IndexType.integer, + header: messagesOptions?['header'] as String? ?? + 'Generated by package:messages_builder.', ); return generationOptions; } diff --git a/pkgs/messages_builder/pubspec.yaml b/pkgs/messages_builder/pubspec.yaml index 80518fcc..962f923e 100644 --- a/pkgs/messages_builder/pubspec.yaml +++ b/pkgs/messages_builder/pubspec.yaml @@ -1,6 +1,6 @@ name: messages_builder description: Build the messages for consumption by package:messages -version: 0.1.0 +version: 0.1.1 repository: https://github.com/dart-lang/i18n/pkgs/messages_builder environment: