Alex
-
2/7/2011 9:12:03 AM
RE:Wrong culture letters in URL if you create new blog post
Yes, I solve this solution and create custom tree node handler
Here it is
// Function for converting cyrilic letters to latin const string Cyrillic = "АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщъыьЭэЮюЯя"; const string Latin = "A|a|B|b|V|v|G|g|D|d|E|e|E|e|Zh|zh|Z|z|I|i|I|i|K|k|L|l|M|m|N|n|O|o|P|p|R|r|S|s|T|t|U|u|F|f|Kh|kh|Sh|sh|Ch|ch|Sh|sh|Shch|shch||y||E|e|Yu|yu|Ya|ya"; Dictionary<char, string> mLookup;
public string Romanize(string russian) { if (mLookup == null) { mLookup = new Dictionary<char, string>(); var replace = Latin.Split('|'); for (int ix = 0; ix < Cyrillic.Length; ++ix) { mLookup.Add(Cyrillic[ix], replace[ix]); } } var buf = new StringBuilder(russian.Length); foreach (char ch in russian) { if (mLookup.ContainsKey(ch)) buf.Append(mLookup[ch]); else buf.Append(ch); } return buf.ToString(); }
public override void OnAfterInsert(object treeNodeObj, int parentNodeId, object tree) { TreeNode newsDoc = (TreeNode)treeNodeObj;
if (newsDoc.NodeClassName.ToLower() == "cms.blogpost") { if (newsDoc != null) { System.Globalization.DateTimeFormatInfo dEn = new System.Globalization.DateTimeFormatInfo(); string BlogPostTitle = ValidationHelper.GetString(newsDoc.GetValue("BlogPostTitle"), ""); var BlogPostDate = ValidationHelper.GetDateTime(newsDoc.GetValue("BlogPostDate"), new DateTime(2011, 1, 1)); int monthName = BlogPostDate.Month; string BlogMonthandYear = dEn.MonthNames[monthName-1] + "-" + DateTime.Now.Year; newsDoc.SetValue("NodeAlias", Romanize(BlogPostTitle)); newsDoc.Update(); } }
// For convert MonthName if (newsDoc.NodeClassName.ToLower() == "cms.blogmonth") { if (newsDoc != null) { System.Globalization.DateTimeFormatInfo dEn = new System.Globalization.DateTimeFormatInfo(); System.Globalization.DateTimeFormatInfo dRu = new System.Globalization.CultureInfo("ru-RU", false).DateTimeFormat; var BlogPostDate = ValidationHelper.GetDateTime(newsDoc.GetValue("BlogMonthStartingDate"), new DateTime(2011, 1, 1)); int monthName = BlogPostDate.Month; string BlogMonthandYear = dEn.MonthNames[monthName - 1] + "-" + DateTime.Now.Year; string BlogMonthRu = dRu.MonthNames[monthName-1]; newsDoc.SetValue("BlogMonthName", BlogMonthRu); newsDoc.SetValue("NodeName", BlogMonthRu); newsDoc.SetValue("DocumentName", BlogMonthRu); newsDoc.SetValue("NodeAlias", BlogMonthandYear); newsDoc.Update(); } } }
|