Пример #1
0
        public static void ImportTranslationsCsv(DataContext db, CsvReader csv, TranslationArea area)
        {
            while (csv.Read())
            {
                var code = csv.GetField<string>(0);
                var key = csv.GetField<string>(1);
                var value = csv.GetField<string>(2);

                // ToList is called on purpose for case sensitive search
                var translation =
                    db.Translations.ToList().FirstOrDefault(
                        t => t.LanguageCode == code && t.Key == key && t.Area == area);

                if (translation == null)
                {
                    translation = new Translation
                                  {
                                      LanguageCode = code,
                                      Key = key,
                                      Value = value,
                                      Area = area
                                  };
                    db.Translations.Add(translation);
                }
                else
                {
                    translation.Value = value;
                }
            }

            db.SaveChanges();

            TranslationHelper.ClearCache();
        }
Пример #2
0
        private static string saveAndReturnKey(string key, string languageCode, TranslationArea area)
        {
            if (unitTest) return key;

            using (DataContext db = DataContext.Create())
            {
                var translation = new Translation
                                  {
                                      Key = key,
                                      Value = key,
                                      LanguageCode = languageCode,
                                      Area = area
                                  };
                db.Translations.Add(translation);
                db.SaveChanges();
            }

            return key;
        }