pub repository
mirror.p-hatan.comflutter_i18n
0.5.2i18n made easy for Flutter. With flutter_i18n you can make your app international, using just a simple .json file!
Readme
flutter_i18n
I18n made easy, for Flutter!
Why you should use flutter_i18n?
The main goal of flutter_i18n is to simplify the i18n process in Flutter. I would like to recreate the same experience that you have with the Angular i18n: simple json files, one for each language that you want to support.
Configuration
To use this library, you must create a folder in your project's root: the basePath. Some examples:
/assets/flutter_i18n (the default one)
/assets/i18n
/assets/locales
Inside this folder, you'll put the json files containing the translated keys. You have two options:
-
If you want to specify the country code
basePath/{languageCode}_{countryCode}.json -
otherwise
basePath/{languageCode}.json
Of course, you must declare the subtree in your pubspec.yaml as assets:
flutter:
assets:
- {basePath}
The next step consist in the configuration of the localizationsDelegates; to use flutter_i18n, you should configure as follows:
localizationsDelegates: [
FlutterI18nDelegate(useCountryCode, [fallbackFile, basePath]),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
The useCountryCode parameter depends on the json configuration:
- if you used the pattern {languageCode}_{countryCode}, useCountryCode must be true
- if you used the pattern {languageCode}, useCountryCode must be false
The fallbackFile parameter was entroduces with the version 0.1.0 and provide a default language, used when the translation for the current running system is not provided. This should contain the name of a valid json file in assets folder.
The basePath parameter is optionally used to set the base path for translations. If this option is not set, the default path will be assets/flutter_i18n. This path must be the same path as the one defined in your pubspec.yaml.
If there isn't any translation available for the required key, the same key is returned.
flutter_i18n in action
After the configuration steps, the only thing to do is invoke the following method:
FlutterI18n.translate(buildContext, "your.key")
Where:
- buildContext is the BuildContext instance of the widget
- your.key is the key to translate
Other examples of use:
await FlutterI18n.refresh(buildContext, languageCode, {countryCode});
FlutterI18n.plural(buildContext, "your.key", pluralValue);
For more informations, read the CHANGELOG.md.
Changelog
[0.2.0]
flutter_i18n now manage strings that contain parameters; an example can be: "Hello, {user}!" For a correct translation, you must use the third parameter of the translate method, a Map<String, String> where:
- the keys are the placeholders used in the .json file (i.e. user)
- the values are what you want to display
[0.3.0]
flutter_i18n now supports language change at runtime. To use it, you must invoke the method
await FlutterI18n.refresh(buildContext, languageCode, {countryCode});
NOTE: countryCode is optional.
[0.4.0]
flutter_i18n now supports plurals. To use it, invoke the method:
FlutterI18n.plural(buildContext, "your.key", pluralValue);
Where pluralValue is the integer value that will be used to determinate the plural form of the translation.
Here is an example of configuration of the .json file:
"clicked": {
"times-0": "You clicked {times} times!",
"times-1": "You clicked {time} time!",
"times-2": "You clicked {times} times!"
}
With this configuration, you must invoke the plural method as follow:
FlutterI18n.plural(buildContext, "clicked.times", pluralValue);
FlutterI18n will choose the right key using the value of pluralValue: it will match the last key with a value <= of pluralValue.
[0.5.0]
flutter_i18n now supports the basePath configuration.
The default one is: assets/flutter_i18n.
To configure it, use the third optional parameter of FlutterI18nDelegate.
[0.5.1]
Print in log when a key is not found.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add flutter_i18npubspec.yaml
name: flutter_i18n
description: i18n made easy for Flutter. With flutter_i18n you can make your app international, using just a simple .json file!
version: 0.5.2
author: Matteo Pietro Dazzi <matteopietro.dazzi@gmail.com>
homepage: https://github.com/ilteoood/flutter_i18n
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
environment:
sdk: '>=1.19.0 <3.0.0'Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | 2018-08-26T21:04:01.985130Z | Download | bc62ed0c0f91a86e96cc6a15234bceef1f4bb3e0679c18355bbc2befca6b4262 |
| 0.0.2 | 2018-08-27T21:33:02.280068Z | Download | 53d2a591e69524257b5a0f1c1d654cbb10483fac084653fed61717816776baee |
| 0.0.3 | 2018-09-10T21:11:31.961228Z | Download | 4f262b0dcfadb17197dfeac13783d2b4d8bf1299a3cc080868b5418765c3d320 |
| 0.1.0 | 2018-09-21T19:16:57.681831Z | Download | c8a7e81b5c5f65c8ba90f09891b5d5cb02bfec437fa882a9a7f131aae580768b |
| 0.2.0 | 2018-09-23T14:14:30.542962Z | Download | 74c6b69cee950b04364ee8656e51483e26a23b93eed9f8b41b2ff2fa59045ed4 |
| 0.3.0 | 2018-10-29T20:48:00.709676Z | Download | 4eba6520eb9854985f0840d373f1c06cc4593566ec4fa9d9d51ed21bdef1c244 |
| 0.4.0 | 2018-11-03T14:10:38.525501Z | Download | 32557618f1d8ad93d69dbd16069ab7ce3d489298ab4226e44904a92815ba7775 |
| 0.5.0 | 2018-11-14T19:39:03.673200Z | Download | 2b118d2661ad2747e050b650e5272495e9117bf2e3a3e6cf70c6edb284b206e5 |
| 0.5.1 | 2018-12-17T20:08:16.235361Z | Download | 7cfdec9ffd014d0b5eaa16e8d1dd4391f0f35173afb863c3366bc14c944888b4 |
| 0.5.2 | 2019-01-07T20:26:07.209874Z | Download | e3fcf08125f97a91f28d66114c51bbcf6462072c750494ed254c9f35bd0ebfcc |
| 0.6.0 | 2019-03-05T21:47:52.259604Z | Download | 65c9167c0303b5d5f981c2875fbd189e70087795ce1ffa319c0fa6b173f84f62 |
| 0.6.1 | 2019-03-09T12:43:10.817899Z | Download | de342cf3c49b4d3c5c3563b990e3cb8b3e9590c38ec09db0e0ce0d38547fb15e |
| 0.6.2 | 2019-03-11T20:58:43.533934Z | Download | 620a8242ee5064c233de261963d2cbe8b9155181d40882c5d920b439d85d4929 |
| 0.6.3 | 2019-03-17T10:39:47.917692Z | Download | 95d2ec261e11f0f8378b1c4637d61db307fe36732e73624cf7e767f03ca2f65e |
| 0.6.4 | 2019-08-11T09:36:54.640786Z | Download | 9b0231b638d58411ba8ccaf1179a49af1415b379e65c8e6b9000f42e950f9de4 |
| 0.7.0 | 2019-09-30T19:59:44.413347Z | Download | 4e21b4d8e37caf16caf9d0ed39356b874f62b352db466b6a6343e7a2d8850d78 |
| 0.8.0 | 2019-10-26T18:16:49.864494Z | Download | 88a9bab0d755846e2b97115ac149abf9b0a6c5631a05937d28be3b74fa622bff |
| 0.8.1 | 2019-11-15T21:46:15.098385Z | Download | 61dc2387aeea13885a3429f11c5d88f410a59c8e9954044c768a554da69d4a4c |
| 0.8.2 | 2019-11-16T17:47:44.166275Z | Download | 4f1217f14e43d46c91409dce53712177f7afb4424ba7052f6a0d62f7d0a0305c |
| 0.8.3 | 2019-12-29T15:58:31.061423Z | Download | 411807a576669f6707c417935e731e5348e13f9eedfb6560b34dc232e1403fd6 |
| 0.9.0 | 2020-03-01T17:30:55.038990Z | Download | 84b7bb766128447374e524ed725a455193988855945bc2e99724c901376f1f2e |
| 0.10.0 | 2020-03-02T22:44:36.244631Z | Download | 79bb2c69e7dc2d4b1105b101557b68a256a1c6f9bedb8ba3bd8720bdc59b5f61 |
| 0.10.1 | 2020-03-06T18:55:36.352844Z | Download | f862efcd027d422da060f6bb85aee129d108e84e4c92e355bde58c5f1c113a8d |
| 0.11.0 | 2020-03-11T21:01:08.014565Z | Download | 575ab3688ee14f7704b83b697cd6ea22fe91a55dde7ecef8585f8db3f085f14d |
| 0.11.1 | 2020-03-12T19:15:20.076435Z | Download | 5ea048981cb55ba0eed017489f54e64d696406f9db34ca63d2f7894cd3f7e32e |
| 0.12.0 | 2020-03-16T13:32:17.272413Z | Download | 8b93a2858d70fe0a452652f893f7b9265084caade6fc6457e180ae9146d0bc7e |
| 0.13.0 | 2020-03-24T20:01:03.075417Z | Download | c6391b80ecc8286bd1a3fa8d308fa9db53d78c9365c5ed04028e246c5f6c927c |
| 0.13.1 | 2020-04-24T12:15:29.332125Z | Download | c48f9f5e96efbec443f17a9aff0f5967abb18d30c5f7838f8d8d45395d8b6bd5 |
| 0.13.2 | 2020-04-24T20:07:25.746303Z | Download | fb23273aa9e341aa9f70085791466f3ae2eeda0b1005364512d25199436f6aea |
| 0.14.0 | 2020-04-30T21:13:02.731418Z | Download | 8eda74b3265a33bcfd9a4d432acc4727f2a602bfeb6e677ddddd95878223c255 |
| 0.15.0 | 2020-05-09T07:26:16.927216Z | Download | 0b8452f6960d0c167b11e18d3bb1dedb4e126f44cccb94b49b8dbaafccb81b80 |
| 0.16.0 | 2020-06-02T16:15:42.681833Z | Download | 3821b4a29b43189fef0af337c67a56d9caf2602e360cd888c1d419609cd770cb |
| 0.16.1 | 2020-06-09T10:02:54.456251Z | Download | 92d94b691e4f5dab29aa939dd925aad1cdcfdfd9f50c5fb81e52663fa179e702 |
| 0.16.2 | 2020-06-10T20:22:43.008226Z | Download | a1578783187f227a2779f68eeb60833d45b0a20c259b16524a5904b67ae42e4d |
| 0.16.3 | 2020-07-13T12:01:33.990171Z | Download | 480a953bded3f7490d6ebe1d44acc853ba406a584e7c0030a692412f8217aeab |
| 0.17.0 | 2020-07-15T20:30:54.684133Z | Download | e087afc13af6cde948524c129f93d1c5875cf38d40033775eb6e7fce215858bc |
| 0.18.0 | 2020-07-16T19:42:31.250028Z | Download | d1659c8b5a61cd01b5ada821afcf4dbc7032799e386503993cc72d0c7a4d2f18 |
| 0.19.0 | 2020-08-10T19:35:23.270589Z | Download | fa476f0a9b209b03e7751850d1760ca5d648d87514e7858dbbcc90968279426c |
| 0.19.1 | 2020-08-18T20:49:33.901023Z | Download | f0a5815e272921d688032fddabe50091990c4d7efb2d4a20635955ec1fcac246 |
| 0.19.2 | 2020-09-12T14:45:15.540359Z | Download | 6ec2e77e93ed5947692f57eb2b8e3c6e93d72f37f0888d8c6bf7fbb829199745 |
| 0.19.3 | 2020-09-30T18:35:18.789660Z | Download | 548e327f8446a697e9a37a9e722d7894224528ceba882448e54d08fe7cb56326 |
| 0.19.4 | 2020-10-01T18:18:59.742503Z | Download | 9532ebbceaabc3407977fccd8c68b63e1387e782fbf218c9c89a0de7bb6e732e |
| 0.20.0 | 2020-10-12T09:32:56.185497Z | Download | ecef39ae7cb0789bf5a2f2ca1866b547a209b14df1449bc514ab85d614defb5b |
| 0.20.1 | 2020-10-24T16:51:39.378330Z | Download | 9b1507fd2d33e644d260c0cbbb1e323346040f55855603a13dadd7bf4ad995fa |
| 0.21.0-intl.nullsafety | 2021-01-03T17:06:40.866045Z | Download | 3baaed18086595be3f49603cf1450bace1fd6d369e240901409717d011dbd00a |
| 0.21.0 | 2021-02-04T20:39:15.270189Z | Download | 5322101af1f6873d5b64a59832e861f371e05ccb46d96d14fabf947e68054f68 |
| 0.21.1 | 2021-03-01T18:28:08.831602Z | Download | 139750e7c5535ee9e90331d4cd64138b767bbb26000e699d5106cf3a5351ea63 |
| 0.22.0 | 2021-03-04T14:22:13.601224Z | Download | 9f2455cc84cccb0462b8e63514ee22f1b22bebadcc1df9ee2592d30d53cabd5a |
| 0.22.1 | 2021-03-04T19:45:01.343111Z | Download | 0ff3150a2ff3fdd54bb5ec82fdfd880449243846bbe9a55c9f2edd3518420d8c |
| 0.22.2 | 2021-03-04T21:57:43.767274Z | Download | 4bf68422a53cea26ed015bcb13a1620fac5e861cd5cdd4cad9ab87950c75d59b |
| 0.22.3 | 2021-03-06T18:49:14.826855Z | Download | 94aed8693b37bf7f37a299d131c62d713b6ac516229d03f4afde4c8c3b20f07b |
| 0.22.4 | 2021-06-19T07:13:59.653739Z | Download | ae96d3f630390dc5590b6bafef373aff342f651da5d1d146b57ff858b833d5ad |
| 0.30.0 | 2021-08-14T11:01:21.377254Z | Download | 5f2203e50eff6523c689566cdd93422a1f2c862ebc6ae9ee46f27b4c8b1b5418 |
| 0.31.0 | 2021-11-25T09:39:38.064342Z | Download | 454d2c4e446a39eed80988358ea60e6053a19947e7ce274681412d484556810d |
| 0.31.1 | 2022-01-15T16:26:48.153911Z | Download | 3dc20ca94bf447ce2dbe365b914c9846e600e61fa4c96a08a1aa0f4f8a4ebcf8 |
| 0.32.0 | 2022-02-11T12:49:48.063881Z | Download | 3f498993ed0d185b04a573dbec52d6ecf0b420f878cf04b3ec2179c2a2ddc25b |
| 0.32.1 | 2022-03-13T12:30:55.997174Z | Download | d0dbf49b68316d0e5e902e0e15dd18863995a1c71af14ab7941983a9ea6bac44 |
| 0.32.2 | 2022-03-30T07:41:58.419889Z | Download | 3eeb3d57d9c5f7e3079e9d35ebce60416ce52e4738d0d9563aedf8e5a469725c |
| 0.32.3 | 2022-06-05T16:51:11.946632Z | Download | 143b397a1c58ef0fa5f37231136f1c5ed157142706eb38c44cbcac22ca58d269 |
| 0.32.4 | 2022-06-08T21:13:32.882435Z | Download | 5f453b2533939c20042902e0ecf12f0a6941e647f839b9add7a5f6c0a625af66 |
| 0.33.0 | 2023-05-11T06:47:40.838456Z | Download | b71fe887697686368c93e4d2257ecdb3c35fe38686a6fbf3902d6355c3f20363 |
| 0.34.0 | 2023-08-15T09:00:38.856101Z | Download | c7e9752c5dea38963bed26513c25a6e5db70c110fc2c68b84694aafa37b29636 |
| 0.35.0 | 2023-12-29T11:34:51.623582Z | Download | 091af6970be8036c37121b8a683bc392d0182786186ab8fe2cf20403aebdcfa6 |
| 0.35.1 | 2024-02-09T17:37:53.753646Z | Download | c823a9c9e32d2166d0ce8fa60b63459648a55f29a17c0d5dbf66fe4c9e05f1c2 |
| 0.36.0 | 2024-06-11T20:14:01.501110Z | Download | 0e88d479c11c4d3d46b2610fb7e94a13ac34fbf5d3adc265afb1645361ec5062 |
| 0.36.1 | 2024-07-06T14:56:19.137292Z | Download | eed5e5d26a66e2da7a2cbbc9a9c558d8469f58c907672334bbac30d7a74663bc |
| 0.36.2 | 2024-07-10T20:20:50.137389Z | Download | 37334bfabd05655895dc0c90a38022e4e588eefb848ffc9d382f37439a44be46 |
| 0.36.3 | 2025-05-20T18:18:43.036545Z | Download | fe2bd740fe522d9dd791850baa6cba492f00c283f3c0b0012995d538ce66570c |
| 0.37.0 | 2025-10-28T21:33:17.634937Z | Download | 9c2e4cbfe35db52c0071371202804551932a331a7ea31338c65ec133ea9f56b8 |
| 0.37.1 | 2025-12-18T18:00:34.741620Z | Download | af7d625e4bfd04764d1554a6411d349dd62d4dc204105cc819a81a35a77bd9b6 |
Dependencies
flutter {
"sdk": "flutter"
}
flutter_localizations {
"sdk": "flutter"
}