コード例 #1
0
        /// <summary>
        /// Delete a prompt.
        /// </summary>
        /// <param name="culture">Culture to delete prompt in</param>
        /// <param name="key">Prompt key</param>
        public void Delete(CultureInfo culture, TypePromptKey key)
        {
            var lang = GetLanguage(culture);

            lang.Delete(key);
            SaveLanguage(culture, lang);
        }
コード例 #2
0
        /// <summary>
        ///   Update translation
        /// </summary>
        /// <param name="culture"> Culture that the prompt is for </param>
        /// <param name="key"> Unique key, in the specified language only, for the prompt to get) </param>
        /// <param name="translatedText"> Translated text string </param>
        public void Update(CultureInfo culture, TypePromptKey key, string translatedText)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (translatedText == null)
            {
                throw new ArgumentNullException("translatedText");
            }

            var sql = "UPDATE LocalizedTypes SET Value=@value, UpdatedAt=@updat, UpdatedBy=@updby WHERE LocaleId = @lcid AND [Key] = @key";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("value", translatedText);
                cmd.AddParameter("updat", DateTime.Now);
                cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name);
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("key", key.ToString());
                cmd.ExecuteNonQuery();
            }
        }
コード例 #3
0
        /// <summary>
        /// Create  or update a prompt
        /// </summary>
        /// <param name="culture">Culture that the prompt is for</param>
        /// <param name="fullTypeName">Type.FullName for the type being localized</param>
        /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param>
        /// <param name="translatedText">Translated text string</param>
        public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (fullTypeName == null)
            {
                throw new ArgumentNullException("fullTypeName");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (translatedText == null)
            {
                throw new ArgumentNullException("translatedText");
            }
            if (fullTypeName.IndexOf(".") == -1)
            {
                throw new ArgumentException("You must use Type.FullName", "fullTypeName");
            }

            var key = new TypePromptKey(fullTypeName, name);

            if (!Exists(culture, key))
            {
                Create(culture, fullTypeName, name, translatedText);
            }
            else
            {
                Update(culture, key, translatedText);
            }
        }
コード例 #4
0
        /// <summary>
        /// Updates the specified culture.
        /// </summary>
        /// <param name="culture">The culture.</param>
        /// <param name="key">The key.</param>
        /// <param name="translatedText">The translated text.</param>
        public void Update(CultureInfo culture, TypePromptKey key, string translatedText)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (translatedText == null)
            {
                throw new ArgumentNullException("translatedText");
            }

            var language = GetOrCreateLanguage(culture);
            var prompt   = (from p in language.Prompts
                            where p.LocaleId == culture.LCID && p.TextKey == key.ToString()
                            select p).FirstOrDefault();

            if (prompt == null)
            {
                throw new InvalidOperationException("Prompt " + key + " do not exist.");
            }

            prompt.Text = translatedText;
            _logger.Debug("Updating text for " + prompt.TypeName + "." + prompt.TextName + " to " + translatedText);
            _documentSession.Store(language);
            _documentSession.SaveChanges();
        }
コード例 #5
0
        public void Update(CultureInfo cultureInfo, TypePromptKey key, string translatedText)
        {
            var localizedType = getLocalizedType(cultureInfo, key);

            localizedType.Update(key, translatedText, cultureInfo);
            _Context.Save();
        }
コード例 #6
0
 public void Update()
 {
     var key = new TypePromptKey(typeof(TestType).FullName, "FirstName");
     _repository.Update(new CultureInfo(1053), key, "Förrenammne");
     var prompt = _repository.GetPrompt(new CultureInfo(1053), key);
     Assert.Null(prompt);
 }
コード例 #7
0
        public ActionResult Delete(string id)
        {
            var key = new TypePromptKey(id);

            _repository.Delete(CultureInfo.CurrentUICulture, key);
            return(RedirectToAction("Index"));
        }
コード例 #8
0
        public void Delete(CultureInfo culture, TypePromptKey key)
        {
            var lt = getLocalizedType(culture, key);

            _Set.Remove(lt);
            _Context.Save();
        }
