Skip to content

Commit 21a5aff

Browse files
committed
Ukrainian: Provide convenience mappings
1 parent 5c0000d commit 21a5aff

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,28 @@ The second change to National 2010 is that we try to restore soft signs and apos
7272

7373
This feature is experimental and can be disabled by setting `apostrophes` to `false`.
7474

75+
#### Convenience mappings
76+
Another modification was to provide the following mappings:
77+
78+
* c → ц
79+
* q → щ
80+
* w → ш
81+
* x → х
82+
83+
Note that these mappings are phonetically inaccurate. However, using them still has a few advantages:
84+
85+
* Every letter of the Latin alphabet is covered
86+
* When the user types *ch*, we can map the first letter to *ц*, then replace it by *ч*
87+
* *w* has a similar shape to *ш*
88+
* *q* and *w* are located next to each other on the English keyboard, *щ* is therefore easy to find
89+
* *x* has the same shape as its Cyrillic counterpart
90+
7591
### Credits
7692
The rules and examples were adapted from the following libraries:
7793

7894
* [translit-english-ukrainian](https://github.com/MarkovSergii/translit-english-ukrainian)
7995
* [translit-ua](https://github.com/dchaplinsky/translit-ua)
96+
* [translit.net](http://translit.net/)
8097

8198
## Licence
8299
translit-scala is licensed under the terms of the Apache v2.0 licence.

shared/src/main/scala/translit/Ukrainian.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ object Ukrainian extends Language {
1212
'g' -> 'ґ',
1313
'h' -> 'г',
1414
'i' -> 'і',
15+
'j' -> 'й',
1516
'k' -> 'к',
1617
'l' -> 'л',
1718
'm' -> 'м',
@@ -24,8 +25,14 @@ object Ukrainian extends Language {
2425
'u' -> 'у',
2526
'v' -> 'в',
2627
'y' -> 'и',
27-
'j' -> 'й',
28-
'z' -> 'з'
28+
'z' -> 'з',
29+
30+
// Mappings for more convenient typing. Allows us to cover every letter of
31+
// the Latin alphabet
32+
'c' -> 'ц',
33+
'q' -> 'щ',
34+
'w' -> 'ш',
35+
'x' -> 'х'
2936
)
3037

3138
val biGrams = Map(
@@ -117,10 +124,6 @@ object Ukrainian extends Language {
117124
val result = if (text(ofs - 2).isUpper) cyrillic.toUpper else cyrillic
118125

119126
(0, result)
120-
} else if ('c' == text(ofs - 1).toLower) {
121-
// Replace Latin `c` to avoid confusion as its Cyrillic counterpart has a
122-
// different byte code
123-
(0, 'ø')
124127
} else {
125128
(0, text(ofs - 1))
126129
}

shared/src/test/scala/translit/UkrainianSpec.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,14 @@ class UkrainianSpec extends FunSuite {
246246
}
247247

248248
test("s vs c") {
249-
assert(Ukrainian.latinToCyrillic("vlacnym") == "влаøним")
249+
assert(Ukrainian.latinToCyrillic("vlacnym") == "влацним")
250250
assert(Ukrainian.latinToCyrillic("vlasnym") == "власним")
251251
}
252252

253253
test("Offsets") {
254254
assert(Ukrainian.latinToCyrillicOfs("shch", 0) == (0, 'с'))
255255
assert(Ukrainian.latinToCyrillicOfs("shch", 1) == (-1, 'ш'))
256-
assert(Ukrainian.latinToCyrillicOfs("shch", 2) == (0, 'ø'))
256+
assert(Ukrainian.latinToCyrillicOfs("shch", 2) == (0, 'ц'))
257257
assert(Ukrainian.latinToCyrillicOfs("shch", 3) == (-2, 'щ'))
258258
assert(Ukrainian.latinToCyrillicOfs("yeshch", 5) == (-2, 'щ'))
259259

@@ -273,4 +273,9 @@ class UkrainianSpec extends FunSuite {
273273

274274
assert(Ukrainian.latinToCyrillicOfs("zgh", 2) == (-1, 'г'))
275275
}
276+
277+
test("Convenience mappings") {
278+
assert(Ukrainian.latinToCyrillic("Puzata Xata") == "Пузата Хата")
279+
assert(Ukrainian.latinToCyrillic("cqwx") == "цщшх")
280+
}
276281
}

0 commit comments

Comments
 (0)