/// <summary> /// Saves to database. If culture is present, Translation entry is saved /// </summary> /// <param name="session"></param> /// <param name="input"></param> private void SaveStringToDatabase(ISession session, StringEntry input, bool overwrite) { var translatableString = (from s in session.Linq<LocalizableStringRecord>() where s.StringKey == input.Key && s.Context == input.Context select s).FirstOrDefault(); if (translatableString == null) { string path = input.Path; if (!path.Contains("{0}") && !string.IsNullOrEmpty(input.Culture)) path = path.Replace(input.Culture, "{0}"); translatableString = new LocalizableStringRecord { Path = path, Context = input.Context, StringKey = input.Key, OriginalLanguageString = input.English }; if (!translatableString.Path.Contains("{0}")) throw new Exception("Path should contain {0}, but doesn't.\n" + translatableString.Path); session.SaveOrUpdate(translatableString); } else if (translatableString.OriginalLanguageString != input.English) { translatableString.OriginalLanguageString = input.English; session.SaveOrUpdate(translatableString); } if (!string.IsNullOrEmpty(input.Culture) && !string.IsNullOrEmpty(input.Translation)) { var translation = (from t in translatableString.Translations where t.Culture.Equals(input.Culture) select t).FirstOrDefault(); if (translation == null) { translation = new TranslationRecord { Culture = input.Culture, Value = input.Translation }; translatableString.AddTranslation(translation); } else if (overwrite) { translation.Value = input.Translation; } session.SaveOrUpdate(translatableString); session.SaveOrUpdate(translation); } SetCacheInvalid(); }
public void UpdateTranslation(int id, string culture, string value) { var wc = _wca.GetContext(); { var _sessionLocator = wc.Resolve<ISessionLocator>(); using (var session = _sessionLocator.For(typeof(LocalizableStringRecord))) { var localizable = session.Get<LocalizableStringRecord>(id); var translation = localizable.Translations.Where(t => t.Culture == culture).FirstOrDefault(); if (translation == null) { if (!string.IsNullOrEmpty(value)) { var newTranslation = new TranslationRecord { Culture = culture, Value = value, LocalizableStringRecord = localizable }; localizable.Translations.Add(newTranslation); session.SaveOrUpdate(newTranslation); session.SaveOrUpdate(localizable); SetCacheInvalid(); } } else if (string.IsNullOrEmpty(value)) { session.Delete(translation); SetCacheInvalid(); } else if (translation.Value != value) { translation.Value = value; session.SaveOrUpdate(translation); SetCacheInvalid(); } } } }
public void UpdateTranslation(int id, string culture, string value) { var localizable = _localizableStringRepository.Get(id); var translation = localizable.Translations.Where(t => t.Culture == culture).FirstOrDefault(); if (translation == null) { if (!String.IsNullOrEmpty(value)) { var newTranslation = new TranslationRecord { Culture = culture, Value = value, LocalizableStringRecord = localizable }; localizable.Translations.Add(newTranslation); _translationRepository.Create(newTranslation); SetCacheInvalid(); } } else if (String.IsNullOrEmpty(value)) { _translationRepository.Delete(translation); SetCacheInvalid(); } else if (String.Compare(translation.Value, value) != 0) { translation.Value = value; _translationRepository.Update(translation); SetCacheInvalid(); } }
public virtual void AddTranslation(TranslationRecord translationRecord) { translationRecord.LocalizableStringRecord = this; Translations.Add(translationRecord); }
public virtual void AddTranslation(TranslationRecord translationRecord) { translationRecord.LocalizableStringRecord = this; Translations.Add(translationRecord); }