Class: FastGettext::TranslationRepository::Yaml

### Home Classes Methods

### In Files

- lib/fast_gettext/translation_repository/yaml.rb

### Parent

FastGettext::TranslationRepository::Base

### Methods

- ::new
- #add_yaml_key
- #available_locales
- #current_translations
- #find_and_store_files
- #load_yaml
- #plural
- #pluralisation_rule
- #reload
- #yaml_dot_notation
- #yaml_hash_to_dot_notation

### Class/Module Index

Quicksearch

- FastGettext
- FastGettext::GetText
- FastGettext::GetText::MOFile
- FastGettext::GetText::MOFile::HeaderRev1
- FastGettext::GetText::MOFile::InvalidFormat
- FastGettext::GetText::PoParser
- FastGettext::MoFile
- FastGettext::PoFile
- FastGettext::Storage
- FastGettext::Storage::NoTextDomainConfigured
- FastGettext::Translation
- FastGettext::TranslationMultidomain
- FastGettext::TranslationRepository
- FastGettext::TranslationRepository::Base
- FastGettext::TranslationRepository::Chain
- FastGettext::TranslationRepository::Db
- FastGettext::TranslationRepository::Logger
- FastGettext::TranslationRepository::Mo
- FastGettext::TranslationRepository::Po
- FastGettext::TranslationRepository::Yaml
- String
- TranslationKey
- TranslationText

No matching classes.

# FastGettext::TranslationRepository::Yaml

Responsibility:

    - find and store yaml files
    - provide access to translations in yaml files

### Constants

MAX_FIND_DEPTH

### Public Class Methods

new(name,options={}) click to toggle source

    # File lib/fast_gettext/translation_repository/yaml.rb, line 10
    def initialize(name,options={})
      super
      reload
    end

### Public Instance Methods

available_locales() click to toggle source

    # File lib/fast_gettext/translation_repository/yaml.rb, line 15
    def available_locales
      @files.keys
    end

plural(*keys) click to toggle source

    # File lib/fast_gettext/translation_repository/yaml.rb, line 19
    def plural(*keys)
      ['one', 'other', 'plural2', 'plural3'].map do |name|
        self[yaml_dot_notation(keys.first, name)]
      end
    end

pluralisation_rule() click to toggle source

    # File lib/fast_gettext/translation_repository/yaml.rb, line 25
    def pluralisation_rule
      self['pluralisation_rule'] ? lambda{|n| eval(self['pluralisation_rule']) } : nil
    end

reload() click to toggle source

    # File lib/fast_gettext/translation_repository/yaml.rb, line 29
    def reload
      find_and_store_files(@options)
      super
    end

### Protected Instance Methods

add_yaml_key(result, prefix, hash) click to toggle source

    # File lib/fast_gettext/translation_repository/yaml.rb, line 61
    def add_yaml_key(result, prefix, hash)
      hash.each_pair do |key, value|
        if value.kind_of?(Hash)
          add_yaml_key(result, yaml_dot_notation(prefix, key), value)
        else
          result[yaml_dot_notation(prefix, key)] = value
        end
      end
      result
    end

current_translations() click to toggle source

    # File lib/fast_gettext/translation_repository/yaml.rb, line 47
    def current_translations
      @files[FastGettext.locale] || super
    end

find_and_store_files(options) click to toggle source

    # File lib/fast_gettext/translation_repository/yaml.rb, line 38
    def find_and_store_files(options)
      @files = {}
      path = options[:path] || 'config/locales'
      Dir["#{path}/??.yml"].each do |yaml_file|
        locale = yaml_file.match(/([a-z]{2})\.yml$/)[1]
        @files[locale] = load_yaml(yaml_file, locale)
      end
    end

load_yaml(file, locale) click to toggle source

Given a yaml file return a hash of key -> translation

    # File lib/fast_gettext/translation_repository/yaml.rb, line 52
    def load_yaml(file, locale)
      yaml = YAML.load_file(file)
      yaml_hash_to_dot_notation(yaml[locale])
    end

yaml_dot_notation(a,b) click to toggle source

    # File lib/fast_gettext/translation_repository/yaml.rb, line 72
    def yaml_dot_notation(a,b)
      a ? "#{a}.#{b}" : b
    end

yaml_hash_to_dot_notation(yaml_hash) click to toggle source

    # File lib/fast_gettext/translation_repository/yaml.rb, line 57
    def yaml_hash_to_dot_notation(yaml_hash)
      add_yaml_key({}, nil, yaml_hash)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.