get method
Gets a translated string from key
, otherwise uses fallback
.
Optional args can be added to place hardcoded values (such as numbers) within the translated text. if the debugStrings is true then it always return key.
Implementation
String get(String key, String fallback, {List<String>? args}) {
if (debugStrings) return '#$key';
final String str = _strings[key] ?? '';
final String string = str.isEmpty ? fallback : str;
if (args != null && args.isNotEmpty) {
final List<MapEntry<String, String>> mapping = List<MapEntry<String, String>>.generate(
args.length,
(int index) => MapEntry<String, String>('$index', args[index]),
);
return string.format(Map<String, String>.fromEntries(mapping));
} else {
return string;
}
}