3

I've been struggling with automatic slug generation in Czech language: there are letters such as "š" or "č" and Craft has a charactere map hardcoded in craft/app/resources/js/craft.js, resp. craft/app/resources/js/compressed/craft.js, which tells craft to convert "š" to "sh" and "č" to "zh" for instance.

In Czech language that is not necessary; it's rather bad behavior which I need to change. Letter "š" should become "s" etc.

Is there any systematic way how to configure this character map?

I technically have no problems with rewriting the table, although that solution might either cause errors with automatic updates or my changes could get rolled back with every update - neither being good.

PS: This issue is NOT related to the same thing as here: How to transform German umlauts when creating slugs? - the described behavior is in place even with "limitAutoSlugsToAscii == 1"

UPDATE:

In case this question was not resolved yet or had no solution, here is a minified charmap which works as a hotfix to Craft issues with Czech slugs: http://pastebin.com/pc6etBFu

It works as a drop-in replacement for the same map in craft/app/resources/js/compressed/craft.js. My current version of craft is Craft Pro 2.3.2643

2

Yeah, this is an issue we're aware of of the 2.x branch that's been resolved for Craft 3.x and we probably won't back-port because of the complexity involved.

But in 2.x, we naively assumed that there was going to be a 1:1 mapping between the character that needed to be replaced and it's replacement.

Turns out that is by no means the case.

So for Craft 3, we're using the Stringy library and you can see they have a 1:many mapping and the š character properly maps over to s.

2
  • Cyrillic characters with limitAutoSlugsToAscii set to true in Craft 2.x don't get converted at all, neither in slugs or in filenames (with convertFilenamesToAscii set to true). So with the first option turned on we get an empty slug saved for the first entry after changing config and URI "" has already been taken. message for the all following entries (and this makes it impossible to save them at all). ` – certainlyakey Jul 13 '15 at 14:27
  • Any values included in customAsciiCharMappings do not affect this behaviour, whether they are Cyrillic ('ж' => 'zh') or Latin ('F' => 'ph'). – certainlyakey Jul 13 '15 at 14:37
3

You can try using my plugin, which will overwrite the character map in craft.js by applying the customAsciiCharMappings setting:

https://github.com/farmstudio/slugcharmap

Tell me if it's working for you.

1

In Czech language that is not necessary; it's rather bad behavior which I need to change.

If this is true, you should email the issue to P&T and I'm sure they will update the mapping table for the next release.

Update: I don't think there's a (good) workaround, the table is hardcoded into craft.js and the function that generates the slugs only got the option to disable the character replacement completely. You could disable it and try to add your own JS that replicated the functionality with a custom plugin, this might work. But I actually think you should report that issue to P&T and they will probably come up with a solution to make all Czech happy without the need for any plugin.

3
  • it might be desired behavior in other languages, so updating the mapping table for Czech language might break some other languages. I will report a feature request to configure mapping table on-fly, but first I'd like to be sure there is no workaround or recommended procedure to already achieve that. I haven't found any, but I am new to Craft, so I might be missing something – Jan Klan Apr 9 '15 at 8:13
  • Ahh now I get it, so this actually needs to be language dependant what it isn't right now. – carlcs Apr 9 '15 at 9:16
  • That's exactly the problem. – Jan Klan Apr 10 '15 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.