tr function

String tr(
  1. String key,
  2. {BuildContext? context,
  3. List<String>? args,
  4. Map<String, String>? namedArgs,
  5. String? gender}

Main function for translate your language keys key Localization key BuildContext The location in the tree where this widget builds args List of localized strings. Replaces {} left to right namedArgs Map of localized strings. Replaces the name keys {key_name} according to its name gender Gender switcher. Changes the localized string based on gender string


   "msg":"{} are written in the {} language",
   "msg_named":"Easy localization is written in the {lang} language",
   "msg_mixed":"{} are written in the {lang} language",
      "male":"Hi man ;) {}",
      "female":"Hello girl :) {}",
      "other":"Hello {}"
Text('msg').tr(args: ['Easy localization', 'Dart']), // args
Text('msg_named').tr(namedArgs: {'lang': 'Dart'}),   // namedArgs
Text('msg_mixed').tr(args: ['Easy localization'], namedArgs: {'lang': 'Dart'}), // args and namedArgs
Text('gender').tr(gender: _gender ? "female" : "male"), // gender


String tr(
  String key, {
  BuildContext? context,
  List<String>? args,
  Map<String, String>? namedArgs,
  String? gender,
}) {
  return context != null
      ? Localization.of(context)!
          .tr(key, args: args, namedArgs: namedArgs, gender: gender)
      : Localization.instance
          .tr(key, args: args, namedArgs: namedArgs, gender: gender);