Can we make an enumeration multilingual in asp.net using c #

I am working on a multilingual site and in which I used enumeration, and now it may be possible that we can enumerate abstracts in accordance with the multilingual language?

My listing structure

public enum abc { [Description{"multilingual text"}] StatucActive = 1 } 

like this. I want to write multilingual text in the description.

+4
source share
3 answers

No, we cannot use the enumeration as multilingual, but I have an alternative that uses a resource file that works like a rename in some situations.

try the resource file and it will solve your problem ....

+1
source

You must follow these steps:

(1) prepare resource files, for example. resource.en-US.resx / resource.zh-CN.resx / etc .. Each resource file has keys and values, their keys are the same between files, the values ​​are different in languages.

(2) define your own DescriptionAttribute , something like this:

 public class LocalDescriptionAttribute : DescriptionAttribute { public string ResourceKey { get; set; } public string CultureCode { get; set; } //you can set a default value of CultureCode //so that you needn't set it everywhere public override string Description { get { //core of this attribute //first find the corresponding resource file by CultureCode //and then get the description text by the ResourceKey } } } 

Using:

 public enum MyTexts { [LocalDescription(CultureCode="zh-CN", ResourceKey="Title")] Title = 0, [LocalDescription(ResourceKey="Status")] //default CultureCode Status = 1 } 
+5
source

An easy way to list an enumeration is to create an array of values ​​for each language you want.

String language1 [] = {"value", "value2"};

String language2 [] = {"different value", "different value2"};

String multi = language2 [enumvalue];

Your enumeration value will become an index for your string translation array.

0
source

All Articles