Reputation: 35434
When asking a new Vietnamese question on my question2answer site, the newly created post will have the URL with the permalink created from title Vietnamese words - i.e. with Vietnamese accent.
That URL make it un-pretty when sharing the link as below snapshot.
I have turned on the option Remove accents from question URLs
in Admin - Viewing
configuration page but it doesn't help. How can I find a work-around for this?
The highlighted URL when copied will be
http://demo.question2answer.org/391/c%C3%A2u-h%E1%BB%8Fi-c%E1%BB%A7a-tui
Upvotes: 0
Views: 984
Reputation: 35434
As discussed here on question2anser.org/qa, here is my resolution for this.
Edit file <<q2aHOME>>\qa-include\util\string.php
Add a new function qa_convert_vi_to_en
code:
function qa_convert_vi_to_en($str)
{
$str = preg_replace('/(à|á|?|?|ã|â|?|?|?|?|?|a|?|?|?|?|?)/', 'a', $str);
$str = preg_replace('/(è|é|?|?|?|ê|?|?|?|?|?)/', 'e', $str);
$str = preg_replace('/(ì|í|?|?|i)/', 'i', $str);
$str = preg_replace('/(ò|ó|?|?|õ|ô|?|?|?|?|?|o|?|?|?|?|?)/', 'o', $str);
$str = preg_replace('/(ù|ú|?|?|u|u|?|?|?|?|?)/', 'u', $str);
$str = preg_replace('/(?|ý|?|?|?)/', 'y', $str);
$str = preg_replace('/(d)/', 'd', $str);
$str = preg_replace('/(À|Á|?|?|Ã|Â|?|?|?|?|?|A|?|?|?|?|?)/', 'A', $str);
$str = preg_replace('/(È|É|?|?|?|Ê|?|?|?|?|?)/', 'E', $str);
$str = preg_replace('/(Ì|Í|?|?|I)/', 'I', $str);
$str = preg_replace('/(Ò|Ó|?|?|Õ|Ô|?|?|?|?|?|O|?|?|?|?|?)/', 'O', $str);
$str = preg_replace('/(Ù|Ú|?|?|U|U|?|?|?|?|?)/', 'U', $str);
$str = preg_replace('/(?|Ý|?|?|?)/', 'Y', $str);
$str = preg_replace('/(Ð)/', 'D', $str);
return $str;
}
qa_string_remove_accents
to return with the newly created one.code:
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);
return qa_convert_vi_to_en($string);
}
Upvotes: 0