XLocalizer.Translate
1.0.0
dotnet add package XLocalizer.Translate --version 1.0.0
NuGet\Install-Package XLocalizer.Translate -Version 1.0.0
<PackageReference Include="XLocalizer.Translate" Version="1.0.0" />
<PackageVersion Include="XLocalizer.Translate" Version="1.0.0" />
<PackageReference Include="XLocalizer.Translate" />
paket add XLocalizer.Translate --version 1.0.0
#r "nuget: XLocalizer.Translate, 1.0.0"
#:package XLocalizer.Translate@1.0.0
#addin nuget:?package=XLocalizer.Translate&version=1.0.0
#tool nuget:?package=XLocalizer.Translate&version=1.0.0
Use Online Translation Services For Localization
Read full docs at: docs.ziya.info.tr
Provides translation support to web applications. Can be used with XLocalizer or as standalsone services.
Table of contents
- Available translation services
- Use with XLocalizer
- Use as standalone service
- Register multiple translation services
Available translation services
Below services are already available as nugets and ready to install.
- XLocalizer.Translate.MyMemoryTranslate
- XLocalizer.Translate.GoogleTranslate
- XLocalizer.Translate.MicrosoftTranslate
- XLocalizer.Translate.YandexTranslate
- XLocalizer.Translate.SystranTranslate
- XLocalizer.Translate.IBMWatsonTranslate
Click on each service for more details about how to install.
Any service that implements ITranslator interface can be used for automatic translation with XLocalizer or as standalone translation services as well.
Use with XLocalizer
// Register a translation service
services.AddHttpClient<ITranslator, MyMemoryTranslateService>();
// Configure XLocalizer to use the translation service
// and enable online translation
services.AddRazorPages()
.AddXLocalizer<LocSource, MyMemoryTranslateService>(ops =>
{
// ...
ops.AutoTranslate = true;
ops.TranslateFrom = "en";
});
Recommended read IHttpClientFactory
If TranslateFrom is not defined, then DefaultRequestCulture will be considered as the source culture for translation.
Use as standalone service
using XLocalizer.Translate;
public class IndexModel : PageModel
{
private readonly ITranslator _translator;
public IndexModel(ITranslator translator)
{
_translator = translator ?? throw new NotImplementedException(nameof(translator));
}
public void OnGet()
{
var success = _translator.TryTranslate("en", "tr", "Welcome", out string translation);
}
}
Or you can use the async method of ITranslator interface:
public async Task OnGetAsync()
{
var translation = await _translator.TranslateAsync("en", "tr", "Welcome", "text");
}
Register multiple translation services
It is possible to register multiple tranlsation services then retrive specific service for translation using ITranslatorFactory interface.
Register multiple translation services:
services.AddHttpClient<ITranslator, MyMemoryTranslateService>();
services.AddHttpClient<ITranslator, GoogleTranslateService>();
services.AddHttpClient<ITranslator, MicrosoftTranslateService>();
services.AddSingleton<ITranslator, IBMWatsonTranslateService>();
services.AddHttpClient<ITranslator, SystranTranslateService>();
services.AddHttpClient<ITranslator, YandexTranslateService>();
Retrive specific service:
using XLocalizer.Translate;
public class IndexModel : PageModel
{
private readonly ITranslator _translator;
public IndexModel(ITranslatorFactory factory)
{
// e.g: retrive an instance of MyMemoryTranslateService
_translator = factory.Create<MyMemoryTranslateService>();
// or retrive an instance based on string service name
_translator = factory.Create("MyMemory Translate");
}
}
ITranslatorFactory is already registered by XLocalizer. If you are not using XLocalizer you need to register it in startup as below:
using XLocalizer.Translate;
using XLocalizer.Translate.MyMemoryTranslate;
services.AddSingleton<ITranslatorFactory, TranslatorFactory<MyMemoryTranslateService>();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
NuGet packages (8)
Showing the top 5 NuGet packages that depend on XLocalizer.Translate:
| Package | Downloads |
|---|---|
|
XLocalizer
XLocalizer package for localization of Asp.Net Core web applications, powered by online translation and auto resource creating. |
|
|
XLocalizer.DB
Database provider for XLocalizer. |
|
|
XLocalizer.Translate.MyMemoryTranslate
Extension package for XLocalizer.TranslationServices to provide translations using MyMemory Translate. |
|
|
XLocalizer.Translate.MicrosoftTranslate
Extension package for XLocalizer.TranslationServices to provide translations using Microsoft Translator service. |
|
|
XLocalizer.Translate.GoogleTranslate
Extension package for XLocalizer.TranslationServices to provide translations using Google Translate. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on XLocalizer.Translate:
| Repository | Stars |
|---|---|
|
LazZiya/XLocalizer
Localizer package for Asp.Net Core web applications, powered by online translation and auto resource creating.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 62,866 | 11/12/2020 |
| 1.0.0-rc.1 | 581 | 11/5/2020 |
| 1.0.0-preview2 | 519 | 7/27/2020 |
| 1.0.0-preview1 | 2,489 | 7/26/2020 |
- Targetframeworks updated
Release notes: https://github.com/LazZiya/XLocalizer.Translate/releases