Whatlang NIF bindings for Elixir.
- Elixir
1.15or more - Erlang OTP
24or more
Note: This project is developed and tested with Elixir
1.18.4and Erlang OTP28. Please open an issue if backward compatibilities with the minimum versions listed above are not respected.
The package can be installed by adding whatlangex to your list of dependencies in mix.exs:
def deps do
[
{:whatlangex, "~> 0.4.0"}
]
endTo detect the language of a sentence:
iex> Whatlangex.detect("¿Cómo te llamas?")
%Whatlangex.Detection{
lang: "spa",
script: "Latin",
confidence: 0.6848222396112233
}You can limit which languages to check using an allowlist or denylist:
# Only check for specific languages
iex> Whatlangex.detect("Hello world", allowlist: ["eng", "fra", "spa"])
%Whatlangex.Detection{lang: "eng", script: "Latin", confidence: ...}
# Exclude specific languages from detection
iex> Whatlangex.detect("Bonjour le monde", denylist: ["eng", "deu"])
%Whatlangex.Detection{lang: "fra", script: "Latin", confidence: ...}Note: allowlist and denylist are mutually exclusive. If both are provided, allowlist takes precedence and denylist is ignored.
To get the full language name from language code:
iex> Whatlangex.code_to_eng_name("spa")
"Spanish"
iex> Whatlangex.code_to_name("spa")
"Español"