Localize a component in another assembly - Updated
Kasrak
26
Reputation points
Updated all the question, reformed and posted the new code here:
I tried 2 approaches at the same time to find out how I can localize my component which is located in a different assembly.
Folder/ Files architecture:
Index (Usage in the Main project)
@page "/"
<Component1 />
Component1:
@inject IStringLocalizer<Component1> Loc
@namespace OurComponents
<div class="my-component">
<span>@Loc["stLink"]</span>
</div>
Startup file:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new List<CultureInfo>()
{ new CultureInfo("en-US") };
options.DefaultRequestCulture = new RequestCulture("en-US");
options.SetDefaultCulture("en-US");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures; ;
});
services.AddRazorPages();
services.AddServerSideBlazor();
}
Namespaces are imported globally.
Currently @Loc ["stLink"] doesn't get the info from any of the defined resources.
Source Code:
Note: Basic localization is working fine, just can't localize the components in the library assembly.
Sign in to answer