Skip to content

How do I know which languages the program supports? #577

Closed Answered by CodingOctocat
CodingOctocat asked this question in Q&A
Discussion options

You must be logged in to vote

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 (CultureNotFoundE…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by CodingOctocat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant