M
M
Maturmalayev2017-12-08 12:47:33
Machine translation from one language to another
Maturmalayev, 2017-12-08 12:47:33

How to write a translator from Cyrillic to Latin?

How to write a website with two windows to move from one state to another?
So that when you enter in the input field in Cyrillic, in another window it gives out text in Latin?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Seva, 2017-12-08
@Zewkin

Yes, whatever. I once did this for the first Angular

.directive('translit', function() {
    var rules = {                           // according to http://zakon3.rada.gov.ua/laws/show/55-2010-%D0%BF
      'А' : 'A',
      'Б' : 'B',
      'В' : 'V',
      'Г' : 'H',
      'Ґ' : 'G',
      'Д' : 'D',
      'Е' : 'E',
      'Є' : ['YE', 'IE'],
      'Ж' : 'ZH',
      'З' : 'Z',
      'И' : 'Y',
      'І' : 'I',
      'Ї' : ['YI', 'I'],
      'Й' : ['Y', 'I'],
      'К' : 'K',
      'Л' : 'L',
      'М' : 'M',
      'Н' : 'N',
      'О' : 'O',
      'П' : 'P',
      'Р' : 'R',
      'С' : 'S',
      'Т' : 'T',
      'У' : 'U',
      'Ф' : 'F',
      'Х' : 'KH',
      'Ц' : 'TS',
      'Ч' : 'CH',
      'Ш' : 'SH',
      'Щ' : 'SHCH',
      'Ю' : ['YU', 'IU'],
      'Я' : ['YA', 'IA'],
    }
    return {
      link: function(scope, element, attrs) {
        element.bind('blur', function(e) {
          var translited = '';
          element.val(element.val().toUpperCase());
          var letters = element.val().split('');
          letters.map(function(letter) {
            var latinLetter;
            rules[letter] ?
              Array.isArray(rules[letter]) ?
                letters.indexOf(letter) == 0 ?      // checking if the letter is the first in the word
                  latinLetter = rules[letter][0] :
                  latinLetter = rules[letter][1]
              : latinLetter = rules[letter]
            : latinLetter = '';                     // if there is no rule for the character, then replace with nothing
            translited += latinLetter;
          })
          scope.$apply(function() {
            scope.customer.personalData[attrs.translit] = translited;
          })
        })
      }
    }
  })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question