Class: FastGettext::MoFile
- Inherits:
-
Object
- Object
- FastGettext::MoFile
- Defined in:
- lib/fast_gettext/mo_file.rb
Overview
Responsibility:
- abstract mo files for Mo Repository
Direct Known Subclasses
Constant Summary collapse
- PLURAL_SEPARATOR =
"\000"
- CONTEXT_SEPARATOR =
"\004"
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #data ⇒ Object
-
#initialize(file, options = {}) ⇒ MoFile
constructor
file => path or FastGettext::GetText::MOFile.
-
#plural(*msgids) ⇒ Object
returns the plural forms or all singular translations that where found Car, Cars => [Auto,Autos] or [].
- #pluralisation_rule ⇒ Object
Constructor Details
#initialize(file, options = {}) ⇒ MoFile
file => path or FastGettext::GetText::MOFile
12 13 14 15 16 |
# File 'lib/fast_gettext/mo_file.rb', line 12 def initialize(file, = {}) @filename = file @data = nil load_data if [:eager_load] 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 |
#data ⇒ Object
41 42 43 44 |
# File 'lib/fast_gettext/mo_file.rb', line 41 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 []
24 25 26 |
# File 'lib/fast_gettext/mo_file.rb', line 24 def plural(*msgids) split_plurals(self[msgids * PLURAL_SEPARATOR].to_s) end |
#pluralisation_rule ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# 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| if /^Plural-Forms:\s*nplurals\s*\=\s*(\d*);\s*plural\s*\=\s*([^;]*)\n?/ =~ line return ->(n) do # rubocop:disable Lint/UnusedBlockArgument eval($2) # rubocop:disable Security/Eval end end end nil end |