none
How to apply multiLanguage for enum? RRS feed

  • Question

  • Hi 

    I want to apply multiLanguage ( zh-CN, en-US) form a enum. How to chang the language showing of a enum, like following showing, when UI cultureInfor changing?

    public enum Style
            {
                Transient,
                Toggle,
                Set,
                Reset,
                LongPress,
                Delay
            }
    
    
    public Style mStyle { get; set;}

    Thanks

    ming


    Monday, September 30, 2019 3:10 AM

All replies

  • Hi,

    You can refer to the following code to traverse the resx file to get the corresponding language.

        List<string> filelist = new List<string>();
        private void button2_Click(object sender, EventArgs e)
        {
            filelist.Clear();
    
            DirectoryInfo TheFolder = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + @"../../");
            foreach (FileInfo NextFile in TheFolder.GetFiles())
            {
                if (NextFile.Name.EndsWith(".resx") && NextFile.Name.Split('.').Length > 2)
                {
                    filelist.Add(NextFile.Name.Split('.')[1]);
                }
            }
        }

    If you want to create an Enum dynamically, you can try to use "EnumBuilder". Here is the reference document.

    EnumBuilder Class

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 30, 2019 6:11 AM
    Moderator