コード例 #9
0
        public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (fullTypeName == null)
            {
                throw new ArgumentNullException("fullTypeName");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (translatedText == null)
            {
                throw new ArgumentNullException("translatedText");
            }
            if (fullTypeName.IndexOf(".") == -1)
            {
                throw new ArgumentException("You must use Type.FullName", "fullTypeName");
            }

            var key = new TypePromptKey(fullTypeName, name);

            // _Context.Save() is done inside "add" and Update "methods"
            if (getLocalizedType(culture, key) == null)
            {
                add(culture, fullTypeName, name, translatedText);
            }
            else
            {
                Update(culture, key, translatedText);
            }
        }
コード例 #10
0
        /// <summary>
        ///   Get all strings.
        /// </summary>
        /// <param name="culture">Culture to get prompts for</param>
        /// <returns>A colleciton of prompts (or an empty collection)</returns>
        public virtual IEnumerable<TypePrompt> GetPrompts(CultureInfo culture)
        {
            if (culture == null) throw new ArgumentNullException("culture");

            var prompts = new List<TypePrompt>();

            var baseAttribte = typeof (ValidationAttribute);
            var attributes =
                typeof (RequiredAttribute).Assembly.GetTypes().Where(
                    p => baseAttribte.IsAssignableFrom(p) && !p.IsAbstract).ToList();
            foreach (var type in attributes)
            {
                var key = new TypePromptKey(type.FullName, "class");
                var typePrompt = new TypePrompt
                                     {
                                         Key = key,
                                         LocaleId = CultureInfo.CurrentUICulture.LCID,
                                         TypeFullName = type.FullName,
                                         TextName = "class",
                                         UpdatedAt = DateTime.Now,
                                         UpdatedBy = Thread.CurrentPrincipal.Identity.Name
                                     };

                var value = GetString(type, culture);
                if (value != null)
                {
                    typePrompt.TranslatedText = DefaultUICulture.IsActive ? value : "";
                }

                prompts.Add(typePrompt);
            }

            return prompts;
        }
コード例 #11
0
        /// <summary>
        /// Get a specific prompt
        /// </summary>
        /// <param name="culture">Culture to get prompt for</param>
        /// <param name="key">Key which is unique in the current language</param>
        /// <returns>
        /// Prompt if found; otherwise <c>null</c>.
        /// </returns>
        public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key)
        {
            var language = GetOrCreateLanguage(culture);

            return((from p in language.Prompts
                    where p.LocaleId == culture.LCID && p.TextKey == key.ToString()
                    select CreateTextPrompt(p)).FirstOrDefault());
        }
コード例 #12
0
 public void DeletePrompt(TypePromptKey key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     Prompts.RemoveAll(k => k.TextKey == key.ToString());
 }
コード例 #13
0
 /// <summary>
 /// Get a prompt
 /// </summary>
 /// <param name="id">Prompt id</param>
 /// <returns>prompt if found; otherwise null</returns>
 public TypePrompt Get(TypePromptKey id)
 {
     if (id == null)
     {
         throw new ArgumentNullException("id");
     }
     return(_prompts.FirstOrDefault(p => p.Key == id));
 }
コード例 #14
0
 /// <summary>
 /// Delete prompt with the specified key
 /// </summary>
 /// <param name="key">key</param>
 public void Delete(TypePromptKey key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     _prompts.RemoveAll(k => k.Key == key);
 }
コード例 #15
0
        public void GetExisting()
        {
            var key = new TypePromptKey(typeof(TestType).FullName, "FirstName");
            _repository.Save(new CultureInfo(1053), typeof (TestType).FullName, "FirstName", "Förnamn");

            var prompt = _repository.GetPrompt(new CultureInfo(1053), key);
            Assert.NotNull(prompt);
            Assert.Equal("Förnamn", prompt.TranslatedText);
        }
コード例 #16
0
        public void Update()
        {
            var key = new TypePromptKey(typeof(TestType).FullName, "FirstName");

            _repository.Update(new CultureInfo(1053), key, "Förrenammne");
            var prompt = _repository.GetPrompt(new CultureInfo(1053), key);

            Assert.IsNull(prompt);
        }
コード例 #17
0
 public ActionResult MakeCommon(string id)
 {
     var key = new TypePromptKey(id);
     var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key);
     prompt.TypeFullName = typeof(CommonPrompts).FullName;
     _repository.Save(CultureInfo.CurrentUICulture, typeof(CommonPrompts).FullName, prompt.TextName,
                      prompt.TranslatedText);
     _repository.Delete(CultureInfo.CurrentUICulture, key);
     return RedirectToAction("Index");
 }
