3ai.solutions.Translator 8.8769.16

dotnet add package 3ai.solutions.Translator --version 8.8769.16
NuGet\Install-Package 3ai.solutions.Translator -Version 8.8769.16
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="3ai.solutions.Translator" Version="8.8769.16" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add 3ai.solutions.Translator --version 8.8769.16
#r "nuget: 3ai.solutions.Translator, 8.8769.16"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install 3ai.solutions.Translator as a Cake Addin
#addin nuget:?package=3ai.solutions.Translator&version=8.8769.16

// Install 3ai.solutions.Translator as a Cake Tool
#tool nuget:?package=3ai.solutions.Translator&version=8.8769.16

3ai.solutions.Translator

Dependancy Injection

builder.Services.AddTranslationService<ImplementedITranslationRepository>();

Database

Create entities for Translation and TranslationName, note that you will need some sort of entity for your language selection

private static void CreateSystemModels(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Language>(e =>
    {
        e.ToTable("SYS_Languages");
        e.HasData(new Language() { Id = 1, Code = "en-gb", Name = "English", IsActive = true },
                    new Language() { Id = 2, Code = "el-gr", Name = "Ελληνικά", IsActive = true }
            );
    });

    modelBuilder.Entity<Translation>(e =>
    {
        e.ToTable("SYS_Translation");
        e.HasKey(p => new { p.ForeignId, p.LanguageId, p.KeyId });
        e.HasOne<Language>().WithMany().HasForeignKey(p => p.LanguageId).IsRequired();
    });

    modelBuilder.Entity<TranslationName>(e =>
    {
        e.ToTable("SYS_TranslationName");
        e.HasKey(p => p.KeyId);
        e.Property(x => x.KeyId).ValueGeneratedNever();
        List<TranslationName> data = new();
        data.AddRange(TranslationService.GetTransltionNames<Models.Content.Topic>());
        data.AddRange(TranslationService.GetTransltionNames<Models.Content.Menu>());
        e.HasData(data);
    });
}

Sample Service

public class SampleService
{
    private readonly IMemoryCache memoryCache;
    private readonly TranslationService translationService;
    private readonly SampleContext context;

    public SampleService(TranslationService translationService, SampleContext context,
                         IMemoryCache memoryCache)
    {
        this.memoryCache = memoryCache;
        this.translationService = translationService;
        this.context = context;
    }

    //Simple cache example
    public async Task<List<Item>> GetCachedTranslatedItemsAsync()
    {
        var items = await memoryCache.GetOrCreateAsync("items", async entry =>
        {
            entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5);
            return await context.Items.ToListAsync();
        }) ?? new();
        return await translationService.GetTranslatedAsync(items, languageId: 1, newItem: true);
    }

    public async Task<List<Item>> GetCachedTranslatedItemsAsync(int languageId = 1)
    {
        return = await memoryCache.GetOrCreateAsync($"items:{languageId}", async entry =>
        {
            entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5);
            if (languageId == 1)
                return await context.Items.ToListAsync();
            else
                return await translationService.GetTranslatedAsync(await GetCachedTranslatedItemsAsync(),
                                                                   languageId: languageId, newItem: true);
        }) ?? new();
    }

    //Returns items translated into specified language,
    //please note that languageId 1 is reserved for the default language
    public async Task<List<Item>> GetTranslatedItemsAsync(List<Item> items)
    {
        return await translationService.GetTranslatedAsync(items, languageId: 1, newItem: true);
    }

    //Creates entries with the name of the property and it's keyId
    public async Task CreateTranslationNamesAsync()
    {
        await translationService.SaveTransltionNamesAsync<Item>();
    }

    //Returns properties of Item which can be translated
    public List<Translation> GetTranslatableItemsOfItem(Item item)
    {
        return TranslationService.GetTranslatableItems(item);
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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. 
.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 was computed. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.8769.16 172 1/4/2024
7.8692.19 224 10/19/2023
7.8681.19 128 10/8/2023
7.8661.12 123 9/18/2023
7.8658.12 117 9/15/2023
7.8658.10 101 9/15/2023
7.8657.15 131 9/14/2023
7.8654.10 127 9/11/2023
2.8397.15 298 12/28/2022
2.8289.10 448 9/11/2022
2.8230.21 496 7/14/2022
1.0.0 513 2/4/2022