コード例 #1
0
        internal void EnsureIeftLanguageTagsUnique(IEnumerable <LdmlMigrationInfo> migrationInfo)
        {
            var uniqueLanguageTags = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);

            foreach (LdmlMigrationInfo info in migrationInfo)
            {
                LdmlMigrationInfo currentInfo = info;
                if (uniqueLanguageTags.Contains(currentInfo.LanguageTagAfterMigration))
                {
                    if (currentInfo.LanguageTagBeforeMigration.Equals(currentInfo.LanguageTagAfterMigration, StringComparison.InvariantCultureIgnoreCase))
                    {
                        // We want to change the other, because we are the same. Even if the other is the same, we'll change it anyway.
                        LdmlMigrationInfo otherInfo = _migrationInfo.First(
                            i => i.LanguageTagAfterMigration.Equals(currentInfo.LanguageTagAfterMigration, StringComparison.InvariantCultureIgnoreCase)
                            );
                        otherInfo.LanguageTagAfterMigration = IetfLanguageTag.ToUniqueLanguageTag(
                            otherInfo.LanguageTagAfterMigration, uniqueLanguageTags);
                        uniqueLanguageTags.Add(otherInfo.LanguageTagAfterMigration);
                    }
                    else
                    {
                        currentInfo.LanguageTagAfterMigration = IetfLanguageTag.ToUniqueLanguageTag(
                            currentInfo.LanguageTagAfterMigration, uniqueLanguageTags);
                        uniqueLanguageTags.Add(currentInfo.LanguageTagAfterMigration);
                    }
                }
                else
                {
                    uniqueLanguageTags.Add(currentInfo.LanguageTagAfterMigration);
                }
            }
        }
コード例 #2
0
        public void ToUniqueLanguageTag_LanguageTagAlreadyContainsADuplicateMarker_DuplicateNumberIsMaintainedAndNewOneIsIntroduced()
        {
            var existingTags = new[] { "en-Zxxx-x-dupl0-audio", "en-Zxxx-x-audio-dupl1" };
            var ws           = new WritingSystemDefinition("en-Zxxx-x-dupl0-audio");

            ws.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(ws.LanguageTag, existingTags);
            Assert.That(ws.LanguageTag, Is.EqualTo("en-Zxxx-x-dupl0-audio-dupl1"));
        }
コード例 #3
0
        public override WritingSystemDefinition ShowDialogIfNeededAndGetDefinition()
        {
            WritingSystemDefinition ws = WritingSystemFactory.Create(_templateWritingSystemDefinition);

            ws.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(
                ws.LanguageTag, _existingWritingSystemsForLanguage.Select(w => w.LanguageTag));
            return(ws);
        }
コード例 #4
0
        public void ToUniqueLanguageTag_IdIsNull()
        {
            var existingTags = new[] { "en-Zxxx-x-audio" };
            var ws           = new WritingSystemDefinition("de");

            ws.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(ws.LanguageTag, existingTags);
            Assert.That(ws.Id, Is.Null);
        }
コード例 #5
0
        public void ToUniqueLanguageTag_ADuplicatewithHigherNumberAlreadyExists_DuplicateMarkerWithLowNumberIsAppended()
        {
            var existingTags = new[] { "en-Zxxx-x-audio", "en-Zxxx-x-audio-dupl1" };
            var ws           = new WritingSystemDefinition("en-Zxxx-x-audio");

            ws.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(ws.LanguageTag, existingTags);
            Assert.That(ws.LanguageTag, Is.EqualTo("en-Zxxx-x-audio-dupl0"));
        }
コード例 #6
0
        public void ToUniqueLanguageTag_IsNotUnique_DuplicateMarkerIsAppended()
        {
            var existingTags = new[] { "en-Zxxx-x-audio" };
            var ws           = new WritingSystemDefinition("en-Zxxx-x-audio");

            ws.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(ws.LanguageTag, existingTags);
            Assert.That(ws.LanguageTag, Is.EqualTo("en-Zxxx-x-audio-dupl0"));
        }
コード例 #7
0
        public void ToUniqueLanguageTag_IsAlreadyUnique_NothingChanges()
        {
            var existingTags = new[] { "en-Zxxx-x-audio" };
            var ws           = new WritingSystemDefinition("de");

            ws.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(ws.LanguageTag, existingTags);
            Assert.That(ws.LanguageTag, Is.EqualTo("de"));
        }
コード例 #8
0
        ///<summary>
        /// Constructor.
        ///</summary>
        ///<param name="idsInFile"></param>
        ///<param name="replaceIdsInFile"></param>
        ///<param name="writingSystemRepository"></param>
        public static void FindOrphans(
            IEnumerable <string> idsInFile,
            IdReplacementStrategy replaceIdsInFile,
            IWritingSystemRepository writingSystemRepository)
        {
            List <string> originalIds = idsInFile.ToList();
            List <string> updatedIds  = originalIds.ToList();

            foreach (string wsId in originalIds)
            {
                // Check if it's in the repo
                if (writingSystemRepository.Contains(wsId))
                {
                    continue;
                }
                string newId;
                if (writingSystemRepository.WritingSystemIdHasChanged(wsId))
                {
                    newId = writingSystemRepository.WritingSystemIdHasChangedTo(wsId);
                }
                else
                {
                    // It's an orphan
                    // Clean it
                    var rfcTagCleaner = new IetfLanguageTagCleaner(wsId);
                    rfcTagCleaner.Clean();
                    newId = rfcTagCleaner.GetCompleteTag();
                }

                WritingSystemDefinition conformantWritingSystem;
                writingSystemRepository.WritingSystemFactory.Create(newId, out conformantWritingSystem);
                // If it changed, then change
                if (conformantWritingSystem.LanguageTag != wsId)
                {
                    conformantWritingSystem.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(
                        conformantWritingSystem.LanguageTag, updatedIds);
                    replaceIdsInFile(wsId, conformantWritingSystem.LanguageTag);
                    updatedIds.Remove(wsId);
                    updatedIds.Add(conformantWritingSystem.LanguageTag);
                }

                // Check if it's in the repo
                if (writingSystemRepository.Contains(conformantWritingSystem.LanguageTag))
                {
                    continue;
                }

                // It's not in the repo so set it
                writingSystemRepository.Set(conformantWritingSystem);
            }
            writingSystemRepository.Save();
        }