public static DictionaryItem Import(XmlNode xmlData, DictionaryItem parent)
            {
                string key = xmlData.Attributes["Key"].Value;

                XmlNodeList    values     = xmlData.SelectNodes("./Value");
                XmlNodeList    childItems = xmlData.SelectNodes("./DictionaryItem");
                DictionaryItem newItem;
                bool           retVal = false;

                if (!hasKey(key))
                {
                    if (parent != null)
                    {
                        addKey(key, " ", parent.key);
                    }
                    else
                    {
                        addKey(key, " ");
                    }

                    if (values.Count > 0)
                    {
                        //Set language values on the dictionary item
                        newItem = new DictionaryItem(key);
                        foreach (XmlNode xn in values)
                        {
                            string cA       = xn.Attributes["LanguageCultureAlias"].Value;
                            string keyValue = xmlHelper.GetNodeValue(xn);

                            Language valueLang = Language.GetByCultureCode(cA);

                            if (valueLang != null)
                            {
                                newItem.setValue(valueLang.id, keyValue);
                            }
                        }
                    }

                    if (parent == null)
                    {
                        retVal = true;
                    }
                }

                newItem = new DictionaryItem(key);

                foreach (XmlNode childItem in childItems)
                {
                    Import(childItem, newItem);
                }

                if (retVal)
                {
                    return(newItem);
                }
                else
                {
                    return(null);
                }
            }
Пример #2
0
        /// <summary>
        /// Imports a language from XML
        /// </summary>
        /// <param name="xmlData">The XML data.</param>
        /// <returns></returns>
        public static Language Import(XmlNode xmlData)
        {
            string cA = xmlData.Attributes["CultureAlias"].Value;

            if (Language.GetByCultureCode(cA) == null)
            {
                Language.MakeNew(cA);
                return(Language.GetByCultureCode(cA));
            }
            else
            {
                return(null);
            }
        }
        // zb023 - utility method
        public static string ReplaceKey(string text)
        {
            if (text.StartsWith("#") == false)
            {
                return(text);
            }

            var lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name);

            if (lang == null)
            {
                return("[" + text + "]");
            }

            if (DictionaryItem.hasKey(text.Substring(1, text.Length - 1)) == false)
            {
                return("[" + text + "]");
            }

            var di = new DictionaryItem(text.Substring(1, text.Length - 1));

            return(di.Value(lang.id));
        }