write method
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 {}]) {
var params = {...values};
var key = this.key;
if (key.contains('#')) {
final valuesKey = key.split('#');
key = valuesKey[0];
if (valuesKey.length > 1) {
for (var i = 1; i < valuesKey.length; i++) {
var val = valuesKey[i].toString();
val = val.replaceAll('{', '').replaceAll('}', '');
params[(i - 1).toString()] = val;
}
}
}
final ln = rq.getLanguage();
var language = WaServer.appLanguages[ln] ?? WaServer.appLanguages['en'];
if (language != null && language[key] != null) {
var res = _repliceParams(language[key]!, params);
return res;
}
return key;
}