tr method
String
tr({
- Map args = const {},
- String category = '',
- ReplacePatternsSettings? configSettings = const ReplacePatternsSettings(opening: '{', closing: '}', delimiter: ';;', separator: '.'),
Translates the string using the active translation file.
Implementation
String tr({
Map<dynamic, dynamic> args = const {},
String category = '',
ReplacePatternsSettings? configSettings = const ReplacePatternsSettings(
opening: '{',
closing: '}',
delimiter: ';;',
separator: '.',
),
}) {
final defaultSettings = const ReplacePatternsSettings();
var input = this;
if (category.isNotEmpty) {
input = input.splitByLastOccurrenceOf(defaultSettings.delimiter).join(
'||${category.isNotEmpty ? '$category${defaultSettings.separator}' : ''}',
);
}
final config = TranslationManager.translationFileConfig;
final temp = config.map<String>(
this,
args: args,
fallback: this,
settings: defaultSettings,
) ??
this;
return temp.replacePatterns(
args.mapKeys((k) => k.toString()),
settings: configSettings ?? config.settings,
);
}