1 year ago
#388876
MadHenchbot
.NET Multi-language support for unsupported ISO 639-2 cultures
I am currently developing an ASP.NET 4.8 MVC single-page application that is expected to support multiple languages. From various resources, I found that one way to accomplish this is through the use of App_GlobalResources
and resource files for each supported language.
I added some navigation links to my page that update the thread's current culture info, which pulls those language resources into my application.
var cultureInfo = CultureInfo.GetCultures(CultureTypes.AllCultures)
.FirstOrDefault(x => x.ThreeLetterISOLanguageName == language);
if (cultureInfo == null)
cultureInfo = CultureInfo.GetCultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
This appears to work fine for languages that have culture support. (IE: "eng" pulls back en-us
and finds the Content.en.resx
file, "spa" retrieves Content.es.resx
, etc.) But I'm running into difficulty where the languages appear in the ISO639-2 list (Hmong, Karen) but don't have CultureInfo associated with them.
I've tried spinning off Cultures for these using CultureAndRegionInfoBuilder
, but from my understanding, this will only work on my computer, and not on the web. I'm also not able to 'hack' an existing Culture -- ie, taking Vietnamese and replacing its ThreeLetterISOLanguageName
and other properties -- because those properties are readonly.
Is there an explicit way to tell my code to reference a specific content file when CultureInfo is not available? Or am I going about this the entirely wrong way?
c#
asp.net-mvc
multilingual
cultureinfo
.net-4.8
0 Answers
Your Answer