I'm using localization for my API application. The problem is, everything work well on local machine, but when I deployed the application on Azure, localization doesn't work anymore.
Here is the result when requesting on debugging (the message is translated):
{
"status": "NotFound",
"timestamp": "2021-05-05T03:31:10Z",
"code": "R001",
"message": "Customer order was not found!"
}
Here is the result when requesting on production (the message is dispalyed as key - R001, not translation value):
{
"status": "NotFound",
"timestamp": "2021-05-05T03:29:04Z",
"code": "R001",
"message": "R001"
}
I can't figure out what's wrong.
The prject hierarchy is as following: enter image description here
My CustomerOrder/Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
...
// Localization service
services.AddLocalization(options => options.ResourcesPath = "Resources")
.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
// adding culture
var supportedCultures = new List<CultureInfo>
{
new CultureInfo("fr"),
new CultureInfo("fr-FR"),
new CultureInfo("en"),
new CultureInfo("en-US")
};
var localizationOptions = new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en"),
// formatted numbers, dates, etc
SupportedCultures = supportedCultures,
// UI strings that we have localized
SupportedUICultures = supportedCultures,
};
app.UseRequestLocalization(localizationOptions);
}
How I use localization in my controller
...
private readonly IStringLocalizer<CustomerOrdersController> _localizer;
...
_localizer["R001"]
Task on azure-pipelines
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '$(build.sourcesDirectory)/src/$(projectName)/$(projectName).csproj'
arguments: '-c "$(buildConfiguration)" -f "netcoreapp3.1" -r "ubuntu.19.10-x64"'