getkirby-v2 / toolkit

This is the deprecated toolkit for Kirby v2.
http://getkirby.com
81 stars 50 forks source link

Ascii foreign chars can set from options #96

Closed afbora closed 8 years ago

afbora commented 9 years ago

In our language as turkish, some chars broken on url address. I just implement that ascii chars can set from options.

Wrong convert: Üsküdar > ueskuedar Right convert: Üsküdar > uskudar

Wrong convert: Öğrenci > oegrenci Right convert: Öğrenci > ogrenci

Sample Usage

c::set('ascii', array(
                    '/Ä/' => 'Ae',
                    '/æ|ǽ|ä/' => 'ae',
                    '/œ|ö/' => 'oe',
                    '/À|Á|Â|Ã|Å|Ǻ|Ā|Ă|Ą|Ǎ|А/' => 'A',
                    '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|а/' => 'a',
                    '/Б/' => 'B',
                    '/б/' => 'b',
                    '/Ç|Ć|Ĉ|Ċ|Č|Ц/' => 'C',
                    '/ç|ć|ĉ|ċ|č|ц/' => 'c',
                    '/Ð|Ď|Đ/' => 'Dj',
                    '/ð|ď|đ/' => 'dj',
                    '/Д/' => 'D',
                    '/д/' => 'd',
                    '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Е|Ё|Э/' => 'E',
                    '/è|é|ê|ë|ē|ĕ|ė|ę|ě|е|ё|э/' => 'e',
                    '/Ф/' => 'F',
                    '/ƒ|ф/' => 'f',
                    '/Ĝ|Ğ|Ġ|Ģ|Г/' => 'G',
                    '/ĝ|ğ|ġ|ģ|г/' => 'g',
                    '/Ĥ|Ħ|Х/' => 'H',
                    '/ĥ|ħ|х/' => 'h',
                    '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|И/' => 'I',
                    '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|и/' => 'i',
                    '/Ĵ|Й/' => 'J',
                    '/ĵ|й/' => 'j',
                    '/Ķ|К/' => 'K',
                    '/ķ|к/' => 'k',
                    '/Ĺ|Ļ|Ľ|Ŀ|Ł|Л/' => 'L',
                    '/ĺ|ļ|ľ|ŀ|ł|л/' => 'l',
                    '/М/' => 'M',
                    '/м/' => 'm',
                    '/Ñ|Ń|Ņ|Ň|Н/' => 'N',
                    '/ñ|ń|ņ|ň|ʼn|н/' => 'n',
                    '/Ö/' => 'O',
                    '/ö/' => 'o',
                    '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|О/' => 'O',
                    '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|о/' => 'o',
                    '/П/' => 'P',
                    '/п/' => 'p',
                    '/Ŕ|Ŗ|Ř|Р/' => 'R',
                    '/ŕ|ŗ|ř|р/' => 'r',
                    '/Ś|Ŝ|Ş|Ș|Š|С/' => 'S',
                    '/ś|ŝ|ş|ș|š|ſ|с/' => 's',
                    '/Ţ|Ț|Ť|Ŧ|Т/' => 'T',
                    '/ţ|ț|ť|ŧ|т/' => 't',
                    '/Ü/' => 'U',
                    '/ü/' => 'u',
                    '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|У/' => 'U',
                    '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|у/' => 'u',
                    '/В/' => 'V',
                    '/в/' => 'v',
                    '/Ý|Ÿ|Ŷ|Ы/' => 'Y',
                    '/ý|ÿ|ŷ|ы/' => 'y',
                    '/Ŵ/' => 'W',
                    '/ŵ/' => 'w',
                    '/Ź|Ż|Ž|З/' => 'Z',
                    '/ź|ż|ž|з/' => 'z',
                    '/Æ|Ǽ/' => 'AE',
                    '/ß/'=> 'ss',
                    '/IJ/' => 'IJ',
                    '/ij/' => 'ij',
                    '/Œ/' => 'OE',
                    '/Ч/' => 'Ch',
                    '/ч/' => 'ch',
                    '/Ю/' => 'Ju',
                    '/ю/' => 'ju',
                    '/Я/' => 'Ja',
                    '/я/' => 'ja',
                    '/Ш/' => 'Sh',
                    '/ш/' => 'sh',
                    '/Щ/' => 'Shch',
                    '/щ/' => 'shch',
                    '/Ж/' => 'Zh',
                    '/ж/' => 'zh',
                  )
    );
bastianallgeier commented 8 years ago

I won't fix this for now. I need to find a better solution here in general. In German the matching fits so I think we need language based translations somehow, but this needs more work and thinking.

afbora commented 8 years ago

I want to give an example from CodeIgniter framework. https://github.com/bcit-ci/CodeIgniter/blob/develop/application/config/foreign_chars.php

So for example on Kirby:

if /site/config/foreign_chars.php file exists, override foreign characters otherwise set defaults.

This feature is optional not required so will only use users who have needs.

distantnative commented 8 years ago

I agree with Bastian that finding a different approach to this (probably based on translations) might be the better way to go.

Until then, you can easily use something like this in your config.php:

str::$ascii = a::merge(str::$ascii, array(
  '/Ä/' => 'A',
  '/æ|ǽ|ä/' => 'a',
  '/œ|ö/' => 'o',
  '/Ö/' => 'O',
  '/ö/' => 'o',
  '/Ü/' => 'U',
  '/ü/' => 'u',
));
afbora commented 8 years ago

@distantnative great solution :+1: Tested and works perfect!