コード例 #18
0
        public void Save()
        {
            var key = new TypePromptKey(typeof(TestType).FullName, "FirstName");

            _repository.Save(new CultureInfo(1053), typeof(TestType).FullName, "FirstName", "Förrenammne");
            var prompt = _repository.GetPrompt(new CultureInfo(1053), key);

            Assert.IsNotNull(prompt);
            Assert.AreEqual("Förrenammne", prompt.TranslatedText);
        }
コード例 #19
0
        public ActionResult MakeCommon(string id)
        {
            var key    = new TypePromptKey(id);
            var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key);

            prompt.TypeFullName = typeof(CommonPrompts).FullName;
            _repository.Save(CultureInfo.CurrentUICulture, typeof(CommonPrompts).FullName, prompt.TextName,
                             prompt.TranslatedText);
            _repository.Delete(CultureInfo.CurrentUICulture, key);
            return(RedirectToAction("Index"));
        }
コード例 #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TypePromptDocument"/> class.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="modelType">Type of the model.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="culture">The culture.</param>
        public TypePromptDocument(TypePromptKey key, Type modelType, string propertyName, CultureInfo culture)
        {
            if (key == null) throw new ArgumentNullException("key");
            if (modelType == null) throw new ArgumentNullException("modelType");
            if (propertyName == null) throw new ArgumentNullException("propertyName");

            TextKey = key.ToString();
            FullTypeName = modelType.FullName;
            TypeName = modelType.Name;
            TextName = propertyName;
            LocaleId = culture.LCID;
        }
コード例 #21
0
        private bool Exists(CultureInfo culture, TypePromptKey key)
        {
            var sql = @"SELECT count(Id) FROM LocalizedTypes WHERE LocaleId = @lcid AND [Key] = @key";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("key", key.ToString());
                cmd.CommandText = sql;
                return(!cmd.ExecuteScalar().Equals(0));
            }
        }
コード例 #22
0
        /// <summary>
        /// Uipdates the specified culture.
        /// </summary>
        /// <param name="culture">The culture.</param>
        /// <param name="key">The key.</param>
        /// <param name="translatedText">The translated text.</param>
        public void Update(CultureInfo culture, TypePromptKey key, string translatedText)
        {
            var lang   = GetLanguage(culture);
            var prompt = lang.Get(key);

            if (prompt == null)
            {
                throw new InvalidOperationException("Failed to find prompt " + key);
            }
            prompt.TranslatedText = translatedText;
            SaveLanguage(culture, lang);
        }
コード例 #23
0
        public void TwoLanguages()
        {
            var key = new TypePromptKey(typeof(TestType).FullName, "FirstName");

            _repository.Save(new CultureInfo(1033), typeof(TestType).FullName, "FirstName", "FirstName");
            _repository.Save(new CultureInfo(1053), typeof(TestType).FullName, "FirstName", "Förnamn");


            var enprompt = _repository.GetPrompt(new CultureInfo(1033), key);
            var seprompt = _repository.GetPrompt(new CultureInfo(1053), key);

            Assert.IsNotNull(enprompt);
            Assert.IsNotNull(seprompt);
            Assert.AreNotEqual(enprompt.TranslatedText, seprompt.TranslatedText);
        }
コード例 #24
0
        /// <summary>
        /// Delete a prompt.
        /// </summary>
        /// <param name="culture">Culture to delete the prompt for</param>
        /// <param name="key">Key</param>
        public void Delete(CultureInfo culture, TypePromptKey key)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var language = GetOrCreateLanguage(culture);

            language.DeletePrompt(key);
            _modifiedDocuments.AddLast(language);
        }
コード例 #25
0
        /// <summary>
        ///   Get a specific prompt
        /// </summary>
        /// <param name="culture"> Culture to get prompt for </param>
        /// <param name="key"> Key which is unique in the current language </param>
        /// <returns> Prompt if found; otherwise <c>null</c> . </returns>
        public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key)
        {
            var sql = "SELECT * FROM LocalizedTypes WHERE LocaleId = @LocaleId AND [Key] = @TextKey";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("LocaleId", culture.LCID);
                cmd.AddParameter("TextKey", key.ToString());

                using (var reader = cmd.ExecuteReader())
                {
                    return(!reader.Read() ? null : MapEntity(reader));
                }
            }
        }
コード例 #26
0
        /// <summary>
        /// Create  or update a prompt
        /// </summary>
        /// <param name="culture">Culture that the prompt is for</param>
        /// <param name="fullTypeName">Type.FullName for the type being localized</param>
        /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param>
        /// <param name="translatedText">Translated text string</param>
        public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (fullTypeName == null)
            {
                throw new ArgumentNullException("fullTypeName");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (translatedText == null)
            {
                throw new ArgumentNullException("translatedText");
            }
            if (fullTypeName.IndexOf(".") == -1)
            {
                throw new ArgumentException("You must use Type.FullName", "fullTypeName");
            }

            var pos      = fullTypeName.LastIndexOf(".");
            var typeName = fullTypeName.Substring(pos + 1);
            var key      = new TypePromptKey(fullTypeName, name);
            var language = GetOrCreateLanguage(culture);
            var prompt   = (from p in language.Prompts
                            where p.LocaleId == culture.LCID && p.TextKey == key.ToString()
                            select p).FirstOrDefault() ?? new TypePromptDocument
            {
                FullTypeName = fullTypeName,
                LocaleId     = culture.LCID,
                TextName     = name,
                Text         = translatedText,
                TextKey      = key.ToString(),
                TypeName     = typeName,
                UpdatedAt    = DateTime.Now,
                UpdatedBy    = Thread.CurrentPrincipal.Identity.Name
            };

            prompt.Text = translatedText;
            _logger.Debug("Updating text for " + prompt.TypeName + "." + prompt.TextName + " to " + translatedText);
            _documentSession.Store(language);
            _documentSession.SaveChanges();
        }
コード例 #27
0
        /// <summary>
        /// Create  or update a prompt
        /// </summary>
        /// <param name="culture">Culture that the prompt is for</param>
        /// <param name="fullTypeName">Type.FullName for the type being localized</param>
        /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param>
        /// <param name="translatedText">Translated text string</param>
        public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (fullTypeName == null)
            {
                throw new ArgumentNullException("fullTypeName");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (translatedText == null)
            {
                throw new ArgumentNullException("translatedText");
            }
            if (fullTypeName.IndexOf(".") == -1)
            {
                throw new ArgumentException("You must use Type.FullName", "fullTypeName");
            }


            var lang   = GetLanguage(culture);
            var key    = new TypePromptKey(fullTypeName, name);
            var prompt = lang.Get(key);

            if (prompt == null)
            {
                prompt = new TypePrompt
                {
                    Key            = key,
                    LocaleId       = culture.LCID,
                    TypeFullName   = fullTypeName,
                    TextName       = name,
                    TranslatedText = translatedText,
                    UpdatedAt      = DateTime.Now,
                    UpdatedBy      = Thread.CurrentPrincipal.Identity.Name
                };
                lang.Add(prompt);
            }

            prompt.TranslatedText = translatedText;
            SaveLanguage(culture, lang);
        }
コード例 #28
0
        public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            if (culture == null) throw new ArgumentNullException("culture");
            if (fullTypeName == null) throw new ArgumentNullException("fullTypeName");
            if (name == null) throw new ArgumentNullException("name");
            if (translatedText == null) throw new ArgumentNullException("translatedText");
            if (fullTypeName.IndexOf(".") == -1)
                throw new ArgumentException("You must use Type.FullName", "fullTypeName");

            var key = new TypePromptKey(fullTypeName, name);

            // _Context.Save() is done inside "add" and Update "methods"
            if (getLocalizedType(culture, key) == null)
                add(culture, fullTypeName, name, translatedText);
            else
                Update(culture, key, translatedText);
        }
コード例 #29
0
        private EditModel CreateModel(string id)
        {
            var key         = new TypePromptKey(id);
            var prompt      = _repository.GetPrompt(CultureInfo.CurrentUICulture, key);
            var defaultLang = _repository.GetPrompt(DefaultUICulture.Value, key);
            var model       = new EditModel
            {
                DefaultText = defaultLang != null ? defaultLang.TranslatedText : "",
                LocaleId    = prompt.LocaleId,
                Path        =
                    string.Format("{0} / {1} / {2}", CultureInfo.CurrentUICulture.DisplayName,
                                  prompt.TypeName, prompt.TextName),
                Text    = prompt.TranslatedText,
                TextKey = prompt.Key.ToString()
            };

            return(model);
        }
コード例 #30
0
        private void Create(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            var sql =
                @"INSERT INTO LocalizedTypes (LocaleId, [Key], TypeName, TextName, Value, UpdatedAt, UpdatedBy)
                      VALUES (@lcid, @TextKey, @TypeName, @TextName, @value, @updat, @updby)";

            var key = new TypePromptKey(fullTypeName, name);

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("TextKey", key.ToString());
                cmd.AddParameter("TypeName", fullTypeName);
                cmd.AddParameter("TextName", name);
                cmd.AddParameter("value", translatedText);
                cmd.AddParameter("updat", DateTime.Now);
                cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name);
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
            }
        }
コード例 #31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TypePromptDocument"/> class.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="modelType">Type of the model.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="culture">The culture.</param>
        public TypePromptDocument(TypePromptKey key, Type modelType, string propertyName, CultureInfo culture)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (modelType == null)
            {
                throw new ArgumentNullException("modelType");
            }
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }

            TextKey      = key.ToString();
            FullTypeName = modelType.FullName;
            TypeName     = modelType.Name;
            TextName     = propertyName;
            LocaleId     = culture.LCID;
        }
コード例 #32
0
        /// <summary>
        ///   Delete a prompt.
        /// </summary>
        /// <param name="culture"> Culture to delete prompt in </param>
        /// <param name="key"> Prompt key </param>
        public void Delete(CultureInfo culture, TypePromptKey key)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var sql = "DELETE FROM LocalizedTypes WHERE [Key]=@textKey AND LocaleId = @lcid";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("textKey", key.ToString());
                cmd.ExecuteNonQuery();
            }
        }
コード例 #33
0
        /// <summary>
        ///   Get all strings.
        /// </summary>
        /// <param name="culture">Culture to get prompts for</param>
        /// <returns>A colleciton of prompts (or an empty collection)</returns>
        public virtual IEnumerable <TypePrompt> GetPrompts(CultureInfo culture)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }

            var prompts = new List <TypePrompt>();

            var baseAttribte = typeof(ValidationAttribute);
            var attributes   =
                typeof(RequiredAttribute).Assembly.GetTypes().Where(
                    p => baseAttribte.IsAssignableFrom(p) && !p.IsAbstract).ToList();

            foreach (var type in attributes)
            {
                var key        = new TypePromptKey(type.FullName, "class");
                var typePrompt = new TypePrompt
                {
                    Key          = key,
                    LocaleId     = CultureInfo.CurrentUICulture.LCID,
                    TypeFullName = type.FullName,
                    TextName     = "class",
                    UpdatedAt    = DateTime.Now,
                    UpdatedBy    = Thread.CurrentPrincipal.Identity.Name
                };

                var value = GetString(type, culture);
                if (value != null)
                {
                    typePrompt.TranslatedText = DefaultUICulture.IsActive ? value : "";
                }

                prompts.Add(typePrompt);
            }

            return(prompts);
        }
コード例 #34
0
        private void Create(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            var sql =
                @"INSERT INTO LocalizedTypes (LocaleId, [Key], TypeName, TextName, Value, UpdatedAt, UpdatedBy)
                      VALUES (@lcid, @TextKey, @TypeName, @TextName, @value, @updat, @updby)";

            var key = new TypePromptKey(fullTypeName, name);
            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("TextKey", key.ToString());
                cmd.AddParameter("TypeName", fullTypeName);
                cmd.AddParameter("TextName", name);
                cmd.AddParameter("value", translatedText);
                cmd.AddParameter("updat", DateTime.Now);
                cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name);
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
            }
        }
コード例 #35
0
        /// <summary>
        ///   Delete a prompt.
        /// </summary>
        /// <param name="culture"> Culture to delete prompt in </param>
        /// <param name="key"> Prompt key </param>
        public void Delete(CultureInfo culture, TypePromptKey key)
        {
            if (culture == null) throw new ArgumentNullException("culture");
            if (key == null) throw new ArgumentNullException("key");

            var sql = "DELETE FROM LocalizedTypes WHERE [Key]=@textKey AND LocaleId = @lcid";
            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("textKey", key.ToString());
                cmd.ExecuteNonQuery();
            }
        }
コード例 #36
0
        /// <summary>
        ///   Update translation
        /// </summary>
        /// <param name="culture"> Culture that the prompt is for </param>
        /// <param name="key"> Unique key, in the specified language only, for the prompt to get) </param>
        /// <param name="translatedText"> Translated text string </param>
        public void Update(CultureInfo culture, TypePromptKey key, string translatedText)
        {
            if (culture == null) throw new ArgumentNullException("culture");
            if (key == null) throw new ArgumentNullException("key");
            if (translatedText == null) throw new ArgumentNullException("translatedText");

            var sql = "UPDATE LocalizedTypes SET Value=@value, UpdatedAt=@updat, UpdatedBy=@updby WHERE LocaleId = @lcid AND [Key] = @key";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("value", translatedText);
                cmd.AddParameter("updat", DateTime.Now);
                cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name);
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("key", key.ToString());
                cmd.ExecuteNonQuery();
            }
        }
コード例 #37
0
        /// <summary>
        /// Create  or update a prompt
        /// </summary>
        /// <param name="culture">Culture that the prompt is for</param>
        /// <param name="fullTypeName">Type.FullName for the type being localized</param>
        /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param>
        /// <param name="translatedText">Translated text string</param>
        public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            if (culture == null) throw new ArgumentNullException("culture");
            if (fullTypeName == null) throw new ArgumentNullException("fullTypeName");
            if (name == null) throw new ArgumentNullException("name");
            if (translatedText == null) throw new ArgumentNullException("translatedText");
            if (fullTypeName.IndexOf(".") == -1)
                throw new ArgumentException("You must use Type.FullName", "fullTypeName");

            var key = new TypePromptKey(fullTypeName, name);
            if (!Exists(culture, key))
                Create(culture, fullTypeName, name, translatedText);
            else
                Update(culture, key, translatedText);
        }
コード例 #38
0
 public ActionResult Delete(string id)
 {
     var key = new TypePromptKey(id);
     _repository.Delete(CultureInfo.CurrentUICulture, key);
     return RedirectToAction("Index");
 }
コード例 #39
0
 /// <summary>
 /// Get a specific prompt
 /// </summary>
 /// <param name="culture">Culture to get prompt for</param>
 /// <param name="key">Key which is unique in the current language</param>
 /// <returns>
 /// Prompt if found; otherwise <c>null</c>.
 /// </returns>
 public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key)
 {
     return(GetLanguage(culture).Get(key));
 }
コード例 #40
0
 public void Delete(CultureInfo culture, TypePromptKey key)
 {
     var lt = getLocalizedType(culture, key);
     _Set.Remove(lt);
     _Context.Save();
 }
コード例 #41
0
        /// <summary>
        /// Translate a string
        /// </summary>
        /// <param name="type">Model being translated</param>
        /// <param name="name">Property name (or <c>propertyName_metadataName</c>)</param>
        /// <returns></returns>
        protected virtual string Translate(Type type, string name)
        {
            if (type == null) throw new ArgumentNullException("type");
            if (name == null) throw new ArgumentNullException("name");

            if (!string.IsNullOrEmpty(type.Namespace) && (type.Namespace.StartsWith("Griffin.MvcContrib") && !type.Namespace.Contains("TestProject")))
            {
                return null;
            }

            var key = new TypePromptKey(type.FullName, name);
            var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key) ??
                         _repository.GetPrompt(CultureInfo.CurrentUICulture,
                                               new TypePromptKey(typeof (CommonPrompts).FullName, name));

            if (prompt == null)
            {
                _repository.Save(CultureInfo.CurrentUICulture, type.FullName, name, "");
            }
            else
            {
                if (!string.IsNullOrEmpty(prompt.TranslatedText))
                    return prompt.TranslatedText;
            }

            return name.EndsWith("NullDisplayText") ? "" : null;
        }
コード例 #42
0
        /// <summary>
        /// Create  or update a prompt
        /// </summary>
        /// <param name="culture">Culture that the prompt is for</param>
        /// <param name="type">Type being localized</param>
        /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param>
        /// <param name="translatedText">Translated text string</param>
        public void Save(CultureInfo culture, Type type, string name, string translatedText)
        {
            if (culture == null) throw new ArgumentNullException("culture");
            if (type == null) throw new ArgumentNullException("type");
            if (name == null) throw new ArgumentNullException("name");
            if (translatedText == null) throw new ArgumentNullException("translatedText");

            var key = new TypePromptKey(type, name);
            if (!Exists(culture, key))
                Create(culture, type, name, translatedText);
            else
                Update(culture, key, translatedText);
        }
