class I18n::Backend::Transliterator::HashTransliterator - i18n-0.6.11 Documentation

# class I18n::Backend::Transliterator::HashTransliterator

A transliterator which accepts a Hash of characters as its translation rule.

### Constants

DEFAULT_APPROXIMATIONS

### Public Class Methods

new(rule = nil) click to toggle source

    # File lib/i18n/backend/transliterator.rb, line 71
    def initialize(rule = nil)
      @rule = rule
      add DEFAULT_APPROXIMATIONS.dup
      add rule if rule
    end

### Public Instance Methods

transliterate(string, replacement = nil) click to toggle source

    # File lib/i18n/backend/transliterator.rb, line 77
    def transliterate(string, replacement = nil)
      string.gsub(/[^\x00-\x7f]/u) do |char|
        approximations[char] || replacement || DEFAULT_REPLACEMENT_CHAR
      end
    end

### Private Instance Methods

add(hash) click to toggle source

Add transliteration rules to the approximations hash.

    # File lib/i18n/backend/transliterator.rb, line 90
    def add(hash)
      hash.each do |key, value|
        approximations[key.to_s] = value.to_s
      end
    end

approximations() click to toggle source

    # File lib/i18n/backend/transliterator.rb, line 85
    def approximations
      @approximations ||= {}
    end