Транслит для LS 1.0.3

Обыкновенный транслит. Не плагин. Для людей у кого нету русской клавиатуры, ну или не умеют печатать на русском(как я дурак). Короче пишем русские слова английским шрифтом, и при нажатии на «Транслит» он переводица в русский.

Делал давно, так что если не будет работать я подправлю.

Создаём /templates/skin/Ваш_скин/js/translit.js
var CapsState = false;

function copy() {
  let textarea = document.getElementById("textarea");
  textarea.select();
  document.execCommand("copy");
}

function initArray() 
{
	this.length = initArray.arguments.length
	for (var i = 0; i < this.length; i++)   
		this[i+1] = initArray.arguments[i]
}

eng_letters = new initArray(1040,1041,1062,1044,1045,1060,1043,1061,1048,1049,1050,1051,1052,1053,1054,1055,1071,1056,1057,1058,1059,1042,1065,1061,1067,1047,91,92,93,94,95,96,1072,1073,1094,1076,1077,1092,1075,1093,1080,1081,1082,1083,1084,1085,1086,1087,1103,1088,1089,1090,1091,1074,1097,120,1099,1079);
second_order = new initArray(72,79,69,85,65,72,77,79,85,65,72,104,111,101,117,97,104,109,111,117,97,104);
first_order  = new initArray(1062,1049,1049,1049,1049,1057,1065,1067,1067,1067,1047,1094,1081,1081,1081,1081,1089,1097,1099,1099,1099,1079);
two_result = new initArray(1063,1025,1069,1070,1071,1064,1068,1025,1070,1071,1046,1095,1105,1101,1102,1103,1096,1100,1105,1102,1103,1078);

var nexto = 1;
var language = (navigator.appName=='Netscape');

function getlanguagename()
{
	if (language==1) return "Eng";
	if (language==0) return "Rus";
}

function changelanguage()
{
if (language==1) {language=0; document.searchform.rus_eng.value="Rus"; document.searchform.comment_text.focus();return 0}
if (language==0) {language=1; document.searchform.rus_eng.value="Eng"; document.searchform.comment_text.focus();return 0}
}

function translate_letter()
{
	if(navigator.appName=='Netscape')
	{
		if (language==0) 
		{
			changelanguage();
			alert("The language is swithched to English. Please complete the text and press 'TRANSLITERATE ALL' button");
		}
		return true;
	}
        if (language==1) {return true;}
	var txt = document.searchform.comment_text.value;
	l1 = txt.substr(txt.length - 1,1);
	var code = l1.charCodeAt(0); 
	l2 = txt.substr(txt.length-2,1);
	var code2 = l2.charCodeAt(0);
	if ((code==39)||(code==35))
	//' and '' and # and ## treatment
	{
		if (code==39) 
		{
			var newcode =1100;
			var doublecode =1068;
		}
		if (code==35) 
		{
			var newcode =1098;
			var doublecode =1066;
		}

		var res = String.fromCharCode(newcode);		
		txt = txt.substr(0, txt.length-1);
		if (code2==newcode) 
		{ 
			res = String.fromCharCode(doublecode);
			txt = txt.substr(0, txt.length-1);
		}

		document.searchform.comment_text.value = txt + res;
                document.searchform.comment_text.focus();
	}

	if ((code<123) && (code>64)) 
	{
		var res = String.fromCharCode(eng_letters[code-64]);
		var rus_code = eng_letters[code-64];
		txt = txt.substr(0, txt.length-1);
		if (nexto==0)
		{ 
			nexto = 1;
			for (i = 1; i<25; i++)
			{
				if (rus_code == first_order[i]) nexto = 0; 
				if ((code==second_order[i])&&(code2==first_order[i])) 
				{ 
					res = String.fromCharCode(two_result[i]);
					txt = txt.substr(0, txt.length-1);
					break;
				}
			}
		}
		else nexto = 0;

                document.searchform.comment_text.focus();
		document.searchform.comment_text.value = txt + res;

	}
}


function translatesymbol(pretxt,txt)
{
	var res = pretxt+txt;
	var code = txt.charCodeAt(0); 
	var code2 = pretxt.charCodeAt(0);

	if ((code==39)||(code==35))
	//' and '' and # and ## treatment
	{
		if (code==39) 
		{
			var newcode =1100;
			var doublecode =1068;
		}
		if (code==35) 
		{
			var newcode =1098;
			var doublecode =1066;
		}

		res = pretxt+String.fromCharCode(newcode);		

		if (code2==newcode) 
		{ 
			res = String.fromCharCode(doublecode);
		}
	}

	if ((code<123) && (code>64)) 
	{
		res = pretxt+String.fromCharCode(eng_letters[code-64]);
		for (i = 1; i<25; i++)
		{ 
			if ((code==second_order[i])&&(code2==first_order[i])) 
			{ 
				res = String.fromCharCode(two_result[i]);
				break;
			}
		}
	}
	return res;
}

function translateAll()
{
	var txt = document.searchform.comment_text.value;
	var txtnew = translatesymbol("",txt.substr(0,1));
	var symb = "";
	for (kk=1;kk<txt.length;kk++)
	{
		symb = translatesymbol(txtnew.substr(txtnew.length-1,1),txt.substr(kk,1));
		txtnew = txtnew.substr(0,txtnew.length-1) + symb;
	}
	document.searchform.comment_text.value = txtnew;
	document.searchform.comment_text.focus();
}

     function onClickKBButtonEx(btn)
     {
	if (btn == 'Caps')
		CapsState = !(CapsState)
        else
	{ 
		var txt = document.searchform.comment_text.value;
		if (btn == 'BkSp')
		{
			txt = txt.substr(0, txt.length - 1);
		}
		else
		{
			txt = txt + btn;
		}
		document.searchform.comment_text.value = txt;
	}
		document.searchform.comment_text.focus();
     }
     function onClickKBButton(btn)
     {
	var code = btn.charCodeAt(0);
	if (CapsState == false)
	{
		if (code == 168) 
                   code = 184;
		else if (code == 1025)
		   code = 1105;
		else
                   code = code + 32;
	}
	btn = String.fromCharCode(code);
	onClickKBButtonEx(btn);
	 }


Далее дебавляем теги в Ну и кнопку транслит. Я добавил транслит себе только в Коментарии. Но можете добавить его куда угодно делея это по схеме с этим. Если есть очень умные люди то можно добавить кнопку транслит в сам ББкод на верх где болд/ италик/. Но я не знаю как.

В конфиге скина добавить:

$config['head']['default']['js'][] = '___path.static.skin___/js/translit.js';


После:

$config['head']['default']['js'][] = '___path.static.skin___/js/template.js';


В форме ответа заменить код на этот.

<form method="post" id="form_comment" onsubmit="return false;" name="searchform" enctype="multipart/form-data">
				<textarea name="comment_text" id="form_comment_text" onkeyup="translate_letter()" class="mce-editor markitup-editor input-width-full"></textarea>
				<input name="tr_all" onclick="translateAll()" type="button" class="button" value="Транслит">

Автоматическое преобразование столбца db mySQL в Translit

На данный момент есть таблица с населёнными пунктами вида
CREATE TABLE IF NOT EXISTS `base_cities` (
  `id_city` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `id_region` int(10) unsigned NOT NULL,
  `id_country` mediumint(8) unsigned NOT NULL,
  `sort` int(11) NOT NULL,
  `city_name_ru` varchar(255) NOT NULL,
  `city_name_en` varchar(255) NOT NULL,
  PRIMARY KEY (`id_city`),
  KEY `id_region` (`id_region`),
  KEY `id_country` (`id_country`),
  KEY `sort` (`sort`),
  KEY `city_name_ru` (`city_name_ru`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=18127 ;

--
-- Dumping data for table `base_cities`
--

INSERT INTO `base_cities` (`id_city`, `id_region`, `id_country`, `sort`, `city_name_ru`, `city_name_en`) VALUES
(1, 1, 1, 1, 'Москва', 'Moscow'),
(2, 1, 1, 0, 'Абрамцево', 'Abramtsevo'),
(3, 1, 1, 0, 'Алабино', 'Alabino'),
(4, 1, 1, 0, 'Апрелевка', 'Aprelevka'),
(5, 1, 1, 0, 'Архангельское', 'Arhangelskoe'),
(6, 1, 1, 0, 'Ашитково', 'Ashitkovo'),
(7, 1, 1, 4, 'Байконур', 'Baikonur'),
(8, 1, 1, 0, 'Бакшеево', 'Baksheevo'),
(9, 1, 1, 0, 'Балашиха', 'Balashiha'),
(10, 1, 1, 0, 'Барыбино', 'Barybino'),
(11, 1, 1, 0, 'Белозёрский', 'Белозёрский'),
(12, 1, 1, 0, 'Белоомут', 'Beloomut'),
(13, 1, 1, 0, 'Белые Столбы', 'Belye Stolby'),
(14, 1, 1, 0, 'Бородино (Московская обл.)', 'Borodino (Moskovskaya obl.)'),
(15, 1, 1, 0, 'Бронницы', 'Bronnitsy'),
(16, 1, 1, 0, 'Быково (Московская обл.)', 'Bykovo (Moskovskaya obl.)'),
(17, 1, 1, 0, 'Валуево', 'Valuevo'),
(18, 1, 1, 0, 'Вербилки', 'Verbilki'),
(19, 1, 1, 0, 'Верея', 'Vereya'),
(20, 1, 1, 0, 'Видное', 'Vidnoe'),


Нужно добавить столбец translit и преобразовать строку city_name_ru в транслит с заменой пробелов знаком _ и убрать все другие знаки, чтобы получилось что-то вроде.

Было:
(16, 1, 1, 0, 'Быково (Московская обл.)', 'Bykovo (Moskovskaya obl.)'),

Стало:
(16, 1, 1, 0, 'Быково (Московская обл.)', 'Bykovo (Moskovskaya obl.)','bykovo_moskovskaya_obl'),


Может быть кто то уже сталкивался с таким и может подсказать как это реализовать..?
Желательно ещё сделать что бы если такой город уже есть, то к ниму делать префикс вроде _1, _2 и так далее.