Skip to content

Commit

Permalink
Правило для замены латинских букв на русские
Browse files Browse the repository at this point in the history
Опечатки, возникающие при переключении клавиатурной раскладки.
  • Loading branch information
hcodes committed Sep 25, 2016
1 parent 22c1429 commit 3759053
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
"ru": "Символы"
}
},
{
"name": "typo",
"title": {
"en": "Typos",
"ru": "Опечатки"
}
},
{
"name": "other",
"title": {
Expand Down
3 changes: 2 additions & 1 deletion src/indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Typograf.groupIndexes = {
date: 810,
other: 910,
optalign: 1010,
html: 1110
typo: 1110,
html: 1210
};
42 changes: 42 additions & 0 deletions src/rules/ru/typo/switchingKeyboardLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(function() {

var replacements = {
A: 'А', // Latin: Russian
a: 'а',
B: 'В',
E: 'Е',
e: 'е',
K: 'К',
M: 'М',
H: 'Н',
O: 'О',
o: 'о',
P: 'р',
p: 'Р',
C: 'С',
c: 'с',
T: 'Т',
y: 'у',
X: 'Х',
x: 'х'
};

var keys = Object.keys(replacements).join('');

Typograf.rule({
name: 'ru/typo/switchingKeyboardLayout',
handler: function(text) {
var re = new RegExp('([' + keys + ']{1,3})(?=[А-ЯЁа-яё]+?)', 'g');

return text.replace(re, function(str, $1) {
var result = '';
for (var i = 0; i < $1.length; i++) {
result += replacements[$1[i]];
}

return result;
});
}
});

})();
4 changes: 4 additions & 0 deletions src/rules/ru/typo/switchingKeyboardLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"en": "Replacement of Latin letters in Russian. Typos occur when you switch keyboard layouts",
"ru": "Замена латинских букв на русские. Опечатки, возникающие при переключении клавиатурной раскладки"
}
18 changes: 18 additions & 0 deletions src/rules/ru/typo/switchingKeyboardLayout.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tests.push(['ru/typo/switchingKeyboardLayout', [
[
'Cпокойствие', // C - latin letter
'Спокойствие' // C - russian letter
],
[
'Ccылка', // Cc - latin letter
'Ссылка' // Сс - russian letter
],
[
'Ccылка, ccылка и ещё ccылка',
'Ссылка, ссылка и ещё ссылка'
],
[
'Первая ccылка\nВторая ccылка\n...\nCедьмая ccылка',
'Первая ссылка\nВторая ссылка\n...\nСедьмая ссылка'
]
]]);

0 comments on commit 3759053

Please sign in to comment.