API reference · Kjarni 0.2.7
Class Translator
Namespace: Kjarni
Assembly: Kjarni.dll
Translates text between languages.
public class Translator : IDisposable
Inheritance
Implements
Examples
using var translator = new Translator(from: "en", to: "de");
Console.WriteLine(translator.Translate("The house is small."));
Constructors
Translator(string?, string?, string?, string, string?, bool)
Load a translation model, downloading it on first use.
public Translator(string? model = null, string? from = null, string? to = null, string device = "cpu", string? cacheDir = null, bool quiet = false)
Parameters
model string?
Model name, e.g. "flan-t5-base" (the default) or "flan-t5-large".
from string?
Default source language ("en", "english", ...), used when a call passes none.
to string?
Default target language, used when a call passes none.
device string
Compute device - "cpu" or "gpu".
cacheDir string?
Directory to cache downloaded models.
quiet bool
Suppress progress output.
Methods
Dispose()
Releases the native model. The object cannot be used afterwards.
public void Dispose()
~Translator()
Releases the native model if
protected ~Translator()
Translate(string, string?, string?)
Translate text. Languages left null fall back to the
defaults given at construction; with neither, this throws with
public string Translate(string text, string? from = null, string? to = null)
Parameters
text string
from string?
to string?
Returns
Kjarni runs the same engine on every platform: