C
C#16mo ago
alkasel#159

✅ .NET Localization Culture Fallback

Hi, I'm using .NET localization in a blazor wasm hosted app, and I have the following issue: Let's consider the generic class myclass, for which I have the following files: myclass.razor myclass.razor.cs myclass.en.resx (english translations) myclass.it.resx (italian translations) Now, if I access the web app by means of a browser with culture set to "en", the english translations are displayed correctly. In fact, from developer tools I can see the request http://.../_framework/en/Client.resources.dll, which is answered with a 200 OK containing some data as response. If then I set the browser culture to "en-US", no term is translated. In fact I see browser is making the following requests: http://.../_framework/en-US/Client.resources.dll http://.../_framework/en/Client.resources.dll Both of which are answerede with a 304 Not Modified. I've tested on Firefox and Edge: the behavior is the same. This is strange because the documentation describes a "Culture fallback" mechanism that should make the above scenario work. Any idea what I could be doing wrong? Thanks
Localization - .NET
Learn the concepts of localization while learning how to use the IStringLocalizer and IStringLocalizerFactory implementations in your .NET workloads.
1 Reply
alkasel#159
alkasel#15916mo ago
So, I found a first problem: I have some myclass.en-us.resx files left from some older experiment. That's why the browser was able to find http://.../_framework/en-US/Client.resources.dll as well. Now I've deleted all myclass.en-us files and the browser just fetch http://.../_framework/en/Client.resources.dll even when it's language is set to en-us. However, terms are still not translated (they are when I set browser language to en, instead) In the end I solved it, even if I'm not sure how: the main thing I changed is that I found in Client configuration the entry Assembly Neutral Language set to "en-us". I changed to "none" and now the fallback works fine