Fix on unicode taxonomies.

Jun 11, 2011 at 5:10 AM

I used the module on my project and since my taxonomy names were in unicode, there were problem when creating the term for it as the slugify function on route module couldn't find the right term part for it.

I have created a function to convert my termpart in to non_unicode characters when created. Just want to share with you guys if somebody may have the same problem as me.

 

I have added these code on to the CreateTermContentType function 

 public void CreateTermContentType(TaxonomyPart taxonomy) {           

// create the associated term's content type                      

//TVT convert system name to non-unicode           

var name = UnUnicode.ConvertToUnSign( GenerateTermTypeName(taxonomy.Name));           

 //TVT replace with name    

 taxonomy.TermTypeName =name;         

_contentDefinitionManager.AlterTypeDefinition(name,                 cfg => cfg                    .WithSetting("TaxonomyId", taxonomy.Id.ToString())                    .WithPart("TermPart")                    .WithPart("RoutePart")                    .WithPart("CommonPart")                    .DisplayedAs(taxonomy.Name + " Term")                );

            RefreshSlugConstraints();     

}

 

Here is my UnUnicode helper

using System;using System.Collections.Generic;using System.Linq;using System.Text.RegularExpressions;using System.Web;
namespace Contrib.Taxonomies.Helpers{    public class UnUnicode    {        public static string ConvertToUnSign(string text)        {
            for (int i = 33; i < 48; i++)            {
                text = text.Replace(((char)i).ToString(), "");
            }


            for (int i = 58; i < 65; i++)            {
                text = text.Replace(((char)i).ToString(), "");
            }


            for (int i = 91; i < 97; i++)            {
                text = text.Replace(((char)i).ToString(), "");
            }
            for (int i = 123; i < 127; i++)            {
                text = text.Replace(((char)i).ToString(), "");
            }
            //text = text.Replace(" ", "-");
            Regex regex = new Regex(@"\p{IsCombiningDiacriticalMarks}+");
            string strFormD = text.Normalize(System.Text.NormalizationForm.FormD);
            return regex.Replace(strFormD, String.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D');
        }    }}