WordPress.org

Support

Support » How-To and Troubleshooting » How can I make correct this character conversion

How can I make correct this character conversion

  • Hello I tried two plugins but I got the same error. Those plugins converts the cyrillic characters used in the post slug into latin chars.
    However the result is like “aaaaaiaaaaa” and other similar.
    Those are the two plugins :
    Any help is appreciated

    add_filter('name_save_pre', 'cyr_slugs', 0);
    
    function cyr_slugs($slug) {
        $cyrillic = array('ΰ','α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','ς','σ','τ','υ','φ','χ','ψ','ω','ϊ','ό','ϋ','ύ','ώ','');
        $translit = array('a','b','v','g','d','e','zh','z','i','i','k','l','m','n','o','p','r','s','t','u','f','h','c','ch','sh','sht','u','y','y','e','yu','ya');
    
        // We don't want to change an existing slug
    	if ($slug) return $slug;
    
    	global $wpdb;
    	$cyr_slug = cyr_strtolower(strtolower(stripslashes($_POST['post_title'])));
    	$cyr_slug = str_replace($cyrillic, $translit, $cyr_slug);
    	$cyr_slug = str_replace(" ", "-", $cyr_slug);
    
    	return $cyr_slug;
    }
    
    function cyr_strtolower($a) {
    	// Just in case standard strtolower doesn't work
            $offset=32;
            $m=array();
            for($i=192;$i<224;$i++)$m[chr($i)]=chr($i+$offset);
            return strtr($a,$m);
    }
    ?>
    class Cyr2LatSlug
    {
    	var $translit_table = array(
    	"ΰ"=>'a',
    	"α"=>'b',
    	"β"=>'v',
    	"γ"=>'g',
    	"δ"=>'d',
    	"ε"=>'e',
    	"ζ"=>'zh',
    	"η"=>'z',
    	"θ"=>'i',
    	"ι"=>'j',
    	"κ"=>'k',
    	"λ"=>'l',
    	"μ"=>'m',
    	"ν"=>'n',
    	"ξ"=>'o',
    	"ο"=>'p',
    	"π"=>'r',
    	"ρ"=>'s',
    	"ς"=>'t',
    	"σ"=>'u',
    	"τ"=>'f',
    	"υ"=>'h',
    	"φ"=>'c',
    	"χ"=>'ch',
    	"ψ"=>'sh',
    	"ω"=>'sch',
    	"ϊ"=>'',
    	"ϋ"=>'y',
    	"ό"=>'',
    	"ύ"=>'e',
    	"ώ"=>'yu',
    	""=>'ya',
    	"Έ"=>'e',
    	"΄"=>'g',
    	"Ί"=>"e",
    	"Ώ"=>'yi',
    	"³"=>'i',
    	"¨"=>'e',
    	"¥"=>'g',
    	""=>"e",
    	"―"=>'yi',
    	"²"=>'i',
    	" "=>'-');
    
    	function Cyr2LatSlug() {
    		add_filter('name_save_pre', array(&$this, 'doCyr2LatSlug'), 1);
    	}
    
    	function doCyr2LatSlug($slug) {
    		global $wpdb;
    		//setlocale(LC_ALL, 'en_US.UTF8');
    
    	    // We don't want to change an existing slug
    		if (!empty($slug)) {return $slug;}
    
    		$s = trim($_POST['post_title']);
    		$s = iconv('utf-8', 'windows-1251', $s);
    		//$s = mb_strtolower($s, 'windows-1251');
    		$s = $this->cyr_strtolower(strtolower(stripslashes($s)));
    		$s = strtr($s, $this->translit_table);
    		return $s;
    	}
    
    	function cyr_strtolower($a) {
    		// Just in case standard strtolower doesn't work
    		// this function is written by Petko Bossakov
    		$offset=32;
    		$m=array();
    		for($i=192;$i<224;$i++){$m[chr($i)]=chr($i+$offset);}
    		return strtr($a,$m);
    	}
    }
    $Cyr2LatSlug = new Cyr2LatSlug();
    ?>
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How can I make correct this character conversion’ is closed to new replies.
Skip to toolbar