I18n class

Wrap your widget tree with the I18n widget. This will translate your strings to the current system locale:

import 'package:i18n_extension/i18n_widget.dart';

@override
Widget build(BuildContext context) {
  return I18n(
      child: Scaffold( ... )
  );
}

You can override it with any locale, like this:

return I18n(
    initialLocale: Locale("pt", "BR"),
    child: Scaffold( ... )
Inheritance

Constructors

I18n({Key? key, String? id, required Widget child, Locale? initialLocale})
The I18n widget should wrap the child which contains the tree of widgets you want to translate. If you want, you may provide an initialLocale. You may also provide a key, or, for advanced uses, an id which you can use with the forceRebuild function.

Properties

child Widget
final
hashCode int
The hash code for this object.
no setterinherited
initialLocale Locale?
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _I18nState
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

defaultLocale Locale
During app initialization, the system locale may be null for a few moments, so this default locale will be used instead. You can change this to reflect your preferred locale.
getter/setter pair
forcedLocale Locale?
no setter
language String
The language of the current locale, as a lowercase string. For example: "en" or "pt".
no setter
locale Locale
Returns the forced-locale, if it is not null. Otherwise, returns the system-locale. Note: If the system-locale is not defined for some reason, the locale will be Locale("en", "US").
no setter
localeStr String
The locale, as a lowercase string. For example: "en_us" or "pt_br".
no setter
observeLocale ↔ void Function({required Locale newLocale, required Locale oldLocale})
This global callback is called whenever the locale changes. Notes:
getter/setter pair
systemLocale Locale
no setter

Static Methods

define(Locale? locale) → void
To change the current locale:
forceRebuild(String id) → void
If you have multiple I18n widgets you can call this method to force specific I18n widgets to rebuild. First, give it an id (and not a key), for example: I18n(id:"myWidget", child: ...).
getDecimalSeparator(Locale locale) String
Given a locale, return the decimal separator. For example, for en_US it's "." but for pt_BR it's ",".
getLanguageFromLocale(Locale locale) String
Return the lowercase language-code of the given locale.
normalizeLocale(Locale locale) String
Return the string representation of the locale, normalized (trims spaces and underscore).
of(BuildContext context) → _I18nState
Getter: print(I18n.of(context).locale);