Class: GetPomo::MoFile
- Inherits:
-
Object
- Object
- GetPomo::MoFile
- Defined in:
- lib/get_pomo/mo_file.rb
Constant Summary collapse
- PLURAL_SEPERATOR =
"\000"
Instance Attribute Summary collapse
-
#translations ⇒ Object
readonly
Returns the value of attribute translations.
Class Method Summary collapse
Instance Method Summary collapse
- #add_translations_from_text(text) ⇒ Object
-
#initialize(options = {}) ⇒ MoFile
constructor
A new instance of MoFile.
- #to_text ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ MoFile
Returns a new instance of MoFile.
19 20 21 |
# File 'lib/get_pomo/mo_file.rb', line 19 def initialize( = {}) @translations = [:translations] || [] end |
Instance Attribute Details
#translations ⇒ Object (readonly)
Returns the value of attribute translations.
17 18 19 |
# File 'lib/get_pomo/mo_file.rb', line 17 def translations @translations end |
Class Method Details
.parse(text) ⇒ Object
8 9 10 |
# File 'lib/get_pomo/mo_file.rb', line 8 def self.parse(text) MoFile.new.add_translations_from_text(text) end |
Instance Method Details
#add_translations_from_text(text) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/get_pomo/mo_file.rb', line 23 def add_translations_from_text(text) text = StringIO.new(text) @translations += GetPomo::GetText::MOFile.open(text, "UTF-8").map do |msgid,msgstr| translation = Translation.new if plural? msgid or plural? msgstr translation.msgid = split_plural(msgid) translation.msgstr = split_plural(msgstr) else translation.msgid = msgid translation.msgstr = msgstr end translation end end |
#to_text ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/get_pomo/mo_file.rb', line 38 def to_text m = GetPomo::GetText::MOFile.new GetPomo.unique_translations(translations).each {|t| m[plural_to_string(t.msgid)] = plural_to_string(t.msgstr)} io = StringIO.new m.save_to_stream io io.rewind io.read end |