public ActionResult Delete(string id) { var key = new ViewPromptKey(id); _repository.Delete(CultureInfo.CurrentUICulture, key); return(RedirectToAction("Index")); }
/// <summary> /// Translate a text prompt /// </summary> /// <param name="routeData">Used to lookup the view location</param> /// <param name="text">Text to translate</param> /// <returns> /// String if found; otherwise null. /// </returns> public virtual string Translate(RouteData routeData, string text) { if (routeData == null) throw new ArgumentNullException("routeData"); if (string.IsNullOrEmpty(text)) throw new ArgumentNullException("text"); if (!_repository.Exists(CultureInfo.CurrentUICulture)) { //use english as default CloneDefaultCulture(); } var textToSay = ""; var uri = ViewPromptKey.GetViewPath(routeData); var id = new ViewPromptKey(uri, text); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, id); if (prompt == null) { textToSay = LoadCommonPrompt(text); if (textToSay == null) _repository.CreatePrompt(CultureInfo.CurrentUICulture, uri, text, ""); } else textToSay = prompt.TranslatedText; return string.IsNullOrEmpty(textToSay) ? FormatMissingPrompt(text) : textToSay; }
private EditModel CreateModel(string id) { var key = new ViewPromptKey(id); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); var defaultLang = _repository.GetPrompt(DefaultUICulture.Value, key); if (prompt == null && defaultLang == null) { throw new InvalidOperationException("You need to visit the view with the default language first."); } if (prompt == null) { _repository.CreatePrompt(CultureInfo.CurrentUICulture, defaultLang.ViewPath, defaultLang.TextName, ""); prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); } var model = new EditModel { DefaultText = defaultLang != null && !string.IsNullOrEmpty(defaultLang.TranslatedText) ? defaultLang.TranslatedText : prompt.TextName, LocaleId = prompt.LocaleId, Path = string.Format("{0} / {1}", CultureInfo.CurrentUICulture.DisplayName, prompt.ViewPath), Text = prompt.TranslatedText, TextKey = prompt.Key.ToString() }; return(model); }
/// <summary> /// Get a text using it's name. /// </summary> /// <param name="culture">Culture to get prompt for</param> /// <param name="key"> </param> /// <returns>Prompt if found; otherwise null.</returns> public ViewPrompt GetPrompt(CultureInfo culture, ViewPromptKey key) { if (culture == null) { throw new ArgumentNullException("culture"); } if (key == null) { throw new ArgumentNullException("key"); } var sql = @"SELECT * FROM LocalizedViews WHERE LocaleId = @LocaleId AND [Key] = @key"; using (var cmd = _db.Connection.CreateCommand()) { cmd.AddParameter("LocaleId", culture.LCID); cmd.AddParameter("TextKey", key.ToString()); cmd.CommandText = sql; cmd.AddParameter("key", key.ToString()); using (var reader = cmd.ExecuteReader()) { return(!reader.Read() ? null : MapEntity(reader)); } } }
public void Delete(CultureInfo cultureInfo, ViewPromptKey key) { var lView = getLocalizedView(cultureInfo, key); _Set.Remove(lView); _Context.Save(); }
private void update(CultureInfo culture, ViewPromptKey key, string translatedText) { var lView = getLocalizedView(culture, key); lView.Update(key, translatedText, culture); _Context.Save(); }
public void Save(CultureInfo culture, string viewPath, string textName, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (viewPath == null) { throw new ArgumentNullException("viewPath"); } if (textName == null) { throw new ArgumentNullException("textName"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } var key = new ViewPromptKey(viewPath, textName); // _Context.Save() is done inside "add" and Update "methods" if (getLocalizedView(culture, key) == null) { CreatePrompt(culture, viewPath, textName, translatedText); } else { update(culture, key, translatedText); } }
/// <summary> /// Gets the specified prompt /// </summary> /// <param name="id">The id.</param> /// <returns>Prompt if found; otherwise <c>null</c></returns> public ViewPrompt Get(ViewPromptKey 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(ViewPromptKey key) { if (key == null) { throw new ArgumentNullException("key"); } _prompts.RemoveAll(k => k.Key == key); }
public ActionResult MakeCommon(string id) { var key = new ViewPromptKey(id); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); prompt.ViewPath = "CommonPrompts"; _repository.Save(CultureInfo.CurrentUICulture, "CommonPrompts", prompt.TextName, prompt.TranslatedText); _repository.Delete(CultureInfo.CurrentUICulture, key); return RedirectToAction("Index"); }
/// <summary> /// Delete a prompt /// </summary> /// <param name="culture">Culture to delete the prompt for</param> /// <param name="key">Prompt key</param> public void Delete(CultureInfo culture, ViewPromptKey key) { var language = GetOrCreateLanguage(culture, culture); if (language != null && language.Delete(key)) { SetAsModified(language); } }
/// <summary> /// Create a new prompt in the specified language /// </summary> /// <param name="culture"> Language that the translation is for </param> /// <param name="viewPath"> Path to view. You can use <see cref="ViewPromptKey.GetViewPath" /> </param> /// <param name="textName"> Text to translate </param> /// <param name="translatedText"> Translated text </param> public void CreatePrompt(CultureInfo culture, string viewPath, string textName, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (viewPath == null) { throw new ArgumentNullException("viewPath"); } if (textName == null) { throw new ArgumentNullException("textName"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } var key = new ViewPromptKey(viewPath, textName); var prompt = new ViewPrompt { Key = key, TranslatedText = translatedText, LocaleId = culture.LCID, TextName = textName, ViewPath = viewPath }; var language = GetLanguage(culture); if (language == null) { var prompts = GetAllPrompts(culture, DefaultUICulture.Value, new SearchFilter()); var collection = new ViewPromptCollection(culture); collection.AddRange(prompts); // dont forget to translate var dbPrompt = collection.Get(key); if (dbPrompt == null) { collection.Add(prompt); } else { dbPrompt.TranslatedText = translatedText; } language = _languages[culture]; } else { language.Add(prompt); } SaveLanguage(culture, language); }
/// <summary> /// Delete a phrase /// </summary> /// <param name="culture">Culture to delete the phrase in</param> /// <param name="key">Unique key within a language</param> public void Delete(CultureInfo culture, ViewPromptKey key) { var language = GetLanguage(culture); if (language != null) { language.Delete(key); SaveLanguage(culture, language); } }
public ActionResult MakeCommon(string id) { var key = new ViewPromptKey(id); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); prompt.ViewPath = "CommonPrompts"; _repository.Save(CultureInfo.CurrentUICulture, "CommonPrompts", prompt.TextName, prompt.TranslatedText); _repository.Delete(CultureInfo.CurrentUICulture, key); return(RedirectToAction("Index")); }
/// <summary> /// Get a specific prompt /// </summary> /// <param name="viewPath">Absolute paht to the view </param> /// <param name="key">Key to find</param> /// <returns>Translation if found; oterwise null.</returns> public string GetPrompt(string viewPath, ViewPromptKey key) { if (viewPath == null) { throw new ArgumentNullException("viewPath"); } if (key == null) { throw new ArgumentNullException("key"); } return (_prompts.Where(p => p.ViewPath == viewPath && p.Key == key).Select(p => p.TranslatedText).FirstOrDefault ()); }
/// <summary> /// Save/Update a text prompt /// </summary> /// <param name="culture">Language to save prompt in</param> /// <param name="viewPath">Path to view. You can use <see cref="ViewPromptKey.GetViewPath"/></param> /// <param name="textName">Text to translate</param> /// <param name="translatedText">Translated text</param> public void Save(CultureInfo culture, string viewPath, string textName, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (viewPath == null) { throw new ArgumentNullException("viewPath"); } if (textName == null) { throw new ArgumentNullException("textName"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } var key = new ViewPromptKey(viewPath, textName); var language = GetOrCreateLanguage(culture, culture); var dbPrompt = language.Prompts.FirstOrDefault(p => p.TextKey == key.ToString()); if (dbPrompt != null) { dbPrompt.Text = translatedText; dbPrompt.UpdatedAt = DateTime.Now; dbPrompt.UpdatedBy = Thread.CurrentPrincipal.Identity.Name; } else { dbPrompt = new ViewPromptDocument { LocaleId = culture.LCID, TextName = textName, Text = translatedText, TextKey = key.ToString(), UpdatedAt = DateTime.Now, UpdatedBy = Thread.CurrentPrincipal.Identity.Name }; language.Prompts.Add(dbPrompt); } _logger.Debug("Saving prompt " + dbPrompt.ViewPath + "/" + dbPrompt.TextName); _documentSession.Store(language); _documentSession.SaveChanges(); }
/// <summary> /// Create a new prompt in the specified language /// </summary> /// <param name="culture">Language that the translation is for</param> /// <param name="viewPath">Path to view. You can use <see cref="ViewPromptKey.GetViewPath"/></param> /// <param name="textName">Text to translate</param> /// <param name="translatedText">Translated text</param> public void CreatePrompt(CultureInfo culture, string viewPath, string textName, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (viewPath == null) { throw new ArgumentNullException("viewPath"); } if (textName == null) { throw new ArgumentNullException("textName"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } var key = new ViewPromptKey(viewPath, textName); var language = GetOrCreateLanguage(culture, culture); var dbPrompt = language.Prompts.FirstOrDefault(p => p.TextKey == key.ToString()); if (dbPrompt == null) { _logger.Debug("Created prompt " + viewPath + " " + textName); dbPrompt = new ViewPromptDocument { TextKey = key.ToString(), Text = translatedText, LocaleId = culture.LCID, TextName = textName, ViewPath = viewPath, UpdatedAt = DateTime.Today, UpdatedBy = Thread.CurrentPrincipal.Identity.Name }; language.Prompts.Add(dbPrompt); } else { dbPrompt.Text = translatedText; } SetAsModified(language); }
/// <summary> /// Get a text using it's name. /// </summary> /// <param name="culture">Culture to get prompt for</param> /// <param name="key"> </param> /// <returns>Prompt if found; otherwise null.</returns> public ViewPrompt GetPrompt(CultureInfo culture, ViewPromptKey key) { if (culture == null) { throw new ArgumentNullException("culture"); } if (key == null) { throw new ArgumentNullException("key"); } var language = GetLanguage(culture); if (language == null) { return(null); } return(language.Prompts.Where(p => p.TextKey == key.ToString()).Select(CreatePrompt).FirstOrDefault()); }
/// <summary> /// Save/Update a text prompt /// </summary> /// <param name="culture"> Language to save prompt in </param> /// <param name="viewPath"> Path to view. You can use <see cref="ViewPromptKey.GetViewPath" /> </param> /// <param name="textName"> Text to translate </param> /// <param name="translatedText"> Translated text </param> public void Save(CultureInfo culture, string viewPath, string textName, string translatedText) { if (culture == null) { throw new ArgumentNullException("culture"); } if (viewPath == null) { throw new ArgumentNullException("viewPath"); } if (textName == null) { throw new ArgumentNullException("textName"); } if (translatedText == null) { throw new ArgumentNullException("translatedText"); } var prompts = GetLanguage(CultureInfo.CurrentUICulture); var key = new ViewPromptKey(viewPath, textName); var thePrompt = prompts.Get(key); if (thePrompt == null) { prompts.Add(new ViewPrompt { Key = key, LocaleId = culture.LCID, TextName = textName, TranslatedText = translatedText, ViewPath = viewPath }); } else { thePrompt.TranslatedText = translatedText; } SaveLanguage(prompts.Culture, prompts); }
/// <summary> /// Delete a prompt /// </summary> /// <param name="cultureInfo">Culture to delete the prompt for</param> /// <param name="key">Prompt key</param> public void Delete(CultureInfo cultureInfo, ViewPromptKey key) { if (cultureInfo == null) { throw new ArgumentNullException("cultureInfo"); } if (key == null) { throw new ArgumentNullException("key"); } var sql = @"DELETE FROM LocalizedViews WHERE LocaleId=@lcid AND [Key]=@key"; using (var cmd = _db.Connection.CreateCommand()) { cmd.AddParameter("lcid", cultureInfo.LCID); cmd.AddParameter("key", key.ToString()); cmd.CommandText = sql; cmd.ExecuteNonQuery(); } }
/// <summary> /// Load a common prompt /// </summary> /// <param name="text">Text to translate</param> /// <returns>Translation if found; otherwise null</returns> /// <remarks>Used to avoid duplications of prompts.</remarks> protected virtual string LoadCommonPrompt(string text) { var key = new ViewPromptKey("CommonPrompts", text); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); return prompt == null ? null : prompt.TranslatedText; }
private LocalizedView getLocalizedView(CultureInfo culture, ViewPromptKey key) { var keyS = key.ToString(); return _Set.Where(vp => vp.LocaleId == culture.LCID && vp.Key == keyS).SingleOrDefault(); }
/// <summary> /// Save/Update a text prompt /// </summary> /// <param name="culture">Language to save prompt in</param> /// <param name="viewPath">Path to view. You can use <see cref="ViewPromptKey.GetViewPath"/></param> /// <param name="textName">Text to translate</param> /// <param name="translatedText">Translated text</param> public void Save(CultureInfo culture, string viewPath, string textName, string translatedText) { if (culture == null) throw new ArgumentNullException("culture"); if (viewPath == null) throw new ArgumentNullException("viewPath"); if (textName == null) throw new ArgumentNullException("textName"); if (translatedText == null) throw new ArgumentNullException("translatedText"); var key = new ViewPromptKey(viewPath, textName); var language = GetOrCreateLanguage(culture, culture); var dbPrompt = language.Prompts.FirstOrDefault(p => p.TextKey == key.ToString()); if (dbPrompt != null) { dbPrompt.Text = translatedText; dbPrompt.UpdatedAt = DateTime.Now; dbPrompt.UpdatedBy = Thread.CurrentPrincipal.Identity.Name; } else { dbPrompt = new ViewPromptDocument { LocaleId = culture.LCID, TextName = textName, Text = translatedText, TextKey = key.ToString(), UpdatedAt = DateTime.Now, UpdatedBy = Thread.CurrentPrincipal.Identity.Name }; language.Prompts.Add(dbPrompt); } _logger.Debug("Saving prompt " + dbPrompt.ViewPath + "/" + dbPrompt.TextName); _documentSession.Store(language); _documentSession.SaveChanges(); }
private LocalizedView getLocalizedView(CultureInfo culture, ViewPromptKey key) { var keyS = key.ToString(); return(_Set.Where(vp => vp.LocaleId == culture.LCID && vp.Key == keyS).SingleOrDefault()); }
/// <summary> /// Delete a prompt /// </summary> /// <param name="cultureInfo">Culture to delete the prompt for</param> /// <param name="key">Prompt key</param> public void Delete(CultureInfo cultureInfo, ViewPromptKey key) { if (cultureInfo == null) throw new ArgumentNullException("cultureInfo"); if (key == null) throw new ArgumentNullException("key"); var sql = @"DELETE FROM LocalizedViews WHERE LocaleId=@lcid AND [Key]=@key"; using (var cmd = _db.Connection.CreateCommand()) { cmd.AddParameter("lcid", cultureInfo.LCID); cmd.AddParameter("key", key.ToString()); cmd.CommandText = sql; cmd.ExecuteNonQuery(); } }
private EditModel CreateModel(string id) { var key = new ViewPromptKey(id); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); var defaultLang = _repository.GetPrompt(DefaultUICulture.Value, key); if (prompt == null && defaultLang == null) throw new InvalidOperationException("You need to visit the view with the default language first."); if (prompt == null) { _repository.CreatePrompt(CultureInfo.CurrentUICulture, defaultLang.ViewPath, defaultLang.TextName, ""); prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key); } var model = new EditModel { DefaultText = defaultLang != null && !string.IsNullOrEmpty(defaultLang.TranslatedText) ? defaultLang.TranslatedText : prompt.TextName, LocaleId = prompt.LocaleId, Path = string.Format("{0} / {1}", CultureInfo.CurrentUICulture.DisplayName, prompt.ViewPath), Text = prompt.TranslatedText, TextKey = prompt.Key.ToString() }; return model; }
public ViewPrompt GetPrompt(CultureInfo culture, ViewPromptKey key) { var type = getLocalizedView(culture, key); return type != null ? type.ToViewPrompt() : null; }
public ViewPrompt GetPrompt(CultureInfo culture, ViewPromptKey key) { var type = getLocalizedView(culture, key); return(type != null?type.ToViewPrompt() : null); }
/// <summary> /// Get a text using it's name. /// </summary> /// <param name="culture">Culture to get prompt for</param> /// <param name="key"> </param> /// <returns>Prompt if found; otherwise null.</returns> public ViewPrompt GetPrompt(CultureInfo culture, ViewPromptKey key) { if (culture == null) throw new ArgumentNullException("culture"); if (key == null) throw new ArgumentNullException("key"); var language = GetLanguage(culture); if (language == null) return null; return language.Prompts.Where(p => p.TextKey == key.ToString()).Select(CreatePrompt).FirstOrDefault(); }
/// <summary> /// Create a new prompt in the specified language /// </summary> /// <param name="culture">Language that the translation is for</param> /// <param name="viewPath">Path to view. You can use <see cref="ViewPromptKey.GetViewPath"/></param> /// <param name="textName">Text to translate</param> /// <param name="translatedText">Translated text</param> public void CreatePrompt(CultureInfo culture, string viewPath, string textName, string translatedText) { if (culture == null) throw new ArgumentNullException("culture"); if (viewPath == null) throw new ArgumentNullException("viewPath"); if (textName == null) throw new ArgumentNullException("textName"); if (translatedText == null) throw new ArgumentNullException("translatedText"); var key = new ViewPromptKey(viewPath, textName); var language = GetOrCreateLanguage(culture, culture); var dbPrompt = language.Prompts.FirstOrDefault(p => p.TextKey == key.ToString()); if (dbPrompt == null) { _logger.Debug("Created prompt " + viewPath + " " + textName); dbPrompt = new ViewPromptDocument { TextKey = key.ToString(), Text = translatedText, LocaleId = culture.LCID, TextName = textName, ViewPath = viewPath, UpdatedAt = DateTime.Today, UpdatedBy = Thread.CurrentPrincipal.Identity.Name }; language.Prompts.Add(dbPrompt); } else { dbPrompt.Text = translatedText; } SetAsModified(language); }
internal void Update(ViewPromptKey key, string translatedText, System.Globalization.CultureInfo culture) { Update(key.ToString(), translatedText, culture); }
public ActionResult Delete(string id) { var key = new ViewPromptKey(id); _repository.Delete(CultureInfo.CurrentUICulture, key); return RedirectToAction("Index"); }
/// <summary> /// Delete prompt /// </summary> /// <param name="key">Prompt key</param> /// <returns>true if a prompt was found; otherwise false.</returns> public bool Delete(ViewPromptKey key) { return Prompts.RemoveAll(k => k.TextKey == key.ToString()) > 0; }
/// <summary> /// Get a text using it's name. /// </summary> /// <param name="culture"> Culture to get prompt for </param> /// <param name="key"> </param> /// <returns> Prompt if found; otherwise null. </returns> public ViewPrompt GetPrompt(CultureInfo culture, ViewPromptKey key) { var prompts = GetLanguage(culture); return(prompts.Get(key)); }
/// <summary> /// Get a text using it's name. /// </summary> /// <param name="culture">Culture to get prompt for</param> /// <param name="key"> </param> /// <returns>Prompt if found; otherwise null.</returns> public ViewPrompt GetPrompt(CultureInfo culture, ViewPromptKey key) { if (culture == null) throw new ArgumentNullException("culture"); if (key == null) throw new ArgumentNullException("key"); var sql = @"SELECT * FROM LocalizedViews WHERE LocaleId = @LocaleId AND [Key] = @key"; using (var cmd = _db.Connection.CreateCommand()) { cmd.AddParameter("LocaleId", culture.LCID); cmd.AddParameter("TextKey", key.ToString()); cmd.CommandText = sql; cmd.AddParameter("key", key.ToString()); using (var reader = cmd.ExecuteReader()) { return !reader.Read() ? null : MapEntity(reader); } } }
/// <summary> /// Delete prompt /// </summary> /// <param name="key">Prompt key</param> /// <returns>true if a prompt was found; otherwise false.</returns> public bool Delete(ViewPromptKey key) { return(Prompts.RemoveAll(k => k.TextKey == key.ToString()) > 0); }
/// <summary> /// Translate a text prompt /// </summary> /// <param name="viewPath">Virtual path to the view, so that we can identify layouts and request common prompts.</param> /// <param name="routeData">Used to lookup the view location</param> /// <param name="text">Text to translate</param> /// <returns> /// String if found; otherwise null. /// </returns> public virtual string Translate(string viewPath, RouteData routeData, string text) { if (routeData == null) throw new ArgumentNullException("routeData"); if (string.IsNullOrEmpty(text)) throw new ArgumentNullException("text"); if (!_repository.Exists(CultureInfo.CurrentUICulture)) { //use english as default CloneDefaultCulture(); } var textToSay = ""; string uri = ViewPromptKey.GetViewPath(viewPath, routeData); /* uri = viewPath.ToLower().Contains("/views/shared/") ? viewPath.TrimStart('~').Remove(viewPath.LastIndexOf('/')) : ViewPromptKey.GetViewPath(routeData); */ var id = new ViewPromptKey(uri, text); var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, id); if (prompt == null) { textToSay = LoadCommonPrompt(text); if (textToSay == null) _repository.CreatePrompt(CultureInfo.CurrentUICulture, uri, text, ""); } else textToSay = prompt.TranslatedText; return string.IsNullOrEmpty(textToSay) ? FormatMissingPrompt(text) : textToSay; }
public void Save(CultureInfo culture, string viewPath, string textName, string translatedText) { if (culture == null) throw new ArgumentNullException("culture"); if (viewPath == null) throw new ArgumentNullException("viewPath"); if (textName == null) throw new ArgumentNullException("textName"); if (translatedText == null) throw new ArgumentNullException("translatedText"); var key = new ViewPromptKey(viewPath, textName); // _Context.Save() is done inside "add" and Update "methods" if (getLocalizedView(culture, key) == null) CreatePrompt(culture, viewPath, textName, translatedText); else update(culture, key, translatedText); }