コード例 #1
0
        // There's some confusion between the Palaso migrator and our version 19 migrator about whether an old language
        // tag should have multiple X's if it has more than one private-use component. Since such X's are not
        // significant, ignore them.
        private bool TryGetNewTag(string oldTag, out string newTag)
        {
            string key = RemoveMultipleX(oldTag.ToLowerInvariant());

            if (m_tagMap.TryGetValue(key, out newTag))
            {
                return(!newTag.Equals(oldTag, StringComparison.OrdinalIgnoreCase));
            }
            var cleaner = new IetfLanguageTagCleaner(oldTag);

            cleaner.Clean();
            // FieldWorks needs to handle this special case.
            if (cleaner.Language.ToLowerInvariant() == "cmn")
            {
                var region = cleaner.Region;
                if (string.IsNullOrEmpty(region))
                {
                    region = "CN";
                }
                cleaner = new IetfLanguageTagCleaner("zh", cleaner.Script, region, cleaner.Variant, cleaner.PrivateUse);
            }
            newTag = cleaner.GetCompleteTag();
            while (m_tagMap.Values.Contains(newTag, StringComparer.OrdinalIgnoreCase))
            {
                // We can't use this tag because it would conflict with what we are mapping something else to.
                cleaner = new IetfLanguageTagCleaner(cleaner.Language, cleaner.Script, cleaner.Region, cleaner.Variant,
                                                     WritingSystemIdMigrator.GetNextDuplPart(cleaner.PrivateUse));
                newTag = cleaner.GetCompleteTag();
            }
            m_tagMap[key] = newTag;
            return(!newTag.Equals(oldTag, StringComparison.OrdinalIgnoreCase));
        }
コード例 #2
0
 public void GetNextDuplPart()
 {
     Assert.That(WritingSystemIdMigrator.GetNextDuplPart(null), Is.EqualTo("dupl1"));
     Assert.That(WritingSystemIdMigrator.GetNextDuplPart(""), Is.EqualTo("dupl1"));
     Assert.That(WritingSystemIdMigrator.GetNextDuplPart("abc"), Is.EqualTo("abc-dupl1"));
     Assert.That(WritingSystemIdMigrator.GetNextDuplPart("dupl1"), Is.EqualTo("dupl2"));
     Assert.That(WritingSystemIdMigrator.GetNextDuplPart("abc-def-dupl12"), Is.EqualTo("abc-def-dupl13"));
 }
コード例 #3
0
        private bool TryGetNewLangTag(string oldTag, out string newTag)
        {
            if (m_tagMap.TryGetValue(oldTag, out newTag))
            {
                return(!newTag.Equals(oldTag));
            }

            var cleaner = new IetfLanguageTagCleaner(oldTag);

            cleaner.Clean();
            newTag = cleaner.GetCompleteTag();
            while (m_tagMap.Values.Contains(newTag))
            {
                // We can't use this tag because it would conflict with what we are mapping something else to.
                cleaner = new IetfLanguageTagCleaner(cleaner.Language, cleaner.Script, cleaner.Region, cleaner.Variant,
                                                     WritingSystemIdMigrator.GetNextDuplPart(cleaner.PrivateUse));
                newTag = cleaner.GetCompleteTag();
            }

            m_tagMap[oldTag] = newTag;
            return(!newTag.Equals(oldTag));
        }