auto generated permalink is strange in Japanese voice sound marked charactors

Jan 27, 2011 at 5:22 AM

Hi, I'm Japanese Orchard user.

In the creating a new page, I input the title using Japanese.
And Orchard is generate permalink automatically.

But, the permalink is not match to the page title.
Voice sound mark is removed.

For example: (please look with Japanese font!)
1) Input title is "ぺいじてすと" then generated permalink is "へいしてすと".
2) Input title is "だあじりん" then generated permalink is "たあしりん".

In Japanese, the presence of voiced sound mark is equivalent to a completely different character.
I think its nice to Orchard modified the rules generate a permalink from a title.

Coordinator
Jan 27, 2011 at 5:39 AM

Please file a bug in the issue tracker.

Jan 27, 2011 at 6:32 AM

Thank you for your reply and leading.

The issue is create in:
http://orchard.codeplex.com/workitem/17266

Developer
Jan 27, 2011 at 6:36 PM

Hi Usagi,

 

If you want to "fix" this problem, you could create a module of your own and overwrite the slug logic to your needs by implementing a ISlugEventHandler. Also, if you want to see the logic we are using you can look at the method FillSlugFromTitle in class RoutableService in the Orchard.Core project.

 

Hope that helps,

Andre

Jan 28, 2011 at 6:09 AM

Thank you, Andre.
Your hint is fit to the problem.

Cause of the problem is the method of RemoveDiacritics(in Orchard.Core.Routable.Services namespace) called from the method of FillSlugFromTitle(in Orchard.Core.Routable.Services).

Its good for a basic Latin character based culture. But, the function is not require by the other cultures. And especially, in Japanese culture, the function is generate strange slug.

I think better if Orchard set out to the neutral for culture then the function split to a module from the core. And the module set disable for default.

---

And quick-fix, I writing the module its copy from a part of FillSlugFromTitle method without RemoveDiacritics function. 

	public class disable_core_slug_remove_diacritics : ISlugEventHandler
	{
		void ISlugEventHandler.FilledSlugFromTitle(FillSlugContext c)
		{
			var disallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""\<\>]+");
			c.Slug = disallowed.Replace(c.Slug, "-").Trim('-');
			if (c.Slug.Length > 1000)
				c.Slug = c.Slug.Substring(0, 1000);
			c.Slug = c.Slug.Trim('.').ToLower();
			c.Adjusted = true;
		}
		void ISlugEventHandler.FillingSlugFromTitle(FillSlugContext c) { }
	}

But, I don't know how to add the my implementation of the ISlugEventHandler to the Orchard ISlugEventHandler list. I read the HelloWorld and create module templete with Command-line. And write the code, and enable the module in a test site in IIS. But, slug is not change. Someone, could you tell me an example module of ISlugEventHandler implementing?

Developer
Jan 28, 2011 at 6:56 PM
Edited Jan 28, 2011 at 7:00 PM

If you use the code generation tool to create a module and implement this class anywhere:

using System.Text.RegularExpressions;

namespace Orchard.Core.Routable.Events {
    public class JapaneseSlugEventHandler : ISlugEventHandler {
        public void FillingSlugFromTitle(FillSlugContext context) {
            var disallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""\<\>]+");

            context.Slug = disallowed.Replace(context.Slug, "-").Trim('-');
            if (context.Slug.Length > 1000)
                context.Slug = context.Slug.Substring(0, 1000);
            context.Slug = context.Slug.Trim('.').ToLower();

            // Processing is done. Don't process further.
            context.Adjusted = true;
        }

        public void FilledSlugFromTitle(FillSlugContext context) {
            // No nothing
        }
    }
}

Orchard will automatically detect that dependency (when the feature is enabled) and inject it. Note that I just copied the code you suggested and adapted it to make it functional.

The problem you had was that you were placing your code under the "Filled" method instead of on the "Filling" method.

Andre

Jan 29, 2011 at 12:46 AM
Edited Jan 29, 2011 at 12:47 AM

Great thanks!

It's work fine on my test environment.
I was miss placing my code in the other namespace.

And, I uploaded the module to Orchard Gallery:
http://orchardproject.net/gallery/Packages/Modules/Details/Japanese-Slug-1-0

Developer
Jan 29, 2011 at 1:05 AM

Actually it wasn't the namespace but the method you were using :) But in any case, glad it works now! :) Awesome work and thank you for uploading your module. Feel free to extend to other module contributions as you explore the platform :)

 

Andre

Jan 29, 2011 at 3:14 AM

I think the problem is not for only Japanese maybe.

RemoveDiacrictics function is not require for Cyrillic, Greek, etc., and Japanese (non-English like character or non-Latin based character languages).
These cultures text can't convert to ASCII use RemoveDiacrictics, and the function bring side-effect(difficult to read) only.
Especially, the side-effect is large in non-Latin based character users(e.g. Japanese).

So, I propose:
 * Split and remove "RemoveDiacrictics" function from Orchard core module.
 * Create new module with the splited "RemoveDiacrictics" function.
 (I think the new module bundled and enabled to Orchard default is good usability for all Orchard existing users :) )

... But, I don't know whether this is necessary for those users.
I'm use Japanese and a little English only.

---
ps. I'm sure develop modules, create themes, and translate UIs for Orchard with enjoy. Thank you Andre.

Developer
Jan 29, 2011 at 3:34 AM
Edited Jan 29, 2011 at 3:36 AM

Sounds reasonable. Could you please open a bug with that description and include a link to this discussion ? That way we can make sure we fix it for orchard vnext. Again, thank you for taking the time into investigating this.

Jan 29, 2011 at 11:12 PM

The issue:
http://orchard.codeplex.com/workitem/17266
(I rewrote the title and the description to organized the thread from copy of this thread the first post.)