public string this[string key]
        {
            get
            {
                try
                {
                    var temp = StringsTable[key];
                    if (temp.AliasedKey)
                    {
                        return(this[temp.CloneOf]);
                    }
                    if (temp.DeriveFromParent)
                    {
                        return(null);
                    }

                    return(temp.Value);
                }
                catch (KeyNotFoundException)
                {
                    throw new StringNotFoundException(key, this.Key);
                }
            }
            set
            {
                if (StringsTable.ContainsKey(key))
                {
                    StringsTable[key] = new StringTranslation(key, value);
                }
                else
                {
                    StringsTable[key].Value = value;
                }
            }
        }
Пример #2
0
        public string this[string key]
        {
            get
            {
                try
                {
                    var temp = StringsTable[key];
                    if(temp.AliasedKey)
                    {
                        return this[temp.CloneOf];
                    }
                    if(temp.DeriveFromParent)
                    {
                        return null;
                    }

                    return temp.Value;
                }
                catch(KeyNotFoundException)
                {
                    throw new StringNotFoundException(key, this.Key);
                }
            }
            set
            {
                if (StringsTable.ContainsKey(key))
                {
                    StringsTable[key] = new StringTranslation(key, value);
                }
                else
                {
                    StringsTable[key].Value = value;
                }
            }
        }
Пример #3
0
        private void lstKeys_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstKeys.SelectedItems.Count == 0)
                return;

            var selectedKey = lstKeys.SelectedItems[0].Text;

            if (_lastTranslation != null)
            {
                StoreCurrentData();
            }

            txtOld.Text = _parentLocale != null ? _parentLocale.GetString(_collection.Key, selectedKey) : string.Empty;

            try
            {
                txtNew.Text = _collection[selectedKey];
            }
            catch (StringNotFoundException)
            {
                _collection.StringsTable.Add(selectedKey, new StringTranslation(selectedKey, string.Empty));
                txtNew.Text = _collection[selectedKey];
            }

            _lastTranslation = _collection.StringsTable[selectedKey];

            chkDerived.Checked = _lastTranslation.DeriveFromParent;

            if (chkMinorUpdate.Visible)
            {
                if (_forceModified)
                {
                    chkMinorUpdate.Checked = true;
                }
                else
                {
                    chkMinorUpdate.Checked = !_lastTranslation.BumpVersion;
                }
            }
            else if(chkUpToDate.Visible)
            {
                chkUpToDate.Checked = _lastTranslation.BumpVersion;
            }

            ReflectCheckboxes();
        }
        public void Load(string xmlPath)
        {
            Key = Path.GetFileNameWithoutExtension(xmlPath);
            string localeKey = Path.GetFileName(Path.GetDirectoryName(xmlPath));

            var xmlDocument = new XmlDocument();

            xmlDocument.Load(xmlPath);

            var node = xmlDocument.SelectSingleNode(@"/localization/strings");

            if (node == null)
            {
                throw new IncompleteLocaleException("The required locale element 'strings' was not found.");
            }

            var strings = xmlDocument.SelectNodes(@"/localization/strings/string");

            if (strings != null)
            {
                foreach (XmlNode text in strings)
                {
                    if (text.Attributes == null)
                    {
                        throw new MalformedStringException("Invalid translation string found. Attribute 'key' is required.");
                    }

                    var temp = text.Attributes["key"];

                    if (temp == null || string.IsNullOrEmpty(temp.InnerText))
                    {
                        throw new MalformedStringException("Invalid translation string found. Attribute 'key' is required.");
                    }

                    var key = temp.InnerText;

                    var value  = text.Attributes["value"] != null ? text.Attributes["value"].InnerText : null;
                    var clone  = text.Attributes["clone"] != null ? text.Attributes["clone"].InnerText : null;
                    var derive = text.Attributes["derive"] != null && text.Attributes["derive"].InnerText == @"true";

                    uint version        = 0;
                    var  versionElement = text.Attributes["version"];
                    if (versionElement != null)
                    {
                        version = uint.Parse(versionElement.InnerText);
                    }

                    if (_strings.ContainsKey(key))
                    {
                        throw new DuplicateKeyException(string.Format("Key {0} in {1}\\{2} was defined more than once.", key, localeKey, Key));
                    }

                    var newString = new StringTranslation(key);

                    if (value != null)
                    {
                        newString.Value = value;
                    }
                    else if (!string.IsNullOrEmpty(clone))
                    {
                        newString.CloneOf = clone;
                    }
                    else if (derive)
                    {
                        newString.DeriveFromParent = true;
                    }
                    else
                    {
                        //throw new MalformedStringException(string.Format("Invalid translation string {0} found. One of attributes 'value', 'clone', or 'derive' is required.", key));
                        continue;
                    }

                    _strings[newString.Key] = newString;
                    newString.Version       = version;
                }
            }
        }
Пример #5
0
        public void Load(string xmlPath)
        {
            Key = Path.GetFileNameWithoutExtension(xmlPath);
            string localeKey = Path.GetFileName(Path.GetDirectoryName(xmlPath));

            var xmlDocument = new XmlDocument();
            xmlDocument.Load(xmlPath);

            var node = xmlDocument.SelectSingleNode(@"/localization/strings");
            if (node == null)
                throw new IncompleteLocaleException("The required locale element 'strings' was not found.");

            var strings = xmlDocument.SelectNodes(@"/localization/strings/string");
            if (strings != null)
            {
                foreach (XmlNode text in strings)
                {
                    if (text.Attributes == null)
                        throw new MalformedStringException("Invalid translation string found. Attribute 'key' is required.");

                    var temp = text.Attributes["key"];

                    if (temp == null || string.IsNullOrEmpty(temp.InnerText))
                        throw new MalformedStringException("Invalid translation string found. Attribute 'key' is required.");

                    var key = temp.InnerText;

                    var value = text.Attributes["value"] != null ? text.Attributes["value"].InnerText : null;
                    var clone = text.Attributes["clone"] != null ? text.Attributes["clone"].InnerText : null;
                    var derive = text.Attributes["derive"] != null && text.Attributes["derive"].InnerText == @"true";

                    uint version = 0;
                    var versionElement = text.Attributes["version"];
                    if (versionElement != null)
                    {
                        version = uint.Parse(versionElement.InnerText);
                    }

                    if (_strings.ContainsKey(key))
                        throw new DuplicateKeyException(string.Format("Key {0} in {1}\\{2} was defined more than once.", key, localeKey, Key));

                    var newString = new StringTranslation(key);

                    if(value != null)
                    {
                        newString.Value = value;
                    }
                    else if(!string.IsNullOrEmpty(clone))
                    {
                        newString.CloneOf = clone;
                    }
                    else if(derive)
                    {
                        newString.DeriveFromParent = true;
                    }
                    else
                    {
                        //throw new MalformedStringException(string.Format("Invalid translation string {0} found. One of attributes 'value', 'clone', or 'derive' is required.", key));
                        continue;
                    }

                    _strings[newString.Key] = newString;
                    newString.Version = version;
                }
            }
        }