Reputation: 307
I am working on a globalization project using .resx resourse files. I have some fallback logic in case the language that the user selected doesn't have a resx file. Is there a way to find a culture that has the same language but a different region than a supplied culture?
Upvotes: 1
Views: 144
Reputation: 73442
If I understand you correctly then you're looking for something like cultures with same languages
var culture = new CultureInfo("fr");
var sameLanguageCultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures)
.Where(x => x.ThreeLetterISOLanguageName == culture.ThreeLetterISOLanguageName && x.Name != culture.Name)
.ToArray();
foreach (var c in sameLanguageCultures)
{
Console.WriteLine(c.Name);
}
this will output
fr-FR fr-BE fr-CA fr-CH fr-LU fr-MC
Make it clear if am wrong.
Upvotes: 1
Reputation: 56536
Resources that are specific to a language, but not to a specific culture, should be in their own file, e.g. if you have the following resource files:
Resources.resx
Resources.en.resx
Resources.fr.resx
Resources.fr-FR.resx
(language-invariant strings in Resources.resx
, French strings in Resources.fr.resx
, and France-specific French strings in Resources.fr-FR.resx
)
And the user's culture is fr-CA
(Canadian French), then it will use resources from the following files, in this order:
Resources.fr.resx
Resources.resx
This is the default resource behavior.
Upvotes: 3