tr method

String tr({
  1. Map args = const {},
  2. String category = '',
  3. 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,
  );
}