Skip to content

Commit

Permalink
Doc improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcglasberg committed Dec 16, 2024
1 parent 66363e6 commit a361dc5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/i18n_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<I18nLoader Function()> 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<I18nLoader Function()> loaders = [
() => I18nJsonLoader(),
() => I18nPoLoader(),
];
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
homepage: https://github.com/marcglasberg/i18n_extension
topics:
Expand Down

0 comments on commit a361dc5

Please sign in to comment.