translate method
Implementation
String translate(String key, {List<String>? args}) {
String localeName = this.localeName ?? Platform.localeName.split('_')[0];
if (!_localizedValues.containsKey(localeName) ||
_localizedValues[localeName]!.isEmpty ||
!_localizedValues[localeName]!.containsKey(key) ||
_localizedValues[localeName] == null) {
return key;
} else {
String translation = _localizedValues[localeName]![key]!;
if (args != null) {
for (int i = 0; i < args.length; i++) {
translation = translation.replaceAll('{$i}', args[i]);
}
} else {
// Remove all placeholders
translation = translation.replaceAll(RegExp(r'\{\d+\}'), '');
}
return translation;
}
}