create method

type - type of service which should be created and initialized

Implementation

Future<AbstractTranslationService> create(TranslationServiceType type) async {
  try {
    final configuration = await _parseConfiguration();

    switch (type) {
      case TranslationServiceType.azureCognitiveServices:
        return _createAzureCognitiveServicesTranslator(configuration);
      case TranslationServiceType.yandex:
        return _createYandexTranslator(configuration);
      case TranslationServiceType.googleCloud:
        return await _createGoogleCloudTranslator(configuration);
      case TranslationServiceType.deepL:
        return _createDeepLTranslator(configuration);
      case TranslationServiceType.amazonTranslate:
        return _createAmazonTranslateTranslator(configuration);
    }
  } on Exception catch (error) {
    logger.error('Failed to initialize translator service', error);
    rethrow;
  }
}