/// <summary> /// Delete a prompt. /// </summary> /// <param name="culture">Culture to delete prompt in</param> /// <param name="key">Prompt key</param> public void Delete(CultureInfo culture, TypePromptKey key) { var lang = GetLanguage(culture); lang.Delete(key); SaveLanguage(culture, lang); }
/// <summary> /// Update translation /// </summary> /// <param name="culture"> Culture that the prompt is for </param> /// <param name="key"> Unique key, in the specified language only, for the prompt to get) </param> /// <param name="translatedText"> Translated text string </param> public void Update(CultureInfo culture, TypePromptKey key, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (key == null) { throw new ArgumentNullException("key"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } var sql = "UPDATE LocalizedTypes SET Value=@value, UpdatedAt=@updat, UpdatedBy=@updby WHERE LocaleId = @lcid AND [Key] = @key"; using (var cmd = _db.Connection.CreateCommand()) { cmd.CommandText = sql; cmd.AddParameter("value", translatedText); cmd.AddParameter("updat", DateTime.Now); cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name); cmd.AddParameter("lcid", culture.LCID); cmd.AddParameter("key", key.ToString()); cmd.ExecuteNonQuery(); } }
/// <summary> /// Create or update a prompt /// </summary> /// <param name="culture">Culture that the prompt is for</param> /// <param name="fullTypeName">Type.FullName for the type being localized</param> /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param> /// <param name="translatedText">Translated text string</param> public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (fullTypeName == null) { throw new ArgumentNullException("fullTypeName"); } if (name == null) { throw new ArgumentNullException("name"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } if (fullTypeName.IndexOf(".") == -1) { throw new ArgumentException("You must use Type.FullName", "fullTypeName"); } var key = new TypePromptKey(fullTypeName, name); if (!Exists(culture, key)) { Create(culture, fullTypeName, name, translatedText); } else { Update(culture, key, translatedText); } }
/// <summary> /// Updates the specified culture. /// </summary> /// <param name="culture">The culture.</param> /// <param name="key">The key.</param> /// <param name="translatedText">The translated text.</param> public void Update(CultureInfo culture, TypePromptKey key, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (key == null) { throw new ArgumentNullException("key"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } var language = GetOrCreateLanguage(culture); var prompt = (from p in language.Prompts where p.LocaleId == culture.LCID && p.TextKey == key.ToString() select p).FirstOrDefault(); if (prompt == null) { throw new InvalidOperationException("Prompt " + key + " do not exist."); } prompt.Text = translatedText; _logger.Debug("Updating text for " + prompt.TypeName + "." + prompt.TextName + " to " + translatedText); _documentSession.Store(language); _documentSession.SaveChanges(); }
public void Update(CultureInfo cultureInfo, TypePromptKey key, string translatedText) { var localizedType = getLocalizedType(cultureInfo, key); localizedType.Update(key, translatedText, cultureInfo); _Context.Save(); }
public void Update() { var key = new TypePromptKey(typeof(TestType).FullName, "FirstName"); _repository.Update(new CultureInfo(1053), key, "Förrenammne"); var prompt = _repository.GetPrompt(new CultureInfo(1053), key); Assert.Null(prompt); }
public ActionResult Delete(string id) { var key = new TypePromptKey(id); _repository.Delete(CultureInfo.CurrentUICulture, key); return(RedirectToAction("Index")); }
public void Delete(CultureInfo culture, TypePromptKey key) { var lt = getLocalizedType(culture, key); _Set.Remove(lt); _Context.Save(); }
public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (fullTypeName == null) { throw new ArgumentNullException("fullTypeName"); } if (name == null) { throw new ArgumentNullException("name"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } if (fullTypeName.IndexOf(".") == -1) { throw new ArgumentException("You must use Type.FullName", "fullTypeName"); } var key = new TypePromptKey(fullTypeName, name); // _Context.Save() is done inside "add" and Update "methods" if (getLocalizedType(culture, key) == null) { add(culture, fullTypeName, name, translatedText); } else { Update(culture, key, translatedText); } }
/// <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> /// Get a specific prompt /// </summary> /// <param name="culture">Culture to get prompt for</param> /// <param name="key">Key which is unique in the current language</param> /// <returns> /// Prompt if found; otherwise <c>null</c>. /// </returns> public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key) { var language = GetOrCreateLanguage(culture); return((from p in language.Prompts where p.LocaleId == culture.LCID && p.TextKey == key.ToString() select CreateTextPrompt(p)).FirstOrDefault()); }
public void DeletePrompt(TypePromptKey key) { if (key == null) { throw new ArgumentNullException("key"); } Prompts.RemoveAll(k => k.TextKey == key.ToString()); }
/// <summary> /// Get a prompt /// </summary> /// <param name="id">Prompt id</param> /// <returns>prompt if found; otherwise null</returns> public TypePrompt Get(TypePromptKey id) { if (id == null) { throw new ArgumentNullException("id"); } return(_prompts.FirstOrDefault(p => p.Key == id)); }
/// <summary> /// Delete prompt with the specified key /// </summary> /// <param name="key">key</param> public void Delete(TypePromptKey key) { if (key == null) { throw new ArgumentNullException("key"); } _prompts.RemoveAll(k => k.Key == key); }
public void GetExisting() { var key = new TypePromptKey(typeof(TestType).FullName, "FirstName"); _repository.Save(new CultureInfo(1053), typeof (TestType).FullName, "FirstName", "Förnamn"); var prompt = _repository.GetPrompt(new CultureInfo(1053), key); Assert.NotNull(prompt); Assert.Equal("Förnamn", prompt.TranslatedText); }
public void Update() { var key = new TypePromptKey(typeof(TestType).FullName, "FirstName"); _repository.Update(new CultureInfo(1053), key, "Förrenammne"); var prompt = _repository.GetPrompt(new CultureInfo(1053), key); Assert.IsNull(prompt); }
public ActionResult MakeCommon(string id) { var key = new TypePromptKey(id); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); prompt.TypeFullName = typeof(CommonPrompts).FullName; _repository.Save(CultureInfo.CurrentUICulture, typeof(CommonPrompts).FullName, prompt.TextName, prompt.TranslatedText); _repository.Delete(CultureInfo.CurrentUICulture, key); return RedirectToAction("Index"); }
public void Save() { var key = new TypePromptKey(typeof(TestType).FullName, "FirstName"); _repository.Save(new CultureInfo(1053), typeof(TestType).FullName, "FirstName", "Förrenammne"); var prompt = _repository.GetPrompt(new CultureInfo(1053), key); Assert.IsNotNull(prompt); Assert.AreEqual("Förrenammne", prompt.TranslatedText); }
public ActionResult MakeCommon(string id) { var key = new TypePromptKey(id); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); prompt.TypeFullName = typeof(CommonPrompts).FullName; _repository.Save(CultureInfo.CurrentUICulture, typeof(CommonPrompts).FullName, prompt.TextName, prompt.TranslatedText); _repository.Delete(CultureInfo.CurrentUICulture, key); return(RedirectToAction("Index")); }
/// <summary> /// Initializes a new instance of the <see cref="TypePromptDocument"/> class. /// </summary> /// <param name="key">The key.</param> /// <param name="modelType">Type of the model.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="culture">The culture.</param> public TypePromptDocument(TypePromptKey key, Type modelType, string propertyName, CultureInfo culture) { if (key == null) throw new ArgumentNullException("key"); if (modelType == null) throw new ArgumentNullException("modelType"); if (propertyName == null) throw new ArgumentNullException("propertyName"); TextKey = key.ToString(); FullTypeName = modelType.FullName; TypeName = modelType.Name; TextName = propertyName; LocaleId = culture.LCID; }
private bool Exists(CultureInfo culture, TypePromptKey key) { var sql = @"SELECT count(Id) FROM LocalizedTypes WHERE LocaleId = @lcid AND [Key] = @key"; using (var cmd = _db.Connection.CreateCommand()) { cmd.AddParameter("lcid", culture.LCID); cmd.AddParameter("key", key.ToString()); cmd.CommandText = sql; return(!cmd.ExecuteScalar().Equals(0)); } }
/// <summary> /// Uipdates the specified culture. /// </summary> /// <param name="culture">The culture.</param> /// <param name="key">The key.</param> /// <param name="translatedText">The translated text.</param> public void Update(CultureInfo culture, TypePromptKey key, string translatedText) { var lang = GetLanguage(culture); var prompt = lang.Get(key); if (prompt == null) { throw new InvalidOperationException("Failed to find prompt " + key); } prompt.TranslatedText = translatedText; SaveLanguage(culture, lang); }
public void TwoLanguages() { var key = new TypePromptKey(typeof(TestType).FullName, "FirstName"); _repository.Save(new CultureInfo(1033), typeof(TestType).FullName, "FirstName", "FirstName"); _repository.Save(new CultureInfo(1053), typeof(TestType).FullName, "FirstName", "Förnamn"); var enprompt = _repository.GetPrompt(new CultureInfo(1033), key); var seprompt = _repository.GetPrompt(new CultureInfo(1053), key); Assert.IsNotNull(enprompt); Assert.IsNotNull(seprompt); Assert.AreNotEqual(enprompt.TranslatedText, seprompt.TranslatedText); }
/// <summary> /// Delete a prompt. /// </summary> /// <param name="culture">Culture to delete the prompt for</param> /// <param name="key">Key</param> public void Delete(CultureInfo culture, TypePromptKey key) { if (culture == null) { throw new ArgumentNullException("culture"); } if (key == null) { throw new ArgumentNullException("key"); } var language = GetOrCreateLanguage(culture); language.DeletePrompt(key); _modifiedDocuments.AddLast(language); }
/// <summary> /// Get a specific prompt /// </summary> /// <param name="culture"> Culture to get prompt for </param> /// <param name="key"> Key which is unique in the current language </param> /// <returns> Prompt if found; otherwise <c>null</c> . </returns> public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key) { var sql = "SELECT * FROM LocalizedTypes WHERE LocaleId = @LocaleId AND [Key] = @TextKey"; using (var cmd = _db.Connection.CreateCommand()) { cmd.CommandText = sql; cmd.AddParameter("LocaleId", culture.LCID); cmd.AddParameter("TextKey", key.ToString()); using (var reader = cmd.ExecuteReader()) { return(!reader.Read() ? null : MapEntity(reader)); } } }
/// <summary> /// Create or update a prompt /// </summary> /// <param name="culture">Culture that the prompt is for</param> /// <param name="fullTypeName">Type.FullName for the type being localized</param> /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param> /// <param name="translatedText">Translated text string</param> public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (fullTypeName == null) { throw new ArgumentNullException("fullTypeName"); } if (name == null) { throw new ArgumentNullException("name"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } if (fullTypeName.IndexOf(".") == -1) { throw new ArgumentException("You must use Type.FullName", "fullTypeName"); } var pos = fullTypeName.LastIndexOf("."); var typeName = fullTypeName.Substring(pos + 1); var key = new TypePromptKey(fullTypeName, name); var language = GetOrCreateLanguage(culture); var prompt = (from p in language.Prompts where p.LocaleId == culture.LCID && p.TextKey == key.ToString() select p).FirstOrDefault() ?? new TypePromptDocument { FullTypeName = fullTypeName, LocaleId = culture.LCID, TextName = name, Text = translatedText, TextKey = key.ToString(), TypeName = typeName, UpdatedAt = DateTime.Now, UpdatedBy = Thread.CurrentPrincipal.Identity.Name }; prompt.Text = translatedText; _logger.Debug("Updating text for " + prompt.TypeName + "." + prompt.TextName + " to " + translatedText); _documentSession.Store(language); _documentSession.SaveChanges(); }
/// <summary> /// Create or update a prompt /// </summary> /// <param name="culture">Culture that the prompt is for</param> /// <param name="fullTypeName">Type.FullName for the type being localized</param> /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param> /// <param name="translatedText">Translated text string</param> public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (fullTypeName == null) { throw new ArgumentNullException("fullTypeName"); } if (name == null) { throw new ArgumentNullException("name"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } if (fullTypeName.IndexOf(".") == -1) { throw new ArgumentException("You must use Type.FullName", "fullTypeName"); } var lang = GetLanguage(culture); var key = new TypePromptKey(fullTypeName, name); var prompt = lang.Get(key); if (prompt == null) { prompt = new TypePrompt { Key = key, LocaleId = culture.LCID, TypeFullName = fullTypeName, TextName = name, TranslatedText = translatedText, UpdatedAt = DateTime.Now, UpdatedBy = Thread.CurrentPrincipal.Identity.Name }; lang.Add(prompt); } prompt.TranslatedText = translatedText; SaveLanguage(culture, lang); }
public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText) { if (culture == null) throw new ArgumentNullException("culture"); if (fullTypeName == null) throw new ArgumentNullException("fullTypeName"); if (name == null) throw new ArgumentNullException("name"); if (translatedText == null) throw new ArgumentNullException("translatedText"); if (fullTypeName.IndexOf(".") == -1) throw new ArgumentException("You must use Type.FullName", "fullTypeName"); var key = new TypePromptKey(fullTypeName, name); // _Context.Save() is done inside "add" and Update "methods" if (getLocalizedType(culture, key) == null) add(culture, fullTypeName, name, translatedText); else Update(culture, key, translatedText); }
private EditModel CreateModel(string id) { var key = new TypePromptKey(id); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); var defaultLang = _repository.GetPrompt(DefaultUICulture.Value, key); var model = new EditModel { DefaultText = defaultLang != null ? defaultLang.TranslatedText : "", LocaleId = prompt.LocaleId, Path = string.Format("{0} / {1} / {2}", CultureInfo.CurrentUICulture.DisplayName, prompt.TypeName, prompt.TextName), Text = prompt.TranslatedText, TextKey = prompt.Key.ToString() }; return(model); }
private void Create(CultureInfo culture, string fullTypeName, string name, string translatedText) { var sql = @"INSERT INTO LocalizedTypes (LocaleId, [Key], TypeName, TextName, Value, UpdatedAt, UpdatedBy) VALUES (@lcid, @TextKey, @TypeName, @TextName, @value, @updat, @updby)"; var key = new TypePromptKey(fullTypeName, name); using (var cmd = _db.Connection.CreateCommand()) { cmd.AddParameter("lcid", culture.LCID); cmd.AddParameter("TextKey", key.ToString()); cmd.AddParameter("TypeName", fullTypeName); cmd.AddParameter("TextName", name); cmd.AddParameter("value", translatedText); cmd.AddParameter("updat", DateTime.Now); cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name); cmd.CommandText = sql; cmd.ExecuteNonQuery(); } }
/// <summary> /// Initializes a new instance of the <see cref="TypePromptDocument"/> class. /// </summary> /// <param name="key">The key.</param> /// <param name="modelType">Type of the model.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="culture">The culture.</param> public TypePromptDocument(TypePromptKey key, Type modelType, string propertyName, CultureInfo culture) { if (key == null) { throw new ArgumentNullException("key"); } if (modelType == null) { throw new ArgumentNullException("modelType"); } if (propertyName == null) { throw new ArgumentNullException("propertyName"); } TextKey = key.ToString(); FullTypeName = modelType.FullName; TypeName = modelType.Name; TextName = propertyName; LocaleId = culture.LCID; }
/// <summary> /// Delete a prompt. /// </summary> /// <param name="culture"> Culture to delete prompt in </param> /// <param name="key"> Prompt key </param> public void Delete(CultureInfo culture, TypePromptKey key) { if (culture == null) { throw new ArgumentNullException("culture"); } if (key == null) { throw new ArgumentNullException("key"); } var sql = "DELETE FROM LocalizedTypes WHERE [Key]=@textKey AND LocaleId = @lcid"; using (var cmd = _db.Connection.CreateCommand()) { cmd.CommandText = sql; cmd.AddParameter("lcid", culture.LCID); cmd.AddParameter("textKey", key.ToString()); cmd.ExecuteNonQuery(); } }
/// <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> /// Delete a prompt. /// </summary> /// <param name="culture"> Culture to delete prompt in </param> /// <param name="key"> Prompt key </param> public void Delete(CultureInfo culture, TypePromptKey key) { if (culture == null) throw new ArgumentNullException("culture"); if (key == null) throw new ArgumentNullException("key"); var sql = "DELETE FROM LocalizedTypes WHERE [Key]=@textKey AND LocaleId = @lcid"; using (var cmd = _db.Connection.CreateCommand()) { cmd.CommandText = sql; cmd.AddParameter("lcid", culture.LCID); cmd.AddParameter("textKey", key.ToString()); cmd.ExecuteNonQuery(); } }
/// <summary> /// Update translation /// </summary> /// <param name="culture"> Culture that the prompt is for </param> /// <param name="key"> Unique key, in the specified language only, for the prompt to get) </param> /// <param name="translatedText"> Translated text string </param> public void Update(CultureInfo culture, TypePromptKey key, string translatedText) { if (culture == null) throw new ArgumentNullException("culture"); if (key == null) throw new ArgumentNullException("key"); if (translatedText == null) throw new ArgumentNullException("translatedText"); var sql = "UPDATE LocalizedTypes SET Value=@value, UpdatedAt=@updat, UpdatedBy=@updby WHERE LocaleId = @lcid AND [Key] = @key"; using (var cmd = _db.Connection.CreateCommand()) { cmd.CommandText = sql; cmd.AddParameter("value", translatedText); cmd.AddParameter("updat", DateTime.Now); cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name); cmd.AddParameter("lcid", culture.LCID); cmd.AddParameter("key", key.ToString()); cmd.ExecuteNonQuery(); } }
/// <summary> /// Create or update a prompt /// </summary> /// <param name="culture">Culture that the prompt is for</param> /// <param name="fullTypeName">Type.FullName for the type being localized</param> /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param> /// <param name="translatedText">Translated text string</param> public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText) { if (culture == null) throw new ArgumentNullException("culture"); if (fullTypeName == null) throw new ArgumentNullException("fullTypeName"); if (name == null) throw new ArgumentNullException("name"); if (translatedText == null) throw new ArgumentNullException("translatedText"); if (fullTypeName.IndexOf(".") == -1) throw new ArgumentException("You must use Type.FullName", "fullTypeName"); var key = new TypePromptKey(fullTypeName, name); if (!Exists(culture, key)) Create(culture, fullTypeName, name, translatedText); else Update(culture, key, translatedText); }
public ActionResult Delete(string id) { var key = new TypePromptKey(id); _repository.Delete(CultureInfo.CurrentUICulture, key); return RedirectToAction("Index"); }
/// <summary> /// Get a specific prompt /// </summary> /// <param name="culture">Culture to get prompt for</param> /// <param name="key">Key which is unique in the current language</param> /// <returns> /// Prompt if found; otherwise <c>null</c>. /// </returns> public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key) { return(GetLanguage(culture).Get(key)); }
/// <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; }
/// <summary> /// Create or update a prompt /// </summary> /// <param name="culture">Culture that the prompt is for</param> /// <param name="type">Type being localized</param> /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param> /// <param name="translatedText">Translated text string</param> public void Save(CultureInfo culture, Type type, string name, string translatedText) { if (culture == null) throw new ArgumentNullException("culture"); if (type == null) throw new ArgumentNullException("type"); if (name == null) throw new ArgumentNullException("name"); if (translatedText == null) throw new ArgumentNullException("translatedText"); var key = new TypePromptKey(type, name); if (!Exists(culture, key)) Create(culture, type, name, translatedText); else Update(culture, key, translatedText); }
/// <summary> /// Translate a prompt if found /// </summary> /// <param name="key">Prompt to translate</param> /// <returns>Translation if found; otherwise null.</returns> public string Translate(TypePromptKey key) { return(_prompts.Where(p => p.Key == key).Select(p => p.TranslatedText).FirstOrDefault()); }
public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key) { var type = getLocalizedType(culture, key); return(type != null?type.ToTypePrompt() : null); }
internal void Update(TypePromptKey key, string translatedText, CultureInfo culture) { Update(key.ToString(), translatedText, culture); }
private EditModel CreateModel(string id) { var key = new TypePromptKey(id); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); var defaultLang = _repository.GetPrompt(DefaultUICulture.Value, key); var model = new EditModel { DefaultText = defaultLang != null ? defaultLang.TranslatedText : "", LocaleId = prompt.LocaleId, Path = string.Format("{0} / {1} / {2}", CultureInfo.CurrentUICulture.DisplayName, prompt.TypeName, prompt.TextName), Text = prompt.TranslatedText, TextKey = prompt.Key.ToString() }; return model; }
private bool Exists(CultureInfo culture, TypePromptKey key) { var sql = @"SELECT count(Id) FROM LocalizedTypes WHERE LocaleId = @lcid AND [Key] = @key"; using (var cmd = _db.Connection.CreateCommand()) { cmd.AddParameter("lcid", culture.LCID); cmd.AddParameter("key", key.ToString()); cmd.CommandText = sql; return !cmd.ExecuteScalar().Equals(0); } }
public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key) { var type = getLocalizedType(culture, key); return type != null ? type.ToTypePrompt() : null; }
private LocalizedType getLocalizedType(CultureInfo culture, TypePromptKey key) { return getLocalizedType(culture.LCID, key.ToString()); }
public void TwoLanguages() { var key = new TypePromptKey(typeof(TestType).FullName, "FirstName"); _repository.Save(new CultureInfo(1033), typeof (TestType).FullName, "FirstName", "FirstName"); _repository.Save(new CultureInfo(1053), typeof (TestType).FullName, "FirstName", "Förnamn"); var enprompt = _repository.GetPrompt(new CultureInfo(1033), key); var seprompt = _repository.GetPrompt(new CultureInfo(1053), key); Assert.IsNotNull(enprompt); Assert.IsNotNull(seprompt); Assert.AreNotEqual(enprompt.TranslatedText, seprompt.TranslatedText); }
public void DeletePrompt(TypePromptKey key) { if (key == null) throw new ArgumentNullException("key"); Prompts.RemoveAll(k => k.TextKey == key.ToString()); }
/// <summary> /// Get a specific prompt /// </summary> /// <param name="culture"> Culture to get prompt for </param> /// <param name="key"> Key which is unique in the current language </param> /// <returns> Prompt if found; otherwise <c>null</c> . </returns> public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key) { var sql = "SELECT * FROM LocalizedTypes WHERE LocaleId = @LocaleId AND [Key] = @TextKey"; using (var cmd = _db.Connection.CreateCommand()) { cmd.CommandText = sql; cmd.AddParameter("LocaleId", culture.LCID); cmd.AddParameter("TextKey", key.ToString()); using (var reader = cmd.ExecuteReader()) { return !reader.Read() ? null : MapEntity(reader); } } }