This app helps you generate translated .cshtml
files and resources
files.
Requirements:
Run the following command to install this tool:
dotnet tool install --global Aiursoft.Dotlang
- Find all files ends with
.cshtml
- foreach
cshtml
file, replace all text in tag sround with@Localizer[""]
- Call bing translate API to translate all those content
- Save the translated file as
Resource
file in theResources
folder.
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.
Build:
dotnet pack
Install:
dotnet tool install --global --add-source ./nupkg dotlang
Run:
# In your project folder
$ dotlang
Uninstall:
dotnet tool uninstall -g dotlang
- 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!
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.