mirego / accent

The first developer-oriented translation tool. True asynchronous flow between translators and your team.
https://www.accent.reviews
BSD 3-Clause "New" or "Revised" License
1.29k stars 97 forks source link

Machine translation 500 error #423

Closed ChxGuillaume closed 7 months ago

ChxGuillaume commented 7 months ago

Using DeepL is causing a 500 on the backend and locks the input in the review tab.

Backend Error:

12:56:24.458 request_id=F8Du8q1TlrUme7cAAE_C [info] POST /graphql
12:56:24.507 request_id=F8Du8q1TlrUme7cAAE_C current_user=xxxxxx@xxxxxx graphql_operation=TranslateTextProject [info] Sent 500 in 48ms
12:56:24.507 request_id=F8Du8q1TlrUme7cAAE_C current_user=xxxxxx@xxxxxx graphql_operation=TranslateTextProject [error] GenServer #PID<0.5185.0> terminating
** (FunctionClauseError) no function clause matching in String.upcase/2
    (elixir 1.15.7) lib/string.ex:830: String.upcase(nil, :default)
    (accent 1.20.2) lib/machine_translations/provider/deepl.ex:49: Accent.MachineTranslations.Provider.Accent.MachineTranslations.Provider.Deepl.translate/4
    (accent 1.20.2) lib/machine_translations/machine_translations.ex:35: anonymous fn/5 in Accent.MachineTranslations.translate/4
    (elixir 1.15.7) lib/enum.ex:4830: Enumerable.List.reduce/3
    (elixir 1.15.7) lib/enum.ex:2564: Enum.reduce_while/3
    (accent 1.20.2) lib/graphql/resolvers/machine_translation.ex:29: Accent.GraphQL.Resolvers.MachineTranslation.translate_text/3
    (absinthe 1.7.6) lib/absinthe/resolution.ex:209: Absinthe.Resolution.call/2
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:234: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
Last message: {:tcp, #Port<0.49>, "POST /graphql HTTP/1.1\r\nHost: example.com\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36\r\nContent-Length: 680\r\nAccept: */*\r\nAccept-Encoding: gzip, deflate, br, zstd\r\nAccept-Language: en-US,en;q=0.8\r\nAuthorization: Bearer xxxx\r\nContent-Type: application/json\r\nOrigin: https://example.com\r\nReferer: https://example.com/app/projects/72d7618a-2777-4c43-b9bf-32e0b272d490/conflicts?relatedRevisions=%5B%22d1b6ad17-c8f9-4667-817a-2599033e4fd3%22%2C%22d968f646-0b1f-4e54-b3dd-7b04a184dc98%22%5D\r\nSec-Ch-Ua: \"Brave\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"\r\nSec-Ch-Ua-Mobile: ?0\r\nSec-Ch-Ua-Platform: \"macOS\"\r\nSec-Fetch-Dest: empty\r\nSec-Fetch-Mode: cors\r\nSec-Fetch-Site: same-origin\r\nSec-Gpc: 1\r\nX-Forwarded-For: 37.71.132.98\r\nX-Forwarded-Host: example.com\r\nX-Forwarded-Port: 443\r\nX-Forwarded-Proto: https\r\nX-Forwarded-Server: traefik\r\nX-Real-Ip: 37.71.132.98\r\n\r\n"}
State: {%ThousandIsland.Socket{socket: #Port<0.49>, transport_module: ThousandIsland.Transports.TCP, read_timeout: 60000, silent_terminate_on_error: false, span: %ThousandIsland.Telemetry{span_name: :connection, telemetry_span_context: #Reference<0.3129036720.3767271427.128506>, start_time: -576460455125265692, start_metadata: %{remote_address: {172, 22, 0, 1}, telemetry_span_context: #Reference<0.3129036720.3767271427.128506>, remote_port: 48050, parent_telemetry_span_context: #Reference<0.3129036720.3767271426.113644>}}}, %{opts: %{http_1: [], http_2: [], websocket: []}, plug: {Accent.Endpoint, []}, handler_module: Bandit.HTTP1.Handler, http_1_enabled: true, http_2_enabled: true, websocket_enabled: true, requests_processed: 7}}
ChxGuillaume commented 7 months ago

After some investigation, it seems to come from some frontend GraphQL request in this component/function:

https://github.com/mirego/accent/blob/c0c8d83c5403b0f997d5118ad752dd4080292da5/webapp/app/components/inline-machine-translate/component.ts#L23-L40

It seems like this GraphQL Request needs a targetLanguageSlug and sourceLanguageSlug In this method, it seems like the param targetLanguageSlug should be sourceLanguageSlug It is then missing the targetLanguageSlug from request based on the "conflict list column"

ChxGuillaume commented 7 months ago

Hi @simonprev,

Would like to know something regarding the Machine Translation feature. image Are the languages proposed in the inputs supposed to be a Source selection or the other way around?

I thought it was meant to select the source language you wanted to use for translation into the current "context" language 😄 I suppose if it is Target from Source, the source would be the primary language?

Sorry for bothering you with this issue 😅

simonprev commented 7 months ago

Hi @ChxGuillaume ! Yeah the UX for this is not optimal, I see why you thought that the select was the source language.

The way this works is by using the "detect language" of the provider like DeepL and Google Translate. The fix is already in master branch and 1.21.0. The proposed languages in the select are choices "to be translated in". You’re right that it’s pointless since we know the "target" language since we are in the context of a language in the textarea.

This means we should just remove the list of language and make the "translate" icon just send the text with the current textarea language context as the "target" parameter.

That makes sense?

ChxGuillaume commented 7 months ago

Okay yup, get it. Thanks for the clarification 😄

simonprev commented 7 months ago

Much easier to use! Thanks @ChxGuillaume !