translate method

String translate(
  1. String key, [
  2. Map<String, String>? arguments
])

translates a word

Implementation

String translate(String key, [Map<String, String>? arguments]) {
  String value =
      (_values == null || _values![key] == null) ? key : _values![key];

  String? returnValue = value;

  if (_isNestedKey(key)) {
    returnValue = _getNested(key);
  }

  if (returnValue == null) {
    return key;
  }

  if (arguments == null) return returnValue;

  for (var key in arguments.keys) {
    returnValue = returnValue?.replaceAll("{{$key}}", arguments[key]!);
  }
  return returnValue ?? "";
}