/// <summary> /// Get all strings. /// </summary> /// <param name="culture">Culture to get prompts for</param> /// <returns>A colleciton of prompts (or an empty collection)</returns> public virtual IEnumerable <TypePrompt> GetPrompts(CultureInfo culture) { if (culture == null) { throw new ArgumentNullException("culture"); } var prompts = new List <TypePrompt>(); var baseAttribte = typeof(ValidationAttribute); var attributes = typeof(RequiredAttribute).Assembly.GetTypes().Where( p => baseAttribte.IsAssignableFrom(p) && !p.IsAbstract).ToList(); foreach (var type in attributes) { var key = new TypePromptKey(type.FullName, "class"); var typePrompt = new TypePrompt { Key = key, LocaleId = CultureInfo.CurrentUICulture.LCID, TypeFullName = type.FullName, TextName = "class", UpdatedAt = DateTime.Now, UpdatedBy = Thread.CurrentPrincipal.Identity.Name }; var value = GetString(type, culture); if (value != null) { typePrompt.TranslatedText = DefaultUICulture.IsActive ? value : ""; } prompts.Add(typePrompt); } return(prompts); }
/// <summary> /// Translate a string /// </summary> /// <param name="type">Model being translated</param> /// <param name="name">Property name (or <c>propertyName_metadataName</c>)</param> /// <returns></returns> protected virtual string Translate(Type type, string name) { if (type == null) { throw new ArgumentNullException("type"); } if (name == null) { throw new ArgumentNullException("name"); } if (!string.IsNullOrEmpty(type.Namespace) && (type.Namespace.StartsWith("Griffin.MvcContrib") && !type.Namespace.Contains("TestProject"))) { return(null); } var key = new TypePromptKey(type.FullName, name); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key) ?? _repository.GetPrompt(CultureInfo.CurrentUICulture, new TypePromptKey(typeof(CommonPrompts).FullName, name)); if (prompt == null) { _repository.Save(CultureInfo.CurrentUICulture, type.FullName, name, ""); } else { if (!string.IsNullOrEmpty(prompt.TranslatedText)) { return(prompt.TranslatedText); } } return(name.EndsWith("NullDisplayText") ? "" : null); }