Transliteration of non latin texts

If you would like to convert UTF-8 cyrillic to readable latin, you can dynamically transliterate the content of the <div class="dokuwiki">.

To do so, change the following things:

/* original javascript by Eugene Spearance (http://www.spearance.ru) */
function translit()
{
document.getElementById('dokuwiki').innerHTML=convert(document.getElementById('dokuwiki').innerHTML)
}
var rusChars = new Array('Щ','Ё','Ж','Ч','Ш','Э','Ю','Я','А','Б','В','Г','Д','Е','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ъ','Ы','Ь','щ','ё','ж','ч','ш','э','ю','я','а','б','в','г','д','е','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ъ','ы','Ь');
var transChars = new 
Array('SHH','JO','ZH','CH','SH','JE','JU','JA','A','B','V','G','D','E','Z','I','J','K','L','M','N','O','P','R','S','T','U','F','X','C','#','Y','‘','shh','jo','zh','ch','sh','je','ju','ja','a','b','v','g','d','e','z','i','j','k','l','m','n','o','p','r','s','t','u','f','x','c','#','y','‘');

function convert(from){
	var to = new String();
	var len = from.length;
	var character, isRus;
	for(i=0; i < len; i++){
		character = from.charAt(i,1);
		isRus = false;
		for(j=0; j < rusChars.length; j++){
			if(character == rusChars[j]){
			isRus = true;
			break;
			}
		}
		to += (isRus) ? transChars[j] : character;
	}
	return(to);
}


—-

  ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
       DOKU_BASE.'lib/scripts/translit.js"></script>',$it);

Please note that this is client-side javascript, and that your browser might take some time/resources to process it. Of course server-side transliteration would be better…

If you would like to use this for transliteration of non cyrillic (other UTF-8 characters, it is easy to get the strings in UTF-8 by just putting them in a page, and then take a look at the raw file in the /data/pages/ directory.

Alternatively you may use an online UTF-8 encoder like this online translit converter.

Discussion

People that use this tip, could you please provide feedback? Thanks, Riny