Ejemplo n.º 1
0
        // Add a new language
        public void AddLanguage(SymbolLanguage symbolLanguage, string langIdCopyTextsFrom)
        {
            LoadXmlDocument();

            XmlNode newNode = symbolLanguage.CreateXmlNode(xmldoc);

            bool replaced = false;

            // Replace existing language node, if language already exists.
            XmlNodeList languageNodes = root.SelectNodes("/symbols/language");

            foreach (XmlElement langNode in languageNodes)
            {
                if (langNode.GetAttribute("lang") == symbolLanguage.LangId)
                {
                    langNode.ParentNode.ReplaceChild(newNode, langNode);
                    replaced = true;
                    break;
                }
            }

            // Add new language node.
            if (!replaced)
            {
                root.InsertAfter(newNode, languageNodes.Item(languageNodes.Count - 1));
                root.InsertBefore(xmldoc.CreateTextNode("\r\n\t"), newNode);

                CopyAllNames(langIdCopyTextsFrom, symbolLanguage.LangId);     // Copy all the names from another language to the new one.
                CopyAllTexts(langIdCopyTextsFrom, symbolLanguage.LangId);     // Copy all the texts from another language to the new one.
            }

            SaveXmlDocument();
        }
Ejemplo n.º 2
0
        // Add a new language
        public void AddLanguage(SymbolLanguage symbolLanguage, string langIdCopyTextsFrom)
        {
            LoadXmlDocument();

            XmlNode newNode = symbolLanguage.CreateXmlNode(xmldoc);

            bool replaced = false;

            // Replace existing language node, if language already exists.
            XmlNodeList languageNodes = root.SelectNodes("/symbols/language");
            foreach (XmlElement langNode in languageNodes) {
                if (langNode.GetAttribute("lang") == symbolLanguage.LangId) {
                    langNode.ParentNode.ReplaceChild(newNode, langNode);
                    replaced = true;
                    break;
                }
            }

            // Add new language node.
            if (!replaced) {
                root.InsertAfter(newNode, languageNodes.Item(languageNodes.Count - 1));
                root.InsertBefore(xmldoc.CreateTextNode("\r\n\t"), newNode);

                CopyAllNames(langIdCopyTextsFrom, symbolLanguage.LangId);     // Copy all the names from another language to the new one.
                CopyAllTexts(langIdCopyTextsFrom, symbolLanguage.LangId);     // Copy all the texts from another language to the new one.
            }

            SaveXmlDocument();
        }
Ejemplo n.º 3
0
        // Find the best matching SymbolText. Gender can be null or empty for don't care. Same with nounCase. If
        // nounCase is empty then the first noun case from the language is chosen if possible.
        static SymbolText FindBestText(SymbolDB symbolDB, List <SymbolText> texts, string language, bool plural, string gender, string nounCase)
        {
            int        best        = 99999;
            SymbolText bestSymText = null;

            if (gender == null)
            {
                gender = "";
            }

            string         defaultNounCase = "";
            SymbolLanguage symbolLanguage  = symbolDB.GetLanguage(language);

            if (symbolLanguage != null && symbolLanguage.CaseModifiers && symbolLanguage.Cases.Length > 0)
            {
                defaultNounCase = symbolLanguage.Cases[0];
            }

            // Search for exact match.
            foreach (SymbolText symtext in texts)
            {
                int metric = 0;
                if (symtext.Lang != language && symtext.Lang != "en")
                {
                    metric += 100;
                }
                if (symtext.Lang != language && symtext.Lang == "en")   // english is most preferred if no language match
                {
                    metric += 50;
                }
                if (symtext.Plural != plural)
                {
                    metric += 10;
                }
                if (gender != "" && symtext.Gender != gender)
                {
                    metric += 5;
                }
                if (nounCase != "" && symtext.Case != nounCase)
                {
                    metric += 3;
                }
                if (nounCase == "" && symtext.Case != null && symtext.Case != defaultNounCase)
                {
                    metric += 1;
                }

                if (metric < best)
                {
                    best        = metric;
                    bestSymText = symtext;
                }
            }

            return(bestSymText);
        }
Ejemplo n.º 4
0
        public void SetLanguage(SymbolLanguage symLanguage)
        {
            this.symLanguage = symLanguage;

            if (symLanguage.Genders != null && symLanguage.Genders.Length > 0)
            {
                comboBoxGenderChooser.Items.AddRange(symLanguage.Genders);
            }
            if (symLanguage.CaseModifiers && symLanguage.Cases != null && symLanguage.Cases.Length > 0)
            {
                comboBoxCaseChooser.Items.Add(defaultCaseText);
                comboBoxCaseChooser.Items.AddRange(symLanguage.Cases);
            }
        }
Ejemplo n.º 5
0
        private SymbolLanguage CurrentLanguage()
        {
            string         langId   = LangId;
            SymbolLanguage language = null;

            foreach (SymbolLanguage symLanguage in symbolDB.AllLanguages)
            {
                if (symLanguage.LangId == langId)
                {
                    language = symLanguage;
                }
            }

            return(language);
        }
Ejemplo n.º 6
0
        private void ReadSymbolFile(string filename)
        {
            int sortOrder = 1;

            using (XmlInput xmlinput = new XmlInput(filename)) {
                xmlinput.CheckElement("symbols");

                bool first = true;
                while (xmlinput.FindSubElement(first, new string[] { "symbol", "language" }))
                {
                    if (xmlinput.Name == "symbol")
                    {
                        Symbol symbol = new Symbol(this, sortOrder);
                        ++sortOrder;

                        symbol.ReadXml(xmlinput);

                        if (symbols.ContainsKey(symbol.Id))
                        {
                            symbols[symbol.Id].Add(symbol);
                        }
                        else
                        {
                            symbols[symbol.Id] = new List <Symbol>()
                            {
                                symbol
                            };
                        }
                    }
                    else if (xmlinput.Name == "language")
                    {
                        SymbolLanguage language = new SymbolLanguage();

                        language.ReadXml(xmlinput);
                        languages.Add(language.LangId, language);
                    }

                    first = false;
                }
            }
        }
Ejemplo n.º 7
0
        public override bool Equals(object obj)
        {
            if (obj is SymbolLanguage)
            {
                SymbolLanguage other = (SymbolLanguage)obj;

                if (other.Name != Name)
                {
                    return(false);
                }
                if (other.LangId != LangId)
                {
                    return(false);
                }
                if (other.PluralNouns != PluralNouns)
                {
                    return(false);
                }
                if (other.PluralModifiers != PluralModifiers)
                {
                    return(false);
                }
                if (other.GenderModifiers != GenderModifiers)
                {
                    return(false);
                }
                if (!Util.ArrayEquals(other.Genders, Genders))
                {
                    return(false);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
        private void buttonChangeText_Click(object sender, EventArgs e)
        {
            if (selectedId != null)
            {
                UpdateDataFromControls(selectedId);
            }

            EnterSymbolText dialog = new EnterSymbolText(symbolDB);

            char kind = symbolDB[selectedId].Kind;

            SymbolLanguage language = CurrentLanguage();

            dialog.SetLanguage(language);

            List <SymbolText> symTexts;

            if (TextIsCustomized(selectedId))  // UNDONE: this isn't right!
            {
                symTexts = customSymbolText[selectedId];
            }
            else
            {
                symTexts = symbolDB[selectedId].SymbolTexts;
            }

            // Only consider the current language.
            symTexts = symTexts.FindAll(symtext => (symtext.Lang == language.LangId));

            bool hasPlural = false, hasGender = false, hasCase = false;

            foreach (SymbolText symtext in symTexts)
            {
                if (symtext.Plural)
                {
                    hasPlural = true;
                }
                if (!string.IsNullOrEmpty(symtext.Gender))
                {
                    hasGender = true;
                }
                if (!string.IsNullOrEmpty(symtext.Case))
                {
                    hasCase = true;
                }
            }

            bool isModifier = (kind == 'E' || kind == 'C' || kind == 'G' || kind == 'F') && selectedId != "11.15" && !selectedId.StartsWith("10.", StringComparison.InvariantCulture); // column C, E, F, G, but not between/crossing/junction
            bool isNoun     = (kind == 'D' || selectedId == "11.15" || selectedId.StartsWith("10.", StringComparison.InvariantCulture));                                               // column D or between/junction/crossing

            // Note that between/junction/crossing can both modify case of somthing inside, and have it's own case.
            bool canHaveCase   = isNoun;
            bool canModifyCase = (kind == 'F' || kind == 'E' || kind == 'C' || kind == 'G');


            dialog.SetAllowableForms((isNoun && language.PluralNouns) || (kind == 'E' && language.PluralModifiers), hasPlural,
                                     isModifier && language.GenderModifiers, hasGender,
                                     canHaveCase && language.CaseModifiers, hasCase,
                                     isNoun && language.GenderModifiers,
                                     canModifyCase && language.CaseModifiers,
                                     !useAsLocalizeTool && isModifier);

            dialog.SymbolTexts = symTexts;

            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                symTexts = dialog.SymbolTexts;

                // retain custom texts from other languages, if any
                if (customSymbolText.ContainsKey(selectedId))
                {
                    symTexts.AddRange(customSymbolText[selectedId].FindAll(symtext => (symtext.Lang != language.LangId)));
                }

                customSymbolText[selectedId] = symTexts;
                customSymbolKey[selectedId]  = checkBoxShowKey.Checked;
                UpdateControlsFromId(selectedId);
            }

            dialog.Dispose();
        }
Ejemplo n.º 9
0
        public void SetLanguage(SymbolLanguage symLanguage)
        {
            this.symLanguage = symLanguage;

            if (symLanguage.Genders != null && symLanguage.Genders.Length > 0)
                comboBoxGenderChooser.Items.AddRange(symLanguage.Genders);
            if (symLanguage.CaseModifiers && symLanguage.Cases != null && symLanguage.Cases.Length > 0) {
                comboBoxCaseChooser.Items.Add(defaultCaseText);
                comboBoxCaseChooser.Items.AddRange(symLanguage.Cases);
            }
        }
Ejemplo n.º 10
0
        private void ReadSymbolFile(string filename)
        {
            using (XmlInput xmlinput = new XmlInput(filename)) {
                xmlinput.CheckElement("symbols");

                bool first = true;
                while (xmlinput.FindSubElement(first, new string[] { "symbol", "language" })) {
                    if (xmlinput.Name == "symbol") {
                        Symbol symbol = new Symbol(this);

                        symbol.ReadXml(xmlinput);

                        symbols.Add(symbol.Id, symbol);
                    }
                    else if (xmlinput.Name == "language") {
                        SymbolLanguage language = new SymbolLanguage();

                        language.ReadXml(xmlinput);
                        languages.Add(language.LangId, language);
                    }

                    first = false;
                }
            }
        }
Ejemplo n.º 11
0
        private void addDescriptionLanguageMenu_Click(object sender, EventArgs e)
        {
            DebugUI.NewLanguage newLanguageDialog = new NewLanguage();

            if (newLanguageDialog.ShowDialog(this) == DialogResult.OK) {
                SymbolLanguage symLanguage = new SymbolLanguage(newLanguageDialog.LanguageName, newLanguageDialog.LangId, newLanguageDialog.PluralNouns,
                    newLanguageDialog.PluralModifiers, newLanguageDialog.GenderModifiers,
                    newLanguageDialog.GenderModifiers ? newLanguageDialog.Genders.Split(new string[] {",", " "}, StringSplitOptions.RemoveEmptyEntries) : new string[0],
                    newLanguageDialog.CaseModifiers,
                    newLanguageDialog.CaseModifiers ? newLanguageDialog.Cases.Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries) : new string[0]);
                controller.AddDescriptionLanguage(symLanguage);
                controller.SetDescriptionLanguage(symLanguage.LangId);
            }
        }