tOrNull method

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

Attempts to retrieve a translation at key. Returns null if the translation cannot be found.

See also: t for a function that returns a non-nullable String

Implementation

String? tOrNull(
  String key, {
  Locale? locale,
  String? context,
  int? count,
  Map<String, dynamic>? variables,
  I18NextOptions? options,
}) {
  variables ??= {};
  if (context != null) variables['context'] = context;
  if (count != null) variables['count'] = count;

  locale ??= this.locale;
  final newOptions = this.options.merge(options);

  var result = Translator(pluralResolver, resourceStore)
      .call(key, locale, variables, newOptions);
  if (result == null && newOptions.missingKeyHandler != null) {
    result =
        newOptions.missingKeyHandler!(locale, key, variables, newOptions);
  }
  return result;
}