using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Globalization; using System.Linq; using System.Threading; using System.Web; using Resources; namespace Weee.Models { public abstract class MultiLanguage { [NotMapped] [Display(Name = "DisplayName", ResourceType = typeof(Resource))] public string DisplayName { get { //hack !!... 原來多語系是按照CultureInfo("zh-CN")之類方式處置 if (Thread.CurrentThread.CurrentUICulture.LCID == new CultureInfo("zh-CN").LCID) { return string.IsNullOrEmpty(DisplayNameCN) ? DisplayNameTW : DisplayNameCN; } else if (Thread.CurrentThread.CurrentUICulture.LCID == new CultureInfo("en-US").LCID) { return string.IsNullOrEmpty(DisplayNameEN) ? DisplayNameTW : DisplayNameEN; } return DisplayNameTW; } } [Required(ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "RequiredMessage")] [StringLength(200, ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "MaxLengthMessage200")] [Display(Name = "MultiLanguageDisplayNameTW", ResourceType = typeof(Resource))] public string DisplayNameTW { get; set; } [Display(Name = "MultiLanguageDisplayNameCN", ResourceType = typeof(Resource))] public string DisplayNameCN { get; set; } [Display(Name = "MultiLanguageDisplayNameEN", ResourceType = typeof(Resource))] public string DisplayNameEN { get; set; } } }