Translation

From neuromatch

DeepL

Other Implementations

IceCubes

IceCubes has DeepL translation enabled by default, even if the instance doesn't. Apparently there are some problems with the way it detects source/target language: https://neuromatch.social/@LorenAmelang/111207842133765471

There is an open issue here that describes the problem : https://github.com/Dimillian/IceCubesApp/issues/1614

  • "Your Server" means his mastodon instance
  • We removed "Translate with DeepL" since someone complained that it's too confusing for the average user. We haven't changed the use of the "Translate"-Button. If your text is translated via DeepL and you haven't manually forced that in the settings by pasting your API key this is the translation service your mastodon instance provides. We send a request to your instance by default and can't select the translation service in that case.
  • If you use your server's translation service we can't manually select the source language, since that's not included in the mastodon API. This would however be possible with DeepL (AFAIK), so we might be able to add that selector for users which have selected DeepL specifically

It looks like the translation request is submitted with the target language as configured for the translating user: https://github.com/Dimillian/IceCubesApp/blob/8a49409b26c4a914bfddd19f46fe11a5986ba8fa/Packages/Status/Sources/Status/Row/StatusRowViewModel.swift#L343

and the logic of the request happens here: https://github.com/Dimillian/IceCubesApp/blob/8a49409b26c4a914bfddd19f46fe11a5986ba8fa/Packages/Network/Sources/Network/DeepLClient.swift#L51

public func request(target: String, text: String) async throws -> Translation {
    do {
      var components = URLComponents(string: endpoint)!
      var queryItems: [URLQueryItem] = []
      queryItems.append(.init(name: "text", value: text))
      queryItems.append(.init(name: "target_lang", value: target.uppercased()))
      components.queryItems = queryItems
      var request = URLRequest(url: components.url!)
      request.httpMethod = "POST"
      request.setValue(authorizationHeaderValue, forHTTPHeaderField: "Authorization")
      request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
      let (result, _) = try await URLSession.shared.data(for: request)
      let response = try decoder.decode(Response.self, from: result)
      if let translation = response.translations.first {
        return .init(content: translation.text.removingPercentEncoding ?? "",
                     detectedSourceLanguage: translation.detectedSourceLanguage,
                     provider: "DeepL.com")
      }
      throw DeepLError.notFound
    } catch {
      throw error
    }
  }

But that

  • doesn't submit the explicitly indicated source language
  • it looks like there could be potentially multiple translations in that object but it just takes the first one.

The DeepL API does allow one to specify the source language, but IceCubes just doesn't: https://github.com/DeepLcom/openapi/blob/c2afaff99f3e518cafda850782ca077703dba559/openapi.yaml#L128

But the issue indicates the behavior might be different if DeepL is configured on the instance...

References


History

Discord

sneakers-the-rat#technical-wg22-12-18 00:23:06

Mastodon/Tech WG#TODO Translation services! can we do something like Kolektiva does: https://kolektiva.social/@subMedia/109531114768269437 isn't there some fancy new offline/self-contained translation network thing??? I don't want to make any calls to Google from the instance but translation would be great

sneakers.the.rat#technical-wg23-08-27 22:00:20

Also saw you boosted this, seems like a great idea for Translation https://frontrange.co/@raineer/110959799057137486


Other Context