Skip to content

Commit

Permalink
fix: issue in google translator connector whith text contains single …
Browse files Browse the repository at this point in the history
…quote char - EXO-66886 (#52)

Prior to this change, when attempting to translate a text with a simple quote char with google translator, the connector fails due to existing quote char in the text due to the use of signle quotes in the request param.
This prevents this situation by using escaped double quotes in the qurey param.
  • Loading branch information
hakermi committed Oct 19, 2023
1 parent e4af14d commit 48302be
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public DeepLTranslateConnector(SettingService settingService) {
super(settingService);
textTranslationOptions = new TextTranslationOptions();
textTranslationOptions.setTagHandling("html");
textTranslationOptions.setPreserveFormatting(true);
textTranslationOptions.setSentenceSplittingMode(SentenceSplittingMode.All);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public String translate(String message, Locale targetLocale) {
// except for chinese. But as zh correspond to simplified chinese, we can deal
// with that :
// https://cloud.google.com/translate/docs/languages
message = message.replace("'", "\\'");
String data = DATA_PATTERN.replace("{message}", message).replace("{targetLocale}", targetLocale.getLanguage());
try {
HttpPost httpTypeRequest = new HttpPost(serviceUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void translate() throws NoSuchFieldException, IllegalAccessException, Dee
// Need real auth-key to have a real result
TextTranslationOptions textTranslationOptions = new TextTranslationOptions();
textTranslationOptions.setTagHandling("html");
textTranslationOptions.setPreserveFormatting(true);
textTranslationOptions.setSentenceSplittingMode(SentenceSplittingMode.All);
TextResult textResult = new TextResult("<h1>Hello</h1>", "fr");
Field textTranslationOptionsField = deepLTranslateConnector.getClass().getDeclaredField("textTranslationOptions");
Expand Down

0 comments on commit 48302be

Please sign in to comment.