diff --git a/config/config.exs b/config/config.exs index 1507c9360..0611f7c26 100644 --- a/config/config.exs +++ b/config/config.exs @@ -885,7 +885,6 @@ config :pleroma, :libre_translate, config :pleroma, :argos_translate, command_argos_translate: "argos-translate", command_argospm: "argospm", - fallback_language: "en", strip_html: true # Import environment specific config. This must remain at the bottom diff --git a/docs/docs/configuration/cheatsheet.md b/docs/docs/configuration/cheatsheet.md index d0b03e40d..4e84b9a44 100644 --- a/docs/docs/configuration/cheatsheet.md +++ b/docs/docs/configuration/cheatsheet.md @@ -1119,7 +1119,7 @@ Each job has these settings: ### Translation Settings Settings to automatically translate statuses for end users. Currently supported -translation services are DeepL and LibreTranslate. +translation services are DeepL and LibreTranslate. The supported command line tool is [Argos Translate](https://github.com/argosopentech/argos-translate). Translations are available at `/api/v1/statuses/:id/translations/:language`, where `language` is the target language code (e.g `en`) @@ -1128,7 +1128,7 @@ Translations are available at `/api/v1/statuses/:id/translations/:language`, whe - `:enabled` - enables translation - `:module` - Sets module to be used - - Either `Pleroma.Akkoma.Translators.DeepL` or `Pleroma.Akkoma.Translators.LibreTranslate` + - Either `Pleroma.Akkoma.Translators.DeepL`, `Pleroma.Akkoma.Translators.LibreTranslate`, or `Pleroma.Akkoma.Translators.ArgosTranslate` ### `:deepl` @@ -1143,9 +1143,6 @@ Translations are available at `/api/v1/statuses/:id/translations/:language`, whe ### `:argos_translate` -[Argos Translate](https://github.com/argosopentech/argos-translate) is the library used by Libre Translate and can run as a command line tool. It's more basic than Libre Translate as it doesn't provide a way to properly handle html or language detection. - - `:command_argos_translate` - command for `argos-translate`. Can be the command if it's in your PATH, or the full path to the file (default: `argos-translate`). - `:command_argospm` - command for `argospm`. Can be the command if it's in your PATH, or the full path to the file (default: `argospm`). -- `:fallback_language` - When no language is provided to translate from, this language will be used. Must be a two letter langage code from a language you have installed (default: `en`). -- `:strip_html` - Strip html from the post before translating the text (default: `true`). +- `:strip_html` - Strip html from the post before translating it (default: `true`). diff --git a/lib/pleroma/akkoma/translators/argos_translate.ex b/lib/pleroma/akkoma/translators/argos_translate.ex index 375a93b41..9e19b14c7 100644 --- a/lib/pleroma/akkoma/translators/argos_translate.ex +++ b/lib/pleroma/akkoma/translators/argos_translate.ex @@ -11,8 +11,8 @@ defmodule Pleroma.Akkoma.Translators.ArgosTranslate do Config.get([:argos_translate, :command_argospm]) end - defp fallback_language do - Config.get([:argos_translate, :fallback_language]) + defp strip_html? do + Config.get([:argos_translate, :strip_html]) end defp safe_languages() do @@ -85,23 +85,24 @@ defmodule Pleroma.Akkoma.Translators.ArgosTranslate do defp htmlify_response(string, _), do: string @impl Pleroma.Akkoma.Translator - def translate(string, from_language, to_language) do - strip_html = Config.get([:argos_translate, :strip_html]) + def translate(string, nil, to_language) do # Akkoma's Pleroma-fe expects us to detect the source language automatically. # Argos-translate doesn't have that option (yet?) # see - # For now we choose a fallback source language from settings. + # For now we return the text unchanged, supposedly translated from the target language. # Afterwards people get the option to overwrite the source language from a dropdown. - from_language = from_language || fallback_language() - to_language = to_language || fallback_language() + {:ok, to_language, string} + end + + def translate(string, from_language, to_language) do # Argos Translate doesn't properly translate HTML (yet?) # For now we give admins the option to strip the html before translating # Note that we have to add some html back to the response afterwards - string = clean_string(string, strip_html) + string = clean_string(string, strip_html?()) with {translated, 0} <- safe_translate(string, from_language, to_language) do - {:ok, from_language, translated |> htmlify_response(strip_html)} + {:ok, from_language, translated |> htmlify_response(strip_html?())} else {response, _} -> {:error, "ArgosTranslate failed to translate (#{response})"} end diff --git a/test/pleroma/akkoma/translators/argos_translate_test.exs b/test/pleroma/akkoma/translators/argos_translate_test.exs index 57368055a..977df1693 100644 --- a/test/pleroma/akkoma/translators/argos_translate_test.exs +++ b/test/pleroma/akkoma/translators/argos_translate_test.exs @@ -27,19 +27,11 @@ defmodule Pleroma.Akkoma.Translators.ArgosTranslateTest do assert [%{code: "en", name: "en"}, %{code: "nl", name: "nl"}] = dest_langs |> Enum.sort() end - test "it translates from default language when no language is set" do - translation_response = - with_mock System, [:passthrough], - cmd: fn "argos-translate_test", ["--from-lang", "en", "--to-lang", "fr", "blabla"], _ -> - {"yadayada", 0} - end do - ArgosTranslate.translate("blabla", nil, "fr") - end - - assert {:ok, "en", "yadayada"} = translation_response + test "it translates from the to language when no language is set and returns the text unchanged" do + assert {:ok, "nl", "blabla"} = ArgosTranslate.translate("blabla", nil, "nl") end - test "it translates from the provided language" do + test "it translates from the provided language if provided" do translation_response = with_mock System, [:passthrough], cmd: fn "argos-translate_test", ["--from-lang", "nl", "--to-lang", "en", "blabla"], _ ->