How do I know which languages the program supports? #577
-
My application supports multi-language switching, but I can't translate all the languages, users or other developers can translate them by themselves and generate xx-YY/app.resource.dll file and put it in the root directory of the application, and I want to be able to fetch the loaded language resource files when the application starts, so that I can select and switch between these languages. |
Beta Was this translation helpful? Give feedback.
Answered by
CodingOctocat
Aug 6, 2023
Replies: 1 comment
-
I found solution from SO: public static List<CultureInfo> GetAvailableCultures()
{
var result = new List<CultureInfo>() { new("zh-CN") };
var rm = new ResourceManager(typeof(Lang));
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (var culture in cultures)
{
try
{
// Do not use "==", won't work.
if (culture.Equals(CultureInfo.InvariantCulture))
{
continue;
}
using var rs = rm.GetResourceSet(culture, true, false);
if (rs is not null)
{
result.Add(culture);
}
}
catch (CultureNotFoundException)
{
// NOP.
}
}
return result;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
CodingOctocat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found solution from SO: