tr method

String tr(
  1. String key, [
  2. Locale? locale
])

Returns the translated string for the given key and optional locale. If translation is not immediately available, returns key and translates in background.

Implementation

String tr(String key, [Locale? locale]) {
  locale ??= _currentLocale;
  final localeCache = _cache[locale.toString()] ?? {};
  if (localeCache.containsKey(key)) return localeCache[key] ?? key;
  if (_fallbackLanguage != locale) _cache[locale.toString()] = localeCache;
  _translateInBackground(key, locale);
  return key;
}