writeByLang method

String writeByLang(
  1. String ln
)

Retrieves the translated string based on a specified language code.

This method allows specifying a language code to retrieve the translation from the application's language settings. If no translation is found, it returns the original key.

Example:

TString farewellMessage = 'goodbye'.tr;
String translatedMessage = farewellMessage.writeByLang('fr');

ln The language code (e.g., 'en', 'fr') to look up the translation.

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

Implementation

String writeByLang(String ln) {
  var language = WaServer.appLanguages[ln] ?? WaServer.appLanguages['en'];
  if (language != null && language[key] != null) {
    return language[key]!;
  }
  return key;
}