Aiursoft.Dotlang
10.0.35
dotnet tool install --global Aiursoft.Dotlang --version 10.0.35
dotnet new tool-manifest
dotnet tool install --local Aiursoft.Dotlang --version 10.0.35
#tool dotnet:?package=Aiursoft.Dotlang&version=10.0.35
nuke :add-package Aiursoft.Dotlang --version 10.0.35
ASP.NET Core App Translator
This app helps you generate translated .cshtml files and resources files. Based on the Ollama AI model, it translates the content inside @Localizer[""] tags in your ASP.NET Core project.
Installation
Requirements:
Run the following command to install this tool:
dotnet tool install --global Aiursoft.Dotlang
Usage
After getting the binary, run it directly in the terminal.
dotlang translate-aspnet --path ~/Code --instance http://ollama:11434/api/chat --model "qwen:32b" --token "your-ollama-token"
Description:
The command to start translation on an ASP.NET Core project.
Usage:
dotlang translate-aspnet [options]
Options:
-v, --verbose Show detailed log
-d, --dry-run Preview changes without actually making them
-p, --path <path> (REQUIRED) Path of the videos to be parsed.
-l, --languages <languages> (REQUIRED) The target languages code. Connect with ','. For example: zh_CN,en_US,ja_JP [default:
zh-CN,zh-TW,zh-HK,ja-JP,ko-KR,vi-VN,th-TH,de-DE,fr-FR,es-ES,ru-RU,it-IT,pt-PT,pt-BR,ar-SA,nl-NL,sv-SE,pl-PL,tr-TR]
--instance <instance> (REQUIRED) The Ollama instance to use.
--model <model> (REQUIRED) The Ollama model to use.
--token <token> (REQUIRED) The Ollama token to use.
-?, -h, --help Show help and usage information
For example, if you want to localize entire project with deepseek, you can run:
DEEPSEEK_API_KEY="sk-aaaaaaaa"
dotlang auto-generate-view-injections-for-aiursoft-template --path .
dotlang generate-resx-csharp --path . --model "deepseek-chat" --token $DEEPSEEK_API_KEY --instance "https://api.deepseek.com/chat/completions" -c 8
dotlang generate-resx-view --path . --model "deepseek-chat" --token $DEEPSEEK_API_KEY --instance "https://api.deepseek.com/chat/completions" -c 8
dotlang generate-resx-annotations --path . --model "deepseek-chat" --token $DEEPSEEK_API_KEY --instance "https://api.deepseek.com/chat/completions" -c 8
For example, if you want to localize entire project with Aiursoft Ollama server, you can run:
OLLAMA_API_KEY="CONFIDENTIAL"
dotlang auto-generate-view-injections-for-aiursoft-template --path .
dotlang generate-resx-csharp --path . --model "qwen3.5:27b-q8_0" --token $OLLAMA_API_KEY --instance "https://ollama.aiursoft.com/api/chat/completions" -c 8
dotlang generate-resx-view --path . --model "qwen3.5:27b-q8_0" --token $OLLAMA_API_KEY --instance "https://ollama.aiursoft.com/api/chat/completions" -c 8
dotlang generate-resx-annotations --path . --model "qwen3.5:27b-q8_0" --token $OLLAMA_API_KEY --instance "https://ollama.aiursoft.com/api/chat/completions" -c 8
Will help you generate .resx files for all the .cshtml files in the current folder.
Use as a simple translator
This tool can also be used to simply translate a folder of files from one language to another.
dotlang folder-translate --source "./src" --destination "./dist" --language "zh-CN" --extensions "txt" --extensions "md" --recursive --model "qwen:32b" --token "your-ollama-token" --instance "http://ollama:11434/api/chat"
Options:
-s,--source(REQUIRED): Path of the folder to translate files.-d,--destination(REQUIRED): Path of the folder to save translated files.-l,--language(REQUIRED): The target language code.-r,--recursive: Recursively search for files in subdirectories.-e,--extensions: Extensions of files to translate. Can be used multiple times. Default ishtml.--instance: The Ollama instance to use.--model: The Ollama model to use.--token: The Ollama token to use.-k,--skip-existing-files: Skip existing files.
Auto-generate View Injections
This command scans your project for localizable strings in Controllers and ViewModels, specifically looking for:
[RenderInNavBar]attributes (properties:NavGroupName,CascadedLinksGroupName,LinkText)PageTitleassignments in ViewModels (e.g.,PageTitle = "Dashboard")
It then injects these strings into a ViewModelArgsInjector service to ensure they can be picked up by the localizer.
dotlang auto-generate-view-injections-for-aiursoft-template --path .
Use as a library
You can also use the core logic as a library in your own project.
First, install the package:
dotnet add package Aiursoft.Dotlang.AspNetTranslate
Then, register the services in your IServiceCollection:
using Aiursoft.Dotlang.AspNetTranslate;
using Aiursoft.Dotlang.Shared;
using Aiursoft.Canon;
using Aiursoft.GptClient;
// ...
services.AddLogging();
services.AddHttpClient();
services.AddMemoryCache();
services.AddTaskCanon();
services.AddGptClient();
services.AddScoped<MarkdownShredder>();
services.AddScoped<OllamaBasedTranslatorEngine>();
services.AddScoped<CachedTranslateEngine>();
services.AddScoped<FolderFilesTranslateEngine>();
services.AddScoped<TranslateEntry>();
// Add necessary specialized services for TranslateEntry
services.AddScoped<DataAnnotationKeyExtractor>();
services.AddScoped<CshtmlLocalizer>();
services.AddScoped<CSharpKeyExtractor>();
services.AddScoped<ViewMetadataExtractor>();
services.AddTransient<DocumentAnalyser>();
new StartUp().ConfigureServices(services);
services.Configure<TranslateOptions>(options =>
{
options.OllamaInstance = "https://ollama.example.com/api/chat/completions";
options.OllamaModel = "qwen3:30b";
options.OllamaToken = "your-token";
});
Finally, you can use TranslateEntry to perform translation tasks:
var entry = serviceProvider.GetRequiredService<TranslateEntry>();
Or use FolderFilesTranslateEngine for simple file translation:
var folderEngine = serviceProvider.GetRequiredService<FolderFilesTranslateEngine>();
await folderEngine.TranslateAsync(
sourceFolder: "./src",
destinationFolder: "./dist",
language: "zh-CN",
recursive: true,
extensions: [".txt", ".md"],
skipExistingFiles: false);
Translate plain text
You can also use the OllamaBasedTranslatorEngine to translate plain text strings directly.
var translator = serviceProvider.GetRequiredService<OllamaBasedTranslatorEngine>();
var englishText = "Hello, world!";
var chineseText = await translator.TranslateAsync(englishText, "zh-CN");
Console.WriteLine(chineseText); // 你好,世界!
Advanced Usage with TranslateEntry
var entry = serviceProvider.GetRequiredService<TranslateEntry>();
// Localize all .cshtml files in a project
await entry.StartLocalizeContentInCsHtmlAsync(
path: "./MyProject",
langs: ["zh-CN", "ja-JP"],
takeAction: true,
concurentRequests: 8);
// Localize all .cs files
await entry.StartLocalizeContentInCSharpAsync(path, langs, true, 8);
// Localize DataAnnotations
await entry.StartLocalizeDataAnnotationsAsync(path, langs, true, 8);
// Wrap plain text with @Localizer[""]
await entry.StartWrapWithLocalizerAsync(path, true);
Run locally
Requirements about how to run
- .NET 10 SDK
- Ollama.
- Execute
dotnet runto run the app
Run in Microsoft Visual Studio
- Open the
.slnfile in the project path. - Press
F5.
How does this work?
- Find all files ends with
.cshtml. - foreach
cshtmlfile, replace all text in tag surrounded with@Localizer[""]with the content inside. - Call ollama to translate all the content. (The entire file will be sent to ollama to make sure AI understands the context.)
- Save the translated file as
Resourcefile in theResourcesfolder.
The Core Translator won't override any existing translation nor resources files. If your content was already surrounded with @Localizer[""], we won't touch it.
Before running the translator
- Follow the document here ASP.NET Core Localization
Use the following code to register the localizer service:
// In StartUp.cs ConfigureServices method:
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
Use the following code to add localizer middleware:
// In StartUp.cs Configure method
var SupportedCultures = new CultureInfo[]
{
new CultureInfo("en"),
new CultureInfo("zh")
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture(defaultLanguage),
SupportedCultures = SupportedCultures,
SupportedUICultures = SupportedCultures
});
Use the following code to inject localizer:
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Now run this app!
Caution
Running this under your project folder may ruin your project! It may change your cshtml! Do run git commit under your project before running this app.
How to contribute
There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.
Even if you with push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.
We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.35 | 27 | 3/14/2026 |
| 10.0.34 | 79 | 3/9/2026 |
| 10.0.33 | 76 | 3/9/2026 |
| 10.0.32 | 83 | 3/8/2026 |
| 10.0.31 | 93 | 2/28/2026 |
| 10.0.30 | 103 | 2/13/2026 |
| 10.0.29 | 105 | 2/11/2026 |
| 10.0.28 | 101 | 2/11/2026 |
| 10.0.27 | 114 | 1/28/2026 |
| 10.0.26 | 111 | 1/24/2026 |
| 10.0.25 | 108 | 1/19/2026 |
| 10.0.24 | 122 | 1/18/2026 |
| 10.0.23 | 110 | 1/15/2026 |
| 10.0.21 | 107 | 1/15/2026 |
| 10.0.20 | 108 | 1/15/2026 |
| 10.0.18 | 103 | 1/14/2026 |
| 10.0.17 | 112 | 1/14/2026 |
| 10.0.16 | 105 | 1/11/2026 |
| 10.0.15 | 118 | 1/11/2026 |
| 10.0.14 | 108 | 1/10/2026 |