Class: FastGettext::MoFile

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_gettext/mo_file.rb

Overview

Responsibility:

- abstract mo files for Mo Repository

Direct Known Subclasses

PoFile

Constant Summary collapse

PLURAL_SEPERATOR =
"\000"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ MoFile

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



9
10
11
12
# File 'lib/fast_gettext/mo_file.rb', line 9

def initialize(file, options={})
  @filename = file
  load_data if options[:eager_load]
end

Class Method Details

.emptyObject



38
39
40
# File 'lib/fast_gettext/mo_file.rb', line 38

def self.empty
  MoFile.new(File.join(File.dirname(__FILE__),'vendor','empty.mo'))
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/fast_gettext/mo_file.rb', line 14

def [](key)
  data[key]
end

#dataObject



33
34
35
36
# File 'lib/fast_gettext/mo_file.rb', line 33

def data
  load_data if @data.nil?
  @data
end

#plural(*msgids) ⇒ Object

returns the plural forms or all singular translations that where found Car, Cars => [Auto,Autos] or []



20
21
22
# File 'lib/fast_gettext/mo_file.rb', line 20

def plural(*msgids)
  split_plurals(self[msgids*PLURAL_SEPERATOR].to_s)
end

#pluralisation_ruleObject



24
25
26
27
28
29
30
31
# File 'lib/fast_gettext/mo_file.rb', line 24

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