tr method

String tr([
  1. BuildContext? context
])

Translates the string key using the LocalizationManager from the provided context.

This method retrieves the translation of the string key from the nearest LocalizationProvider in the widget tree. If the key is not found, a default "Key not found" text is returned, which can be customized. It is a simpler version of translation that does not involve replacing parameters.

Usage example:

Text('hello'.tr(context))
  • Parameters:

    • context: The BuildContext used to find the LocalizationProvider and access the LocalizationManager.
  • Returns: The translated string, or the default "Key not found" text if the translation key is not found.

Implementation

String tr([BuildContext? context]) {
  return LocalizationProvider.of(context).translate(this);
}