public ActionResult Index() { var model = new LocalizationEditorViewModel { Categories = _persister.GetLocalizations(), Languages = _persister.GetEnabledLanguages(), Versions = _persister.GetTranslationFileVersions(), PowertoolsMode = !Settings.AutoPopulated.DisablePowertoolsMode }; return View(ModuleUtil.PathTo("Views/LocalizationEditor/Index.cshtml"), model); }
public XmlDocument SaveLocalizations(LocalizationEditorViewModel model) { XmlLanguageFileHelper languageXmlFileHelper = new XmlLanguageFileHelper(); languageXmlFileHelper.EnsureLanguagesXPath(); foreach (var translation in model.Categories.SelectMany(category => category.Translations)) { foreach (var dictionary in translation.Translations) { if (!string.IsNullOrWhiteSpace(dictionary.Value)) { languageXmlFileHelper.SetTranslation(translation.Key, dictionary.Key, dictionary.Value); } } } languageXmlFileHelper.AddLanguageNames(); AccessStrategy.SaveXml(languageXmlFileHelper.XmlDoc); LocalizationsUpdatedEventHandler.RaiseLocalizationsUpdatedEvent(); return languageXmlFileHelper.XmlDoc; }
public ActionResult Save(LocalizationEditorViewModel model) { _persister.SaveLocalizations(model); return RedirectToAction("Index"); }
public void SaveLocalizations_Saves_LocalizationsToXml() { var translations = new Dictionary<string, string>(); translations.Add("en", "Share"); translations.Add("fi", "Jaa"); var model = new LocalizationEditorViewModel() { Languages = new List<string>() { "fi", "en" }, Categories = new CategoryList() { new CategoryList.Category() { Name = "Common", Translations = new List<CategoryList.Translation>() { new CategoryList.Translation() {Key = "/common/sitename", DefaultValue = "Share", Translations = translations} } } } }; var actual = _persister.SaveLocalizations(model); var fiResult = actual.SelectSingleNode("/languages/language[@id='fi']/common/sitename"); var enResult = actual.SelectSingleNode("/languages/language[@id='en']/common/sitename"); Assert.AreEqual("Jaa", fiResult.InnerText); Assert.AreEqual("Share", enResult.InnerText); }