From a361dc5b0eeb45ce135a2a2965b059c2c095e97c Mon Sep 17 00:00:00 2001 From: Marcelo Glasberg <13332110+marcglasberg@users.noreply.github.com> Date: Sun, 15 Dec 2024 23:37:31 -0300 Subject: [PATCH] Doc improvements. --- CHANGELOG.md | 2 +- README.md | 21 ++++++++++++--------- lib/src/i18n_widget.dart | 6 +++--- pubspec.yaml | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 818ba13..2831e8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ Sponsored by [MyText.ai](https://mytext.ai) [![](./example/SponsoredByMyTextAi.png)](https://mytext.ai) -## 14.0.0 +## 14.0.1 Version 14 brings important improvements, like new interpolation methods, useful extensions, and improved standardization, with the cost of a few breaking changes that diff --git a/README.md b/README.md index df44b4c..5e313c4 100644 --- a/README.md +++ b/README.md @@ -1380,7 +1380,7 @@ The only important difference is that you must use `DefaultLocale.set()` instead of `I18n.of(context).locale = ...` to set the locale. And you won’t have access and won’t need to use the `i18n` widget, obviously. -# Reading translations from files +# Load translations from files If you want to load translations from `.json` files in your assets directory, create a folder and add some translation files like this: @@ -1507,15 +1507,18 @@ The following formats may be used with translations: * YAML: Can be used, however it lacks specific features for translation, like plurals and gender. -Currently, only `.PO` and `.JSON` loaders are supported out-of-the-box by this package. -If you need to load from any other custom format, remember loading is easy to do -because the Translation constructors use maps as input. If you can generate a map from -your file format, you can then use the `Translation.byLocale()` constructor to create the -translation objects. If you want to help creating importers for any of the other formats -above, we accept PRs. +Currently, only `.PO` and `.JSON` loaders are supported out-of-the-box, but if you need +to load from any other custom format, remember loading translations is easy to do because +the Translation constructors use maps as input. If you can generate a map from your file +format, you can then use the `Translation.byLocale()` constructor to create the +translation objects. -Your custom "loaders" should extend class `I18nLoader`. To see an example, check how -class `I18nJsonLoader` is implemented to load `.json` files: +If you want to create custom loaders that are used automatically when you call +`Translations.byFile()`, you can do that by extending the `I18nLoader` class, and then +adding your custom loader to the static `I18n.loaders` list. + +To see an example on how to create a loader, this is how `I18nJsonLoader` is implemented +to load `.json` files: ```dart class I18nJsonLoader extends I18nLoader { diff --git a/lib/src/i18n_widget.dart b/lib/src/i18n_widget.dart index 08713ff..d0f988d 100644 --- a/lib/src/i18n_widget.dart +++ b/lib/src/i18n_widget.dart @@ -413,9 +413,9 @@ class I18n extends StatefulWidget { /// Returns a list of loaders to be used by the i18n_extension. /// By default, it loads from JSON (.json) and PO (.po) files. - /// This list may be changed statically, to add or remove loaders. - /// You may create your own loaders by extending [I18nLoader]. - static List loaders = [ + /// This list may be changed statically, to add or remove loaders, + /// and you may create your own loaders by extending [I18nLoader]. + static final List loaders = [ () => I18nJsonLoader(), () => I18nPoLoader(), ]; diff --git a/pubspec.yaml b/pubspec.yaml index 9edcb0b..d101bb8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: i18n_extension description: Translation and Internationalization (i18n) for Flutter. Easy to use for both large and small projects. Uses Dart extensions to reduce boilerplate. -version: 14.0.0 +version: 14.0.1 # author: Marcelo Glasberg homepage: https://github.com/marcglasberg/i18n_extension topics: