t method

String t(
  1. String key, {
  2. Locale? locale,
  3. String? context,
  4. int? count,
  5. Map<String, dynamic>? variables,
  6. I18NextOptions? options,
  7. String orElse(
    1. String
    )?,
})

Attempts to retrieve a translation at key.

  • If context is given, then attempts to search for the key at 'key_context', before defaulting to the key itself. It is useful for selections like gender.
  • If count is given, then based on locale attempts to find the appropriate pluralized key, before defaulting to the key itself. Most languages like en have only one and other pluralization forms but some like ar require a more complex system.
  • If variables are given, they are used as a lookup table when a match has been found (delimited by I18NextOptions.interpolationPrefix and I18NextOptions.interpolationSuffix). Before the result is added to the final message, it first goes through I18NextOptions.formats.
  • If locale is given, it overrides the current locale value.
  • If options is given, it overrides any non-null property over current options.

The named parameters in this method that are also declared by I18NextOptions supersede options's values.

Keys that allow both contextualization and pluralization must be declared in the order: key_context_plural

If a value for key is not found, returns the key itself.

Implementation

String t(
  String key, {
  Locale? locale,
  String? context,
  int? count,
  Map<String, dynamic>? variables,
  I18NextOptions? options,
  String Function(String)? orElse,
}) {
  return tOrNull(
        key,
        locale: locale,
        context: context,
        count: count,
        variables: variables,
        options: options,
      ) ??
      orElse?.call(key) ??
      key;
}