Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+7 votes
3.8k views
in Q2A Core by
i have problems with the german letters like ä, ö, ü in url. this letters make them very unclear with a lot of %. is there a possibility to make urls more seo-friendly?
by
You should pick nttnew's answer as the accepted one - I've checked and it works like a charm!

4 Answers

0 votes
by

You can modify the function qa_q_request(...) in qa-base.php, to perform the substitutions on the URL, e.g. using PHP's strtr(...) function.

by
please, can you give me an instruction how to change the code in qa-base.php? i have no experience... thx
by
qa_q_request is for question only, category and tags doesnt work
+2 votes
by

You can add new function to replace your language charater with latin character, after that, you modify function qa_string_remove_accents on qa-util-string.php that return from your new function.

Below is a example that replace Vietnammese characters to latin: 

Step 1: Add new function to qa-util-string.php:

function convert_vi_to_en($str) {
$str = preg_replace('/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/', 'a', $str);
$str = preg_replace('/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/', 'e', $str);
$str = preg_replace('/(ì|í|ị|ỉ|ĩ)/', 'i', $str);
$str = preg_replace('/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/', 'o', $str);
$str = preg_replace('/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/', 'u', $str);
$str = preg_replace('/(ỳ|ý|ỵ|ỷ|ỹ)/', 'y', $str);
$str = preg_replace('/(đ)/', 'd', $str);
$str = preg_replace('/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/', 'A', $str);
$str = preg_replace('/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/', 'E', $str);
$str = preg_replace('/(Ì|Í|Ị|Ỉ|Ĩ)/', 'I', $str);
$str = preg_replace('/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/', 'O', $str);
$str = preg_replace('/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/', 'U', $str);
$str = preg_replace('/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/', 'Y', $str);
$str = preg_replace('/(Đ)/', 'D', $str);
return $str;

 

}
Step 2: change statement: return strtr($string, $qa_utf8removeaccents) on function qa_string_remove_accents($string) to return convert_vi_to_en($string);
 
PS: you must check to Remove accents from question URLs on viewing option in admin panel.
by
What is that replace Turkish characters to latin? How?
+3 votes
by

(since I don't have edit permission for other users' answer, I put my updated version for nttnew's answer here)

In brief

  1. Edit file <<question2answer HOME>>\qa-util-string\qa-util-string.php
     
  2. Look for function qa_string_remove_accents
    and replace its code by the below snippet.
     
  3. Turn on `Remove accents from question URLs` option on admin control page i.e. Admin - Viewing
 
 
function qa_string_remove_accents($string)
/*
Return UTF-8 input $string with all accents (on Roman characters) removed
*/
{
            if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
 
            //global $qa_utf8removeaccents;
            //return strtr($string, $qa_utf8removeaccents);
 
            global $qa_utf8removeaccents;
            $string = strtr($string, $qa_utf8removeaccents);
            $string = convert_vi_to_en($string);
 
            return $string;
}
 
function convert_vi_to_en($str) {
            $str = preg_replace('/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/', 'a', $str);
            $str = preg_replace('/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/', 'e', $str);
            $str = preg_replace('/(ì|í|ị|ỉ|ĩ)/', 'i', $str);
            $str = preg_replace('/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/', 'o', $str);
            $str = preg_replace('/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/', 'u', $str);
            $str = preg_replace('/(ỳ|ý|ỵ|ỷ|ỹ)/', 'y', $str);
            $str = preg_replace('/(đ)/', 'd', $str);
            $str = preg_replace('/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/', 'A', $str);
            $str = preg_replace('/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/', 'E', $str);
            $str = preg_replace('/(Ì|Í|Ị|Ỉ|Ĩ)/', 'I', $str);
            $str = preg_replace('/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/', 'O', $str);
            $str = preg_replace('/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/', 'U', $str);
            $str = preg_replace('/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/', 'Y', $str);
            $str = preg_replace('/(Đ)/', 'D', $str);
            return $str;
}
 
by
not working at all
0 votes
by

Hello there. Here is a solution to keep Turkish characters.

 Add a new function to /qa-include/util/string.php

function qa_keep_turkish_characters($str) 
{
 echo preg_replace('/\xC3\xB6/', 'ö', $str);
 echo preg_replace('/\xC5\x9F/', 'ş', $str);
 echo preg_replace('/\xC3\xBC/', 'Ü', $str);
 echo preg_replace('/\xC3\xAF/', 'ç', $str);
 echo preg_replace('/\xC4\xB1/', 'ı', $str);
 echo preg_replace('/\xC4\x9F/', 'ğ', $str);
 echo preg_replace('/\xC3\xA9/', 'é', $str);
 return $str;
}

Remove accents function became like this.

    function qa_string_remove_accents($string)
    {
     if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }

     //global $qa_utf8removeaccents;
     //return strtr($string, $qa_utf8removeaccents);

     global $qa_utf8removeaccents;
     $string = strtr($string, $qa_utf8removeaccents);
     $string = qa_keep_turkish_characters($string);

     return $string;
    }

Also turn off 'Remove accents from question urls" in admin control page.

by
last two answers are not working
...