Skip to content

Commit

Permalink
Refactor Azb → Cyr
Browse files Browse the repository at this point in the history
  • Loading branch information
surfinzap committed Dec 28, 2019
1 parent 4feb8f6 commit 2fb54c7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ npm install translit-rue
## Documentation
Transliterate text from Cyrillic script to Latin alphabet:
```javascript
translitAzbLat(string)
translitCyrLat(string)
```

Transliterate text from Latin alphabet to Cyrillic script:
```javascript
translitLatAzb(string)
translitLatCyr(string)
```


Expand All @@ -38,4 +38,4 @@ Licensed under MIT license. (See [LICENCE.TXT](//github.com/surfinzap/translit/b


## Special thanks
* [@vit-svoboda](https://github.com/vit-svoboda) for help with gulp pipeline (2.0.0)
* [@vit-svoboda](https://github.com/vit-svoboda) for a help with gulp pipeline (2.0.0)
2 changes: 1 addition & 1 deletion dist/translit.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/translit_dist.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/browser_translit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { translitLatAzb,
translitAzbLat} from './translit';
import { translitLatCyr,
translitCyrLat} from './translit';

window.translitAzbLat = translitAzbLat;
window.translitLatAzb = translitLatAzb;
window.translitCyrLat = translitCyrLat;
window.translitLatCyr = translitLatCyr;
36 changes: 18 additions & 18 deletions src/translit.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,41 +251,41 @@ function streamlineApostrophes(string) {
return string.replace(/\'|’|ʼ|‘/g , '’');
}

function mapAzbLat(string, mappingOption) {
function mapCyrLat(string, mappingOption) {
for (var rule in mapping[mappingOption]){
var re = new RegExp(mapping[mappingOption][rule],"g");
string = string.replace(re, rule);
}
return string;
}

export function translitAzbLat(string) {
string = mapAzbLat(string, "exceptions");
string = mapAzbLat(string, "priority-set-1");
string = mapAzbLat(string, "priority-set-2");
string = mapAzbLat(string, "priority-set-3");
string = mapAzbLat(string, "carons");
string = mapAzbLat(string, "basic");
string = mapAzbLat(string, "chars");
export function translitCyrLat(string) {
string = mapCyrLat(string, "exceptions");
string = mapCyrLat(string, "priority-set-1");
string = mapCyrLat(string, "priority-set-2");
string = mapCyrLat(string, "priority-set-3");
string = mapCyrLat(string, "carons");
string = mapCyrLat(string, "basic");
string = mapCyrLat(string, "chars");
return string;
}

function mapLatAzb(string, mappingOption) {
function mapLatCyr(string, mappingOption) {
for (var rule in mapping[mappingOption]){
var re = new RegExp(rule,"g");
string = string.replace(re, mapping[mappingOption][rule]);
}
return string;
}

export function translitLatAzb(string) {
export function translitLatCyr(string) {
string = streamlineApostrophes(string);
string = mapLatAzb(string, 'exceptions');
string = mapLatAzb(string, 'priority-set-1');
string = mapLatAzb(string, 'priority-set-2');
string = mapLatAzb(string, 'priority-set-3');
string = mapLatAzb(string, 'carons');
string = mapLatAzb(string, 'basic');
string = mapLatAzb(string, 'chars');
string = mapLatCyr(string, 'exceptions');
string = mapLatCyr(string, 'priority-set-1');
string = mapLatCyr(string, 'priority-set-2');
string = mapLatCyr(string, 'priority-set-3');
string = mapLatCyr(string, 'carons');
string = mapLatCyr(string, 'basic');
string = mapLatCyr(string, 'chars');
return string;
}
4 changes: 2 additions & 2 deletions test/test_translit.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

<script>
$("#action_lat_azb").click(function() {
$('#translit-textarea').val(translitLatAzb($('#translit-textarea').val()));
$('#translit-textarea').val(translitLatCyr($('#translit-textarea').val()));
});
$("#action_azb_lat").click(function() {
$('#translit-textarea').val(translitAzbLat($('#translit-textarea').val()));
$('#translit-textarea').val(translitCyrLat($('#translit-textarea').val()));
});
</script>

Expand Down
6 changes: 3 additions & 3 deletions test/test_translit.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@

// Test translations from latin to azbuka
for (var key in test_dict){
assert(translitLatAzb(key), (test_dict[key]),"Assertion error: " + key + "\ntransliterates to: " + translitLatAzb(key) + "\nshould trans’ to: " + test_dict[key]);
assert(translitLatCyr(key), (test_dict[key]),"Assertion error: " + key + "\ntransliterates to: " + translitLatCyr(key) + "\nshould trans’ to: " + test_dict[key]);
}

// Test translations from azbuka to latin
for (var key in test_dict){
assert(translitAzbLat(test_dict[key]), (key),"Assertion error: " + test_dict[key] + "\ntransliterates to: " + translitAzbLat(test_dict[key]) + "\nshould trans’ to: " + key);
assert(translitCyrLat(test_dict[key]), (key),"Assertion error: " + test_dict[key] + "\ntransliterates to: " + translitCyrLat(test_dict[key]) + "\nshould trans’ to: " + key);
}

// Test if script takes different apostrophes
assert(streamlineApostrophes("ja‘nk‘o"),"ja’nk’o","Assertion error: apostrophe is not streamlined");
for (var key in test_dict_apostrophe){
assert(translitLatAzb(key), (test_dict_apostrophe[key]),"Assertion error: " + key + "\ntransliterates to: " + translitLatAzb(key) + ",\nshould trans’ to: " + test_dict[key] + "+\n— this is an apostrophe error.");
assert(translitLatCyr(key), (test_dict_apostrophe[key]),"Assertion error: " + key + "\ntransliterates to: " + translitLatCyr(key) + ",\nshould trans’ to: " + test_dict[key] + "+\n— this is an apostrophe error.");
}

})();

0 comments on commit 2fb54c7

Please sign in to comment.