Skip to content

Instantly share code, notes, and snippets.

@markito
Created July 1, 2020 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markito/e976443fd61a6d7d2278f2acfa7c18d3 to your computer and use it in GitHub Desktop.
Save markito/e976443fd61a6d7d2278f2acfa7c18d3 to your computer and use it in GitHub Desktop.
scf-blog-step2
@Bean
public Function<String, String> translate() {
return input -> {
final String fromLang = "en";
final String toLang = "es";
final String url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" + fromLang + "&tl="
+ toLang + "&dt=t&q=" + input;
final RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
String result = response.getBody();
// clean up results
int index = result.indexOf(",");
result = result.substring(3, index).replace("\"", "");
return result;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment