コード例 #1
0
 /// <summary>
 /// 获取Umbraco中Dictionary中的值
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static Models.UmbDictionaryModel GetDictionaryByKey(string key)
 {
     Models.UmbDictionaryModel model = new Models.UmbDictionaryModel();
     Dictionary.DictionaryItem item  = Dictionary.getTopMostItems.Where(d => d.key.Equals(key)).FirstOrDefault();
     model.EnValue = item.Value(1);
     model.CnValue = item.Value(2);
     model.DicKey  = item.key;
     return(model);
 }
コード例 #2
0
        private string dictinaryItem(string alias)
        {
            if (alias.Substring(1, 0) == "#")
            {
                if (Dictionary.DictionaryItem.hasKey(alias.Substring(1)))
                {
                    Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(alias.Substring(1));

                    if (di != null && !string.IsNullOrEmpty(di.Value()))
                    {
                        return(di.Value());
                    }
                }
            }

            return(alias + " " + alias.Substring(1));
        }
コード例 #3
0
        /// <summary>
        /// Gets the dictionary item for a specified language. Otherwise returns the fallback string.
        /// </summary>
        /// <param name="key">The dictionary key.</param>
        /// <param name="fallback">The fallback.</param>
        /// <param name="languageId">The language id.</param>
        /// <returns>
        /// Returns the value of a dictionary item from a language id, or the fallback string.
        /// </returns>
        public static string GetDictionaryItem(string key, string fallback, int languageId)
        {
            if (Dictionary.DictionaryItem.hasKey(key))
            {
                var item = new Dictionary.DictionaryItem(key);
                return(item.Value(languageId));
            }

            return(fallback);
        }
コード例 #4
0
        /// <summary>
        /// Gets a dictionary item if it exists. Otherwise returns the fallback string.
        /// </summary>
        /// <param name="key">The dictionary key.</param>
        /// <param name="fallback">The fallback.</param>
        /// <returns>
        /// A dictionary string or the fallback string
        /// </returns>
        public static string GetDictionaryItem(string key, string fallback)
        {
            if (Dictionary.DictionaryItem.hasKey(key))
            {
                var item = new Dictionary.DictionaryItem(key);
                return item.Value();
            }

            return fallback;
        }
コード例 #5
0
        static string DictionaryReplace(string text)
        {
            if (!text.StartsWith("#"))
            {
                return(text);
            }
            else
            {
                Language lang = Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentCulture.Name);
                if (lang != null)
                {
                    if (Dictionary.DictionaryItem.hasKey(text.Substring(1, text.Length - 1)))
                    {
                        Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(text.Substring(1, text.Length - 1));
                        return(di.Value(lang.id));
                    }
                }

                return("[" + text + "]");
            }
        }