Class: FastGettext::MoFile
- Inherits:
-
Object
- Object
- FastGettext::MoFile
- Defined in:
- lib/fast_gettext/mo_file.rb
Overview
Responsibility:
- abstract mo files for Mo Repository
Constant Summary collapse
- PLURAL_SEPERATOR =
"\000"
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(file) ⇒ MoFile
constructor
file => path or FastGettext::GetText::MOFile.
-
#plural(*msgids) ⇒ Object
returns the plural forms or all singular translations that where found.
- #pluralisation_rule ⇒ Object
Constructor Details
#initialize(file) ⇒ MoFile
file => path or FastGettext::GetText::MOFile
9 10 11 12 13 14 15 16 |
# 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 |
Class Method Details
Instance Method Details
#[](key) ⇒ Object
18 19 20 |
# File 'lib/fast_gettext/mo_file.rb', line 18 def [](key) @data[key] end |
#plural(*msgids) ⇒ Object
returns the plural forms or all singular translations that where found
23 24 25 26 27 |
# File 'lib/fast_gettext/mo_file.rb', line 23 def plural(*msgids) translations = plural_translations(msgids) return translations unless translations.empty? msgids.map{|msgid| self[msgid] || msgid} #try to translate each id end |
#pluralisation_rule ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/fast_gettext/mo_file.rb', line 29 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 |