translate static method
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!;
}