Class: FastGettext::MoFile

### Home Classes Methods

### In Files

- lib/fast_gettext/mo_file.rb

### Parent

Object

### Methods

- ::empty
- ::new
- #[]
- #plural
- #pluralisation_rule

### 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::MoFile

Responsibility:

    - abstract mo files for Mo Repository

### Constants

PLURAL_SEPERATOR

### Public Class Methods

empty() click to toggle source

    # File lib/fast_gettext/mo_file.rb, line 37
    def self.empty
      MoFile.new(File.join(File.dirname(__FILE__),'vendor','empty.mo'))
    end

new(file) click to toggle source

file => path or FastGettext::GetText::MOFile

    # File lib/fast_gettext/mo_file.rb, line 9
    def initialize(file)
      if file.is_a? FastGettext::GetText::MOFile
        @data = file
      else
        @data = FastGettext::GetText::MOFile.open(file, "UTF-8")
      end
      make_singular_and_plural_available
    end

### Public Instance Methods

[](key) click to toggle source

    # File lib/fast_gettext/mo_file.rb, line 18
    def [](key)
      @data[key]
    end

plural(*msgids) click to toggle source

returns the plural forms or all singular translations that where found

    Car, Cars => [Auto,Autos] or []

    # File lib/fast_gettext/mo_file.rb, line 24
    def plural(*msgids)
      split_plurals(self[msgids*PLURAL_SEPERATOR].to_s)
    end

pluralisation_rule() click to toggle source

    # File lib/fast_gettext/mo_file.rb, line 28
    def pluralisation_rule
      #gettext uses 0 as default rule, which would turn off all pluralisation, very clever...
      #additionally parsing fails when directly accessing po files, so this line was taken from gettext/mofile
      (@data['']||'').split("\n").each do |line|
        return lambda{|n|eval($2)} if /^Plural-Forms:\s*nplurals\s*\=\s*(\d*);\s*plural\s*\=\s*([^;]*)\n?/ =~ line
      end
      nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.