Skip to content

Conversation

asus007
Copy link
Contributor

@asus007 asus007 commented Jul 8, 2024

No description provided.

Comment on lines 26 to 27
private val deeplClient = DeeplClient(property ("tock_translator_deepl_api_url", "default"),property ("tock_translator_deepl_api_key", "default"))
private val glossaryId = property ("tock_translator_deepl_glossaryId", "default")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These properties should be documented in the module's readme

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also does it even make sense to provide default values here? I believe this module should error ASAP when enabled without valid settings.

Comment on lines +7 to +21
/*
* Copyright (C) 2017/2021 e-voyageurs technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copyright notice should be above the package declaration I think. Speaking of which, there is no package declaration in this file...?

*/
class DeeplTranslateIntegrationTest {
@Test
@Disabled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If every method is disabled like this, maybe it would be worth just disabling the entire class? Ideally though, there should be functional end-to-end tests with wiremock to simulate Deepl's responses.

@Disabled
fun testWithHTML() {
val result = DeeplTranslatorEngine.translate(
"Bonjour, je voudrais me rendre à Paris <br><br/> demain soir",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does Deepl behave with a self-closing <br/> tag? I believe that would be the most common form, if it occurred. Could also try more advanced HTML structures, like a list (somewhat common in web connector messages)

private val apiKey: String? = propertyOrNull("tock_translator_deepl_api_key"),
okHttpCustomizer: OkHttpClient.Builder.() -> Unit = {}
) : DeeplClient {
private val client = OkHttpClient.Builder().apply(okHttpCustomizer).build()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This client should use the TockProxyAuthenticator by default

import com.github.salomonbrys.kodein.bind
import com.github.salomonbrys.kodein.provider

fun deeplTranslatorModule(client: DeeplClient = OkHttpDeeplClient()) = Kodein.Module {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have a default val deeplTranslatorModule = deeplTranslatorModule() for consistency with other modules

Comment on lines 25 to 26
private val supportedLanguagesProperty = propertyOrNull("tock_translator_deepl_target_languages")
private val supportedLanguages: Set<String>? = supportedLanguagesProperty?.split(",")?.map { it.trim() }?.toSet()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not inline supportedLanguagesProperty?

override fun translate(text: String, source: Locale, target: Locale): String {
var translatedTextHTML4 = ""
// Allows to filter translation on a specific language
if (supportedLanguages?.contains(target.language) == true || supportedLanguages == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could swap the two conditions to benefit from the smart cast


val request = Request.Builder()
.url(apiURL)
.addHeader("Authorization", "DeepL-Auth-Key $apiKey")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apiKey could be null at this point in the code. The client should fail way earlier if that is the case.

.build()

glossaryId?.let {
formBuilder.add("glossaryId", it)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
formBuilder.add("glossaryId", it)
formBuilder.add("glossary_id", it)

Based on https://developers.deepl.com/docs/api-reference/translate/openapi-spec-for-text-translation

@vsct-jburet vsct-jburet added this to the 24.3.5 milestone Aug 20, 2024
@vsct-jburet vsct-jburet merged commit dd5a73f into theopenconversationkit:master Aug 20, 2024
morgandiverrez pushed a commit that referenced this pull request Aug 26, 2024
* #1606 Add Deepl translator module

* #1606 Add Deepl translator module - first set of corrections

* #1606 Add Deepl translator module - first set of corrections

* #1606 Add Deepl translator module - second set of corrections

* #1606 : Use of TockProxyAuthenticator + use of glossary map ids for all languages

* #1606 translator: clean up module

* #1606 : Correction of the glossary id name

---------

Co-authored-by: charles_moulhaud <[email protected]>
Co-authored-by: Fabilin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants