translate static method

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

Returns the translation for the given key. Optionally passes args to replace placeholders in the translation.

Implementation

static String translate(String key, [Map<String, dynamic>? args]) {
  // Keys are assumed to be structured as namespace.subnamespace.key.
  String? translation = _getNestedTranslation(_translations, key);
  if (translation == null && _fallbackLocale != null) {
    translation = key;
  }
  if (translation == null) {
    return key;
  }
  if (args != null) {
    args.forEach((placeholder, value) {
      translation =
          translation!.replaceAll('{$placeholder}', value.toString());
    });
  }
  return translation!;
}