WordPress.org

Ready to get started?Download WordPress

Forums

How can I make correct this character conversion (12 posts)

  1. Nikolas
    Member
    Posted 4 years ago #

    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();
    ?>
  2. Nikolas
    Member
    Posted 4 years ago #

    anyone ?

  3. Nikolas
    Member
    Posted 4 years ago #

    any ideas?

  4. Nikolas
    Member
    Posted 4 years ago #

    hello ?

  5. Nikolas
    Member
    Posted 4 years ago #

    any good person? :P

  6. MichaelH
    Member
    Posted 4 years ago #

    Please note I deleted your duplicate topic. Please refrain from creating duplicate topics and bumping.

    See Forum Rules

  7. Nikolas
    Member
    Posted 4 years ago #

    ano ole ano ole oloi mia mana exete

  8. MichaelH
    Member
    Posted 4 years ago #

    I deleted your duplicat topic. Please quit posting duplicate threads. Please!

  9. Nikolas
    Member
    Posted 4 years ago #

    but nobody answer this easy question ....

  10. Nikolas
    Member
    Posted 4 years ago #

    anyone?

  11. MichaelH
    Member
    Posted 4 years ago #

    Might ask your question at http://ru.forums.wordpress.org/

  12. lenasterg
    Member
    Posted 3 years ago #


Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.