translate static method

Future<String> translate({
  1. required String text,
  2. String fromLanguageCode = GoogleTranslator.autoLanguage,
  3. required String toLanguageCode,
  4. bool ignoreError = true,
})

Implementation

static Future<String> translate({
  required String text,
  String fromLanguageCode = GoogleTranslator.autoLanguage,
  required String toLanguageCode,
  bool ignoreError = true,
}) async {
  try {
    final Translation translation = await googleTranslator.getTranslation(
      text,
      from: fromLanguageCode,
      to: toLanguageCode,
    );
    return translation.text;
  } catch (e) {
    if (ignoreError) {
      return text;
    } else {
      rethrow;
    }
  }
}