Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bilal's solution to Adapter DP assignment #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.scaler.lld.design.assignments.adapter;

import com.scaler.lld.design.assignments.adapter.external.GoogleTranslateApi;
import com.scaler.lld.design.assignments.adapter.external.GoogleTranslationRequest;

import java.util.List;

public class GoogleTranslateAdapter implements TranslationProviderAdapter{
private GoogleTranslateApi googleTranslateApi=new GoogleTranslateApi();
@Override
public String getTranslatedText(TranslationRequest translationRequest) {
GoogleTranslationRequest googleTranslationRequest=new GoogleTranslationRequest(translationRequest.getText(),translationRequest.getSourceLanguage(),translationRequest.getTargetLanguage(),translationRequest.getConfidenceThreshold());
return googleTranslateApi.convert(googleTranslationRequest);
}

@Override
public List<String> getTranslationSupportedLanguages() {
return googleTranslateApi.getLanguages();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.scaler.lld.design.assignments.adapter;

import com.scaler.lld.design.assignments.adapter.external.MicrosoftTranslateApi;

import java.util.List;

public class MicrosoftTranslateAdapter implements TranslationProviderAdapter{
private MicrosoftTranslateApi microsoftTranslateApi=new MicrosoftTranslateApi();
@Override
public String getTranslatedText(TranslationRequest translationRequest) {
return microsoftTranslateApi.translate(translationRequest.getText(),translationRequest.getSourceLanguage(),translationRequest.getTargetLanguage());
}

@Override
public List<String> getTranslationSupportedLanguages() {
return microsoftTranslateApi.getSupportedLanguages();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.scaler.lld.design.assignments.adapter;

import java.util.List;

public interface TranslationProviderAdapter {
public String getTranslatedText(TranslationRequest translationRequest);
public List<String> getTranslationSupportedLanguages();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.scaler.lld.design.assignments.adapter;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

// DO NOT REMOVE THE NO-ARG CONSTRUCTOR ANNOTATION
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class TranslationRequest {
private String text;
private String sourceLanguage;
private String targetLanguage;
private Double confidenceThreshold;
}