public DynamicText SaveDynamicText( DynamicText dynamicText, IfDefaultNotExistAction actionForDefaultCulture = IfDefaultNotExistAction.DoNothing ) { var dictionaryScope = GetDictionaryScope(dynamicText.DictionaryScope); if (dictionaryScope.Name != dynamicText.DictionaryScope) { m_dictionaryScopeUoW.AddScope(dynamicText.DictionaryScope); dictionaryScope = GetDictionaryScope(dynamicText.DictionaryScope); } var culture = GetCultureByNameOrGetDefault(dynamicText.Culture); if (culture.Name != dynamicText.Culture) { throw new ArgumentException($"Unknown culture {dynamicText.Culture}"); } var staticText = m_staticTextUoW.GetByNameAndCultureAndScope( dynamicText.Name, culture.Name, dictionaryScope.Name ); if (staticText == null) { m_staticTextUoW.AddStaticText( dynamicText.Name, dynamicText.Format, dynamicText.Text, culture.Name, dictionaryScope.Name, dynamicText.ModificationUser, DateTime.UtcNow ); } else { m_staticTextUoW.UpdateStaticText( dynamicText.Name, culture.Name, dictionaryScope.Name, dynamicText.Format, dynamicText.Text, dynamicText.ModificationUser, DateTime.UtcNow ); } ExecuteDefaultCultureAction(actionForDefaultCulture, dynamicText, culture, dictionaryScope); return(dynamicText); }
public void TranslateFallbackTest() { const string scope = "home"; const string key = "name"; var defaultCulture = m_localizationConfiguration.DefaultCulture; const string defaultValue = "Jméno"; var now = DateTime.UtcNow; var nonDefaultCulturesValuePairs = new Dictionary <string, string> { { "en", "Name" }, { "es", "Nombre" }, { "jp", "名前" }, { "ru", "Имя" }, }; var defaultCulturesValuePair = new KeyValuePair <string, string>(defaultCulture.Name, defaultValue); foreach (var culturesValuePair in nonDefaultCulturesValuePairs) { m_staticTextUoW.AddStaticText("name", 0, culturesValuePair.Value, culturesValuePair.Key, "home", "user", now); } m_staticTextUoW.AddStaticText("name", 0, defaultCulturesValuePair.Value, defaultCulturesValuePair.Key, "home", "user", now); foreach (var culturesValuePair in nonDefaultCulturesValuePairs) { var translateResult = m_databaseLocalizationManager.Translate(new CultureInfo(culturesValuePair.Key), scope, key); Assert.AreEqual(culturesValuePair.Value, translateResult.Value); } var defaultCultureTranslateResult = m_databaseLocalizationManager.Translate(new CultureInfo(defaultCulturesValuePair.Key), scope, key); Assert.AreEqual(defaultCulturesValuePair.Value, defaultCultureTranslateResult.Value); foreach (var culturesValuePair in nonDefaultCulturesValuePairs) { m_staticTextUoW.Delete(key, culturesValuePair.Key, scope); } foreach (var culturesValuePair in nonDefaultCulturesValuePairs) { var translateResult = m_databaseLocalizationManager.Translate(new CultureInfo(culturesValuePair.Key), scope, key); Assert.AreEqual(defaultCultureTranslateResult.Value, translateResult.Value); } }
public void StaticTextCreateReadTest() { var cultureUoW = new CultureUoW(m_sessionFactory); var dictionaryScopeUoW = new DictionaryScopeUoW(m_sessionFactory); var staticTextUoW = new StaticTextUoW(m_sessionFactory); cultureUoW.AddCulture("cs"); dictionaryScopeUoW.AddScope("dictionaryScope"); Assert.IsNull(staticTextUoW.GetStaticTextById(0)); Assert.IsNull(staticTextUoW.GetByNameAndCultureAndScope("not-exist", "not-exist", "not-exist")); var time = DateTime.UtcNow; staticTextUoW.AddStaticText( "name", 0, "text", "cs", "dictionaryScope", "modificationUser", time ); var allStaticTexts = staticTextUoW.FindAllStaticTexts(); Assert.AreEqual(1, allStaticTexts.Count); Assert.AreEqual("name", allStaticTexts.First().Name); Assert.AreEqual("name", staticTextUoW.GetStaticTextById(1).Name); var staticText = staticTextUoW.GetByNameAndCultureAndScope( "name", "cs", "dictionaryScope" ); Assert.AreEqual("name", staticText.Name); Assert.AreEqual("text", staticText.Text); var nullStaticText1 = staticTextUoW.GetByNameAndCultureAndScope( "not-exist", "cs", "dictionaryScope" ); var nullStaticText2 = staticTextUoW.GetByNameAndCultureAndScope( "name", "en", "dictionaryScope" ); var nullStaticText3 = staticTextUoW.GetByNameAndCultureAndScope( "name", "cs", "not-exist" ); Assert.IsNull(nullStaticText1); Assert.IsNull(nullStaticText2); Assert.IsNull(nullStaticText3); }
public void StaticTextCreateUpdateTest() { var cultureUoW = new CultureUoW(m_sessionFactory); var dictionaryScopeUoW = new DictionaryScopeUoW(m_sessionFactory); var staticTextUoW = new StaticTextUoW(m_sessionFactory); cultureUoW.AddCulture("cs"); dictionaryScopeUoW.AddScope("dictionaryScope"); var time = DateTime.UtcNow; staticTextUoW.AddStaticText( "name", 0, "text", "cs", "dictionaryScope", "modificationUser", time ); var staticText = staticTextUoW.GetByNameAndCultureAndScope( "name", "cs", "dictionaryScope" ); Assert.AreEqual("name", staticText.Name); Assert.AreEqual("text", staticText.Text); staticTextUoW.UpdateStaticText( "name", "cs", "dictionaryScope", 0, "modifiedText", "modificationUser", time ); var staticTextReFetched = staticTextUoW.GetByNameAndCultureAndScope( "name", "cs", "dictionaryScope" ); Assert.AreEqual("modifiedText", staticTextReFetched.Text); }