I have set it up for localization as follows:
Set the neutralLanguage for the project,
// .csproj
<NeutralLanguage>ko-KR</NeutralLanguage>
Registered localization services into the service container,
// program.cs
builder.Services.AddLocalization(options =>
{
options.ResourcesPath = "Resources";
}) ;
...
app.UseRequestLocalization(new RequestLocalizationOptions()
.AddSupportedCultures(new[] { "ko-KR", "en-US" })
.AddSupportedUICultures(new[] { "ko-KR", "en-US"}));
...
Created a .resx file in ~\Resource directory with VS 2022, which created .Designer.cs in the directory as per to my configuration
//~\Resources
UIStrings.resx
UIStrings.Designer.cs
Added a string resource into UIStrings.resx, for example:
Name : "이름"
FYI, "이름" is Korean for English "name".
and, I am seeing the below result:
// .razor
...
@inject IStringLocalizer<UIStrings> Localizer
...
@UIStrings.Name // prints "이름"
@UIStrings.ResourceManager.GetString("Name") // prints "이름"
@Localizer["Name"] // prints "Name" <= not good
I don't know why IStringLocalizer doesn't work.
I tried some code and found how
IStringLocalizer<T>behaves and how it differs from the behavior ofResourceManager.The failure of my question was from different file-location behavior of
IStringLocalizer.All relevant comments are added between code shown here:
The project folder structure is: