tr method

String tr([
  1. BuildContext? context
])

Implementation

String tr([BuildContext? context]) {
  // Try to use the provided context
  if (context != null) {
    return AppLocalizations.of(context).translate(this);
  }

  // Try to use the global context from Localingo
  if (Localingo.navigatorKey.currentContext != null) {
    return AppLocalizations.of(Localingo.navigatorKey.currentContext!)
        .translate(this);
  }

  // Fallback: return the key itself if no context is available
  debugPrint(
      'WARNING: No context available for translation of key "$this". Returning key.');
  return this;
}