/// <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> /// Create translation for a new language /// </summary> /// <param name="culture"> Language to create </param> /// <param name="templateCulture"> Language to use as a template </param> public void CreateLanguage(CultureInfo culture, CultureInfo templateCulture) { var prompts = GetLanguage(templateCulture).Select(p => new ViewPrompt(culture.LCID, p)); var newLanguage = new ViewPromptCollection(culture); newLanguage.AddRange(prompts); lock (_languages) { _languages[culture] = newLanguage; } }
/// <summary> /// Load a language /// </summary> /// <param name="culture">Culture to load for</param> /// <returns>Language if found; otherwise null.</returns> protected ViewPromptCollection LoadLanguage(CultureInfo culture) { var filename = GetFullPath(culture); if (!File.Exists(filename)) { return(null); } using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var prompts = new ViewPromptCollection(culture); var items = Deserialize(stream); prompts.AddRange(items); return(prompts); } }