Beispiel #1
0
        /// <summary> Exports vernacular language character set to an ldml file </summary>
        private static void LdmlExport(string filePath, string vernacularBcp47, List <string> validChars)
        {
            var wsr = LdmlInFolderWritingSystemRepository.Initialize(filePath);
            var wsf = new LdmlInFolderWritingSystemFactory(wsr);

            wsf.Create(vernacularBcp47, out var wsDef);

            // If there isn't already a main character set defined,
            // make one and add it to the writing system definition.
            if (!wsDef.CharacterSets.TryGet("main", out var chars))
            {
                chars = new CharacterSetDefinition("main");
                wsDef.CharacterSets.Add(chars);
            }

            // Replace all the characters found with our copy of the character set
            chars.Characters.Clear();
            foreach (var character in validChars)
            {
                chars.Characters.Add(character);
            }

            // Write out the new definition
            wsr.Set(wsDef);
            wsr.Save();
        }
Beispiel #2
0
        /// <summary> Imports main character set for a project from an ldml file </summary>
        public void LdmlImport(string filePath, string langTag, IProjectRepository projRepo, Project project)
        {
            var wsr = LdmlInFolderWritingSystemRepository.Initialize(filePath);
            var wsf = new LdmlInFolderWritingSystemFactory(wsr);

            wsf.Create(langTag, out var wsDef);

            // If there is a main character set, import it to the project
            if (wsDef.CharacterSets.Contains("main"))
            {
                project.ValidCharacters = wsDef.CharacterSets["main"].Characters.ToList();
                projRepo.Update(project.Id, project);
            }
        }
        /// <summary> Exports main character set from a project to an ldml file </summary>
        private void LdmlExport(string filePath, string langTag)
        {
            // SLDR is the SIL Locale Data repository, it is necessary for reading/writing ldml
            // It is being initialized in offline mode here to only pull local data
            Sldr.Initialize(true);
            try
            {
                var wsr = LdmlInFolderWritingSystemRepository.Initialize(filePath);
                var wsf = new LdmlInFolderWritingSystemFactory(wsr);
                wsf.Create(langTag, out var wsDef);

                var proj = _projService.GetProject(_projectId).Result;

                // If there isn't already a main character set defined, make one and add it to the writing system
                // definition
                if (!wsDef.CharacterSets.TryGet("main", out var chars))
                {
                    chars = new CharacterSetDefinition("main");
                    wsDef.CharacterSets.Add(chars);
                }

                // Replace all the characters found with our copy of the character set
                chars.Characters.Clear();
                foreach (var character in proj.ValidCharacters)
                {
                    chars.Characters.Add(character);
                }

                // Write out the new definition
                wsr.Set(wsDef);
                wsr.Save();
            }
            finally
            {
                // If there was somehow an error above, we still want to cleanup to prevent unhelpful errors later
                Sldr.Cleanup();
            }
        }
        /// <summary> Imports main character set for a project from an ldml file </summary>
        public void LdmlImport(string filePath, string langTag)
        {
            // SLDR is the SIL locale data repository, it is necessary for reading/writing ldml
            // It is being initialized in offline mode here to only pull local data
            Sldr.Initialize(true);
            try
            {
                var wsr = LdmlInFolderWritingSystemRepository.Initialize(filePath);
                var wsf = new LdmlInFolderWritingSystemFactory(wsr);
                wsf.Create(langTag, out var wsDef);

                //if there is a main character set, import it to the project
                if (wsDef.CharacterSets.Contains("main"))
                {
                    var newProj = _projService.GetProject(_projectId).Result;
                    newProj.ValidCharacters = wsDef.CharacterSets["main"].Characters.ToList();
                    _projService.Update(_projectId, newProj);
                }
            }
            finally //if there was somehow an error above, we still want to cleanup to prevent unhelpful errors later
            {
                Sldr.Cleanup();
            }
        }