1

I am implementing the localization for a Blazor WebAssembly app. and everything works fine with one .resx file. However, I am wondering if it is possible to use multiple .resx for same language, I tried to look in the documentation but it is somehow not mentioned anywhere, and all tutotial or documentation end-up calling the unique resource with:

@inject IStringLocalizer<LocalizationRes> _L

So, is it possible to use multiple .resx for the same language?if yes, how the IStringLocalizer should be used in that case ?

Thank you

2
  • Do you mean one .resx file per component/page for a particular language? I don't see a reason why one would need multiple .resx files for one language (if we are talking about localizing a particular component/page). Commented Sep 13, 2022 at 0:56
  • Hi, No, I am talking about multiple .resx of the same language for a particular language of the full app. Commented Sep 13, 2022 at 7:25

1 Answer 1

1

You can use multiple Resx files for same language, and distribute them along your project structure. i.e. if you have a folder structure like this

MainFolder
..Cats
....Cats.razor.cs
....Cats.razor
Resources
..Cats
....Cats.en.resx <- english resource
....Cats.es.resx <- spanish resource

in your injection you should use as following:

@inject Microsoft.Extensions.Localization.IStringLocalizer _localizer

to use you implement as i.e.:

<TitleComponent Title="@_localizer["Cats"]" Description="@_localizer["All your Cats."]" />

in the resx you should provide a translation for each implementation and once you propagate the culture change in your app it will take the correct resx file.

_localizer["Cats"].

this to support more than one language, to have multiple files of the same language just apply the same structure along your project i.e.

MainFolder
..Cats
....Cats.razor.cs
....Cats.razor
..Dogs
....Dogs.razor.cs
....Dogs.razor
Resources
..Cats
....Cats.en.resx <- english resource
....Cats.es.resx <- spanish resource
..Dogs
....Dogs.en.resx
....Dogs.es.resx
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer but this is not what I am looking for, I am looking to use multiple .resx for the same language for the full app. I am not looking to localize each webpage separately.
@Raziel : Did you had any luck with finding an answer? I'm running into similar issue with Blazor where I want single global .resx file per language and not per page bases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.