write method
Retrieves the translated string based on the current language from the Request.
This method uses the current language from the Request 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);
Returns the translated string if found, otherwise returns the original key.
Implementation
String write([Map 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 = Context.rq.getLanguage();
var language = FinchApp.appLanguages[ln] ?? FinchApp.appLanguages['en'];
if (language != null && language[key] != null) {
var res = _repliceParams(language[key]!, params);
return res;
}
return key;
}