public TextPrompt(TextPrompt source) { TextKey = source.TextKey; LocaleId = source.LocaleId; ActionName = source.ActionName; ControllerName = source.ControllerName; TextName = source.TextName; TranslatedText = source.TranslatedText; }
public ViewPrompt(TextPrompt prompt) { ActionName = prompt.ActionName; ControllerName = prompt.ControllerName; UpdatedAt = DateTime.Now; UpdatedBy = Thread.CurrentPrincipal.Identity.Name; LocaleId = prompt.LocaleId; TextKey = prompt.TextKey; TextName = prompt.TextName; Text = prompt.TranslatedText; }
/// <summary> /// Create a new prompt in the specified language /// </summary> /// <param name="culture">Language that the translation is for</param> /// <param name="source">Prompt to use as source</param> /// <param name="translatedText">Translated text</param> public void CreatePrompt(CultureInfo culture, TextPrompt source, string translatedText) { if (source.TextKey == null) throw new InvalidOperationException("TextKey must be specified for all prompts."); var language = GetOrCreateLanguage(culture, culture); var dbPrompt = language.Prompts.Where(p => p.TextKey == source.TextKey).FirstOrDefault(); if (dbPrompt == null) { _logger.Debug("Created prompt " + source.ControllerName + "." + source.ActionName + "." + source.TextName); dbPrompt = new ViewPrompt(source) { Text = translatedText, LocaleId = culture.LCID, }; language.Prompts.Add(dbPrompt); } else { dbPrompt.Text = translatedText; } lock (_modifiedDocuments) { if (!_modifiedDocuments.Contains(language)) _modifiedDocuments.AddLast(language); } }
/// <summary> /// Save/Update a text prompt /// </summary> /// <param name="prompt">Prompt to update</param> public void Save(TextPrompt prompt) { var ourCulture = new CultureInfo(prompt.LocaleId); var language = GetOrCreateLanguage(ourCulture, ourCulture); var dbPrompt = language.Prompts.Where(p => p.TextKey == prompt.TextKey).FirstOrDefault(); if (dbPrompt != null) dbPrompt.Text = prompt.TranslatedText; else { dbPrompt = new ViewPrompt(prompt); language.Prompts.Add(dbPrompt); } // Can't figure out a better way. if (prompt.ActionName == null) prompt.ActionName = "Index"; _logger.Debug("Saving prompt " + prompt.ControllerName + "." + prompt.ActionName + "." + prompt.TextName); _documentSession.Store(language); _documentSession.SaveChanges(); }
/// <summary> /// Save/Update a text prompt /// </summary> /// <param name="prompt">Prompt to update</param> public void Save(TextPrompt prompt) { if (prompt.TextKey == null) throw new InvalidOperationException("Prompt id may not be null"); var prompts = GetLanguage(CultureInfo.CurrentUICulture); var thePrompt = prompts.Get(prompt.TextKey); if (thePrompt == null) prompts.Add(prompt); else if (!ReferenceEquals(prompt, thePrompt)) thePrompt.TranslatedText = prompt.TranslatedText; SaveLanguage(prompts.Culture, prompts); }
/// <summary> /// Create a new prompt in the specified language /// </summary> /// <param name="culture">Language that the translation is for</param> /// <param name="source">Prompt to use as source</param> /// <param name="translatedText">Translated text</param> public void CreatePrompt(CultureInfo culture, TextPrompt source, string translatedText) { var prompt = new TextPrompt(source) { LocaleId = culture.LCID, TranslatedText = translatedText }; var language = GetLanguage(culture); if (language == null) { CreateForLanguage(culture, culture); language = _languages[culture]; } language.Add(prompt); SaveLanguage(culture, language); }
public ViewPrompt(TextPrompt prompt) { _prompt = prompt; }
/// <summary> /// Translate a text prompt /// </summary> /// <param name="controllerName"></param> /// <param name="actionName"></param> /// <param name="text"></param> /// <returns></returns> public virtual string Translate(string controllerName, string actionName, string text) { if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullException("controllerName"); if (string.IsNullOrEmpty(text)) throw new ArgumentNullException("text"); if (actionName == null) actionName = "Index"; if (!Repository.Exists(CultureInfo.CurrentUICulture)) { Repository.CreateForLanguage(CultureInfo.CurrentUICulture, new CultureInfo(1033)); //use english as default } string textToSay = ""; var id = TextPrompt.CreateKey(controllerName, actionName, text); var prompt = Repository.GetPrompt(CultureInfo.CurrentUICulture, id); if (prompt == null) { var templatePrompt = new TextPrompt { TextKey = id, ControllerName = controllerName, ActionName = actionName, TextName = text }; Repository.CreatePrompt(CultureInfo.CurrentUICulture, templatePrompt, ""); } else textToSay = prompt.TranslatedText; if (string.IsNullOrEmpty(textToSay)) textToSay = CultureInfo.CurrentUICulture.Equals(DefaultCulture) ? text : string.Format("{1}:[{0}]", text, CultureInfo.CurrentUICulture); return textToSay; }