コード例 #43
0
 /// <summary>
 /// Translate a prompt if found
 /// </summary>
 /// <param name="key">Prompt to translate</param>
 /// <returns>Translation if found; otherwise null.</returns>
 public string Translate(TypePromptKey key)
 {
     return(_prompts.Where(p => p.Key == key).Select(p => p.TranslatedText).FirstOrDefault());
 }
コード例 #44
0
        public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key)
        {
            var type = getLocalizedType(culture, key);

            return(type != null?type.ToTypePrompt() : null);
        }
コード例 #45
0
 internal void Update(TypePromptKey key, string translatedText, CultureInfo culture)
 {
     Update(key.ToString(), translatedText, culture);
 }
コード例 #46
0
 private EditModel CreateModel(string id)
 {
     var key = new TypePromptKey(id);
     var prompt = _repository.GetPrompt(CultureInfo.CurrentUICulture, key);
     var defaultLang = _repository.GetPrompt(DefaultUICulture.Value, key);
     var model = new EditModel
                     {
                         DefaultText = defaultLang != null ? defaultLang.TranslatedText : "",
                         LocaleId = prompt.LocaleId,
                         Path =
                             string.Format("{0} / {1} / {2}", CultureInfo.CurrentUICulture.DisplayName,
                                           prompt.TypeName, prompt.TextName),
                         Text = prompt.TranslatedText,
                         TextKey = prompt.Key.ToString()
                     };
     return model;
 }
コード例 #47
0
        private bool Exists(CultureInfo culture, TypePromptKey key)
        {
            var sql = @"SELECT count(Id) FROM LocalizedTypes WHERE LocaleId = @lcid AND [Key] = @key";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("key", key.ToString());
                cmd.CommandText = sql;
                return !cmd.ExecuteScalar().Equals(0);
            }
        }
コード例 #48
0
 public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key)
 {
     var type = getLocalizedType(culture, key);
     return type != null ? type.ToTypePrompt() : null;
 }
コード例 #49
0
 public void Update(CultureInfo cultureInfo, TypePromptKey key, string translatedText)
 {
     var localizedType = getLocalizedType(cultureInfo, key);
     localizedType.Update(key, translatedText, cultureInfo);
     _Context.Save();
 }
コード例 #50
0
 private LocalizedType getLocalizedType(CultureInfo culture, TypePromptKey key)
 {
     return getLocalizedType(culture.LCID, key.ToString());
 }
コード例 #51
0
        public void TwoLanguages()
        {
            var key = new TypePromptKey(typeof(TestType).FullName, "FirstName");
            _repository.Save(new CultureInfo(1033), typeof (TestType).FullName, "FirstName", "FirstName");
            _repository.Save(new CultureInfo(1053), typeof (TestType).FullName, "FirstName", "Förnamn");


            var enprompt = _repository.GetPrompt(new CultureInfo(1033), key);
            var seprompt = _repository.GetPrompt(new CultureInfo(1053), key);
            Assert.IsNotNull(enprompt);
            Assert.IsNotNull(seprompt);
            Assert.AreNotEqual(enprompt.TranslatedText, seprompt.TranslatedText);
        }
コード例 #52
0
 public void DeletePrompt(TypePromptKey key)
 {
     if (key == null) throw new ArgumentNullException("key");
     Prompts.RemoveAll(k => k.TextKey == key.ToString());
 }
コード例 #53
0
        /// <summary>
        ///   Get a specific prompt
        /// </summary>
        /// <param name="culture"> Culture to get prompt for </param>
        /// <param name="key"> Key which is unique in the current language </param>
        /// <returns> Prompt if found; otherwise <c>null</c> . </returns>
        public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key)
        {
            var sql = "SELECT * FROM LocalizedTypes WHERE LocaleId = @LocaleId AND [Key] = @TextKey";
            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("LocaleId", culture.LCID);
                cmd.AddParameter("TextKey", key.ToString());

                using (var reader = cmd.ExecuteReader())
                {
                    return !reader.Read() ? null : MapEntity(reader);
                }
            }
        }