t method

  1. @override
String t(
  1. String key, {
  2. Map<String, dynamic>? parameters,
  3. String? locale,
  4. String? namespace,
})
override

Looks up a translation for the given key with advanced parameter replacement.

Supports multiple parameters using :param syntax, custom replacers, and namespace lookup.

Implementation

@override
String t(
  String key, {
  Map<String, dynamic>? parameters,
  String? locale,
  String? namespace,
}) {
  final loc = locale ?? _currentLocale;
  final ns = namespace ?? '';

  // Try namespace first, then global
  String? msg =
      _getTranslation(key, loc, ns) ?? _getTranslation(key, loc, '');

  // Fallback to fallback locale
  if (msg == null && loc != _fallbackLocale) {
    msg = _getTranslation(key, _fallbackLocale, ns) ??
        _getTranslation(key, _fallbackLocale, '');
  }

  // Use key if not found
  msg ??= key;

  // Apply parameter replacement
  if (parameters != null) {
    msg = _replaceParameters(msg, parameters);
  }

  return msg;
}