Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Wrong culture letters in URL if you create new blog post View modes: 
User avatar
Member
Member
Alex - 12/8/2010 10:01:17 AM
   
Wrong culture letters in URL if you create new blog post
I create new blog post.
And write title of post in russian letters in culture ru-RU.

After saving it automatically copies the title as URL of this post. But in russian letters! It is wrong. Url must be only in latin letters.
How can resolve this problem?

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 12/9/2010 5:54:56 AM
   
RE:Wrong culture letters in URL if you create new blog post
Hi,

you can change the URL in the Properties of blog post document. Document alias field in the URLs tab. This way the title of blog post will be in Russian and in the URL will be only latin letters. The original alias you can delete in Document aliases part.

If you would like to use latin letters by default you will need to develop custom tree node handler that replaces Russian alphabet with latin.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
Alex - 1/28/2011 7:01:18 AM
   
RE:Wrong culture letters in URL if you create new blog post
Do you have more simple solution?

I only need that Russian letters in Document name is automatically saved in the custom URL path as Latin characters when the document is created.

Do you understand what it is an error?
If User create new blog post on any language exept english then he get this error if he decide to view, edit or delete this post?

I think you can solve this problem in next updates.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 2/7/2011 8:58:19 AM
   
RE:Wrong culture letters in URL if you create new blog post
Hi,

Unfortunately, there is no conversion class implemented in the current version of Kentico, therefore the custom tree node handler is the easiest solution. I have created a requirement to add this functionality into one of next versions. I am sorry for inconvenience.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
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();
}
}
}