Packages

Kanta plugin for using DeepL translator from the UI

Current section

Files

Jump to
kanta_deep_l_plugin lib kanta_deep_l_plugin.ex
Raw

lib/kanta_deep_l_plugin.ex

defmodule Kanta.DeepL.Plugin do
@moduledoc """
Kanta DeepL integration plugin
"""
use GenServer
alias Kanta.DeepL.Adapter
def start_link(opts) do
GenServer.start_link(__MODULE__, opts, name: opts[:name])
end
def init(_opts) do
{:ok, %{}}
end
def validate(opts) do
case Keyword.get(opts, :api_key) do
api_key when is_binary(api_key) ->
if String.ends_with?(api_key, "fx"), do: :ok, else: {:error, "invalid DeepL API key"}
nil ->
{:error, "missing DeepL API key"}
end
end
def usage do
Adapter.usage()
end
end