i18n_extension_core 2.0.4 i18n_extension_core: ^2.0.4 copied to clipboard
Dart-only package for Translation and Internationalization (i18n), with Dart extensions. Easy to use for both large and small projects.
i18n_extension_core #
This is the core Dart-only package for the i18n_extension package.
In your Flutter app: #
-
Do NOT include this core package directly.
Instead, go to the i18n_extension package which already exports this core code, plus provides Flutter related code like the
I18n
widget that you must use to wrap your widget tree.
In your Dart server or Dart-only code: #
-
If you are creating code for a Dart server (backend) like Celest, or developing some Dart-only package that does not depend on Flutter, then you can use this package directly:
import 'package:i18n_extension_core/i18n_extension_core.dart'; extension Localization on String { static var t = Translations.byText("en_us") + {"en_us":"Hello", "pt_br":"Hola"}; String get i18n => localize(this, t); } DefaultLocale.set("es_ES"); expect("Hello".i18n, "Hola");
Note: When using Celest, this is especially useful for translating the exception messages that the backend throws to the frontend. For example, throwing
MyException('The password you typed is invalid'.i18n);
in the backend, will reach the frontend already translated asMyException('La contraseña que ingresaste no es válida')
if the user device is in Spanish.
Documentation #
Go to i18n_extension to read the docs.
There are only 2 differences when using this package directly:
-
Here you don't have access to the
I18n
widget, which is a Flutter widget. -
The way to set the default locale is different. Instead of using the
I18n
widget, you must use theDefaultLocale.set()
static method, like in the example above.
Marcelo Glasberg #
https://github.com/marcglasberg
https://twitter.com/glasbergmarcelo
https://stackoverflow.com/users/3411681/marcg
https://medium.com/@marcglasberg
The Flutter packages I've authored:
- async_redux
- fast_immutable_collections
- provider_for_redux
- i18n_extension
- align_positioned
- network_to_file_image
- image_pixels
- matrix4_transform
- back_button_interceptor
- indexed_list_view
- animated_size_and_fade
- assorted_layout_widgets
- weak_map
- themed
My Medium Articles:
- Async Redux: Flutter’s non-boilerplate version of Redux ( versions: Português)
- i18n_extension ( versions: Português)
- Flutter: The Advanced Layout Rule Even Beginners Must Know ( versions: русский)
- The New Way to create Themes in your Flutter App
- A new BDD tool for TypeScript/React, and Flutter/Dart
My article in the official Flutter documentation: