Module: RailsI18n::Transliteration::Ukrainian

Defined in:
lib/rails_i18n/transliteration.rb

Class Method Summary collapse

Class Method Details

.ruleObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rails_i18n/transliteration.rb', line 7

def rule
  lambda do |string|
    next '' unless string

    string.gsub(/./) do |char|
      # Regexp.last_match is local to the thread and method scope
      # of the method that did the pattern match.
      @pre_match, @post_match = $`, $'

      case char
      when 'Ж'
        lookahead_upcase 'ZH'
      when 'Х'
        lookahead_upcase 'KH'
      when 'Ц'
        lookahead_upcase 'TS'
      when 'Ч'
        lookahead_upcase 'CH'
      when 'Ш'
        lookahead_upcase 'SH'
      when 'Щ'
        lookahead_upcase 'SHCH'
      when 'г'
        behind =~ /[зЗ]/ ? 'gh' : 'h'
      when 'Г'
        behind =~ /[зЗ]/ ? lookahead_upcase('GH') : 'H'
      when 'є'
        letter?(behind) ? 'ie' : 'ye'
      when 'Є'
        letter?(behind) ? lookahead_upcase('IE') : lookahead_upcase('YE')
      when 'ї'
        letter?(behind) ? 'i' : 'yi'
      when 'Ї'
        letter?(behind) ? 'I' : lookahead_upcase('YI')
      when 'й'
        letter?(behind) ? 'i' : 'y'
      when 'Й'
        letter?(behind) ? 'I' : 'Y'
      when 'ю'
        letter?(behind) ? 'iu' : 'yu'
      when 'Ю'
        letter?(behind) ? lookahead_upcase('IU') : lookahead_upcase('YU')
      when 'я'
        letter?(behind) ? 'ia' : 'ya'
      when 'Я'
        letter?(behind) ? lookahead_upcase('IA') : lookahead_upcase('YA')
      when "'"
        # remove apostrophe inside a word
        letter?(behind) && letter?(ahead) ? '' : "'"
      else
        straight_lookup[char] || char
      end
    end
  end
end