write method

String write(
  1. WebRequest rq, [
  2. Map<String, Object?> values = const {}
])

Retrieves the translated string based on the current language from the WebRequest.

This method uses the current language from the WebRequest and looks up the translation in the application's language settings. If no translation is found, it returns the original key.

Example:

WebRequest request = ...; // Your web request object
TString welcomeMessage = 'welcome'.tr;
String translatedMessage = welcomeMessage.write(request);

rq The WebRequest object that provides the current language context.

Returns the translated string if found, otherwise returns the original key.

Implementation

String write(WebRequest rq, [Map<String, Object?> values = const {}]) {
  final ln = rq.getLanguage();
  var language = WaServer.appLanguages[ln] ?? WaServer.appLanguages['en'];
  if (language != null && language[key] != null) {
    var res = _repliceParams(language[key]!, values);
    return res;
  }
  return key;
}