tr method

String tr(
  1. BuildContext context
)

Translates the string based on the current locale's translations.

This method looks up the nearest LocalizationProvider from the provided context, and attempts to translate the current string. If no translation is found, the original string is returned as a fallback.

Example usage:

'hello'.tr(context)

context The build context from which to find the LocalizationProvider. Returns the translated string if a match is found, or the original string if not.

Implementation

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