Exemplo n.º 1
0
        private void WriteDisplayNameFieldForOption(IValueHolder <string> optionRef, string fieldName)
        {
            OptionsList list = WeSayWordsProject.Project.GetOptionsList(fieldName);

            if (list != null)
            {
                Option posOption = list.GetOptionFromKey(optionRef.Value);
                if (posOption == null)
                {
                    return;
                }
                if (posOption.Name == null)
                {
                    return;
                }

                LanguageForm[] labelForms =
//                        posOption.Name.GetOrderedAndFilteredForms(
                    posOption.Abbreviation.GetOrderedAndFilteredForms(
                        _viewTemplate.GetField(fieldName).WritingSystemIds);

                if (labelForms != null && labelForms.Length > 0)
                {
                    Writer.WriteStartElement("field");
                    Writer.WriteAttributeString("type",
                                                fieldName == "POS" ? "grammatical-info" : fieldName);
                    WriteLanguageFormsInWrapper(labelForms, "form", false);
                    Writer.WriteEndElement();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update the users' field inventory with new stuff.
        /// </summary>
        /// <remarks>
        /// used in the admin to update the users template with new fields.
        ///
        /// This was written before, and should not to be confused with,
        ///  MigrateConfigurationXmlIfNeeded(), which could
        /// do most of this work. It's not obvious how that would get the guess
        /// of which writing systems to assign in (but that's not a big deal).
        ///
        /// The algorithm here is to fill the list with all of the fields from the master inventory.
        /// If a field is also found in the users existing inventory, turn on the checkbox,
        /// and change any settings (e.g. the writing systems) to match the users' inventory spec.
        /// Then add any custom fields from the existing inventory.
        /// </remarks>
        /// <param name="factoryTemplate"></param>
        /// <param name="usersTemplate"></param>
        public static void UpdateUserViewTemplate(ViewTemplate factoryTemplate,
                                                  ViewTemplate usersTemplate)
        {
            if (factoryTemplate == null)
            {
                throw new ArgumentNullException();
            }
            if (usersTemplate == null)
            {
                throw new ArgumentNullException();
            }

            // handled by xslt           //in jan 2008 we changed this field name, moving it in line with the lift spec
            //            const string oldGlossFieldName = "SenseGloss";
            //            Field userGlossField = usersTemplate.GetField(oldGlossFieldName);
            //            if (userGlossField != null)
            //            {
            //                userGlossField.FieldName = LexSense.WellKnownProperties.Gloss;
            //            }

            foreach (Field masterField in factoryTemplate)
            {
                Field userField = usersTemplate.GetField(masterField.FieldName);
                if (userField != null)
                {
                    //allow us to improve the descriptions
                    userField.Description = masterField.Description;
                }
                else
                {
                    masterField.Enabled = false;                     //let them turn it on if they want
                    usersTemplate.Fields.Add(masterField);
                }
            }

            if (factoryTemplate.GetField(LexSense.WellKnownProperties.Definition) == null)
            {
                return;                 // this is some  test situation with a abnormal factory template
            }

            usersTemplate.MoreMigrations();
        }
Exemplo n.º 3
0
        internal void SetWritingSystemsForFields()
        {
            var liftDom = new XmlDocument();

            liftDom.Load(_path);             //will throw if the file is ill-formed
            var missingWritingSystems = new StringBuilder();

            foreach (XmlNode node in liftDom.SelectNodes("//@lang"))
            {
                if (node.Value == "x-spec" && !_writingSystems.Contains("x-spec"))
                {
                    _writingSystems.Set(WritingSystemDefinition.Parse("x-spec"));
                }
                if (!_writingSystems.Contains(node.Value))
                {
                    _writingSystems.Set(WritingSystemDefinition.Parse(node.Value));
                    missingWritingSystems.AppendFormat("{0},", node.Value);
                }
            }
            _writingSystems.Save();

            if (missingWritingSystems.Length > 0)
            {
                var list = missingWritingSystems.ToString().Trim(new[] { ',' });
                ErrorReport.NotifyUserOfProblem(
                    "WeSay had a problem locating information on at least one input system used in the LIFT export from FLEx.  One known cause of this is an old version of FLEx. In the folder containing the LIFT file, there should have been '___.ldml' files for the following input systems: {0}.\r\nBecause these input system definitions were not found, WeSay will create blank input systems for each of these, which you will need to set up with the right fonts, keyboards, etc.", list);
            }
            // replace all "v" fields with the first lexical-unit writing system
            //and all "en" with the first translation one...

            var vernacular = GetTopWritingSystem(liftDom, "//lexical-unit/form/@lang");

            if (vernacular != String.Empty)
            {
                _viewTemplate.OnWritingSystemIDChange(WeSayWordsProject.VernacularWritingSystemIdForProjectCreation, vernacular);
                if (_writingSystems.Contains(WeSayWordsProject.VernacularWritingSystemIdForProjectCreation))
                {
                    _writingSystems.Remove(WeSayWordsProject.VernacularWritingSystemIdForProjectCreation);
                }
            }
            var analysis = GetTopWritingSystem(liftDom, "//sense/gloss/@lang");

            if (analysis == String.Empty)
            {
                analysis = GetTopWritingSystem(liftDom, "//sense/definition/@lang");
                //nb: we don't want to remove english, even if they don't use it
            }
            if (analysis != String.Empty)
            {
                _viewTemplate.OnWritingSystemIDChange(WeSayWordsProject.AnalysisWritingSystemIdForProjectCreation, analysis);
            }

            AddWritingSystemsForField(liftDom, "//lexical-unit/form/@lang", LexEntry.WellKnownProperties.LexicalUnit);
            AddWritingSystemsForField(liftDom, "//sense/gloss/@lang", LexSense.WellKnownProperties.Gloss);

            AddWritingSystemsForField(liftDom, "//sense/definition/form/@lang", LexSense.WellKnownProperties.Definition);

            AddAllGlossWritingSystemsToDefinition();

            AddWritingSystemsForField(liftDom, "//example/form/@lang", LexExampleSentence.WellKnownProperties.ExampleSentence);
            AddWritingSystemsForField(liftDom, "//translation/form/@lang", LexExampleSentence.WellKnownProperties.Translation);

            //------------ hack
            var gloss = _viewTemplate.GetField(LexSense.WellKnownProperties.Gloss);
            var def   = _viewTemplate.GetField(LexSense.WellKnownProperties.Definition);

            foreach (var id in def.WritingSystemIds)
            {
                if (!gloss.WritingSystemIds.Contains(id))
                {
                    gloss.WritingSystemIds.Add(id);
                }
            }
            foreach (var id in gloss.WritingSystemIds)
            {
                if (!def.WritingSystemIds.Contains(id))
                {
                    def.WritingSystemIds.Add(id);
                }
            }
        }