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 working on a Dart server-side application (backend) using frameworks such as
Serverpod, Dart Frog, or Shelf, or developing a Dart-only package that does not rely on
Flutter, you can use this package directly.:
Note: One key use case is translating exception messages from the backend to the
frontend. For example, if the backend throws an exception like:
MyException('The password you typed is invalid'.i18n)
it will automatically appear on the frontend as:
MyException('La contraseña que ingresaste no es válida')
if the user's device language is set to Spanish.
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 the DefaultLocale.set() static method, like in the example above.