BergamotTranslatorSharp is a C# wrapper for Bergamot Translator. It allows easy integration of an offline machine translation engine into .NET applications.
Bergamot Translator is an offline translation engine. The official website is https://browser.mt/. This library wraps its functionality for use from C#.
- Offline translation capability
- Multi-language support
- Fast processing
- Easy integration with .NET applications
Install-Package BergamotTranslatorSharp
Or
dotnet add package BergamotTranslatorSharp
- .NET 6.0 or later
- .NET Standard 2.1 or later
- Windows x64 or Linux x64
- Download and extract models from the Firefox Translations models official website.
cd test_page git clone --depth 1 --branch main --single-branch https://github.com/mozilla/firefox-translations-models/ mkdir models cp -rf firefox-translations-models/registry.json models cp -rf firefox-translations-models/models/prod/* models cp -rf firefox-translations-models/models/dev/* models gunzip models/*/*
- Create a configuration file in the same location as the binary file.
relative-paths: true models: - model.enja.intgemm.alphas.bin // model path vocabs: - vocab.enja.spm // source vocabulary path - vocab.enja.spm // target vocabulary path shortlist: - lex.50.50.enja.s2t.bin // shortlist path - false beam-size: 1 normalize: 1.0 word-penalty: 0 max-length-break: 128 mini-batch-words: 1024 workspace: 128 max-length-factor: 2.0 skip-cost: true cpu-threads: 0 quiet: true quiet-translation: true gemm-precision: int8shiftAlphaAll // specify 'int8shiftAlphaAll' if the model name contains 'alphas', otherwise specify 'int8shiftAll'
using BergamotTranslatorSharp;
// Create an instance of BergamotTranslator
using var translator = new BergamotTranslator(configPath);
// Execute translation
string sourceText = "Hello, world!";
string translatedText = translator.Translate(sourceText);
Console.WriteLine(translatedText); // こんにちは、世界!This project is released under the MPL-2.0 license.
Please report bugs and feature requests to the GitHub Issue Tracker. Pull requests are also welcome.
This project is based on browsermt/bergamot-translator.