Class: GetPomo::Translation
- Inherits:
-
Object
- Object
- GetPomo::Translation
- Defined in:
- lib/get_pomo/translation.rb
Constant Summary collapse
- FUZZY_REGEX =
/^#,\s*fuzzy/- OBSOLETE_REGEX =
/^#~\s*msgstr/
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#msgctxt ⇒ Object
Returns the value of attribute msgctxt.
-
#msgid ⇒ Object
Returns the value of attribute msgid.
-
#msgstr ⇒ Object
Returns the value of attribute msgstr.
Instance Method Summary collapse
- #add_text(text, options) ⇒ Object
- #complete? ⇒ Boolean
- #fuzzy=(value) ⇒ Object
- #fuzzy? ⇒ Boolean
- #header? ⇒ Boolean
- #obsolete? ⇒ Boolean
- #plural? ⇒ Boolean
- #singular? ⇒ Boolean
- #to_hash ⇒ Object
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
5 6 7 |
# File 'lib/get_pomo/translation.rb', line 5 def comment @comment end |
#msgctxt ⇒ Object
Returns the value of attribute msgctxt.
5 6 7 |
# File 'lib/get_pomo/translation.rb', line 5 def msgctxt @msgctxt end |
#msgid ⇒ Object
Returns the value of attribute msgid.
5 6 7 |
# File 'lib/get_pomo/translation.rb', line 5 def msgid @msgid end |
#msgstr ⇒ Object
Returns the value of attribute msgstr.
5 6 7 |
# File 'lib/get_pomo/translation.rb', line 5 def msgstr @msgstr end |
Instance Method Details
#add_text(text, options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/get_pomo/translation.rb', line 7 def add_text(text,) to = [:to] if to.to_sym == :msgid_plural self.msgid = [msgid] unless msgid.is_a? Array msgid[1] = msgid[1].to_s + text elsif to.to_s =~ /^msgstr\[(\d)\]$/ self.msgstr ||= [] msgstr[$1.to_i] = msgstr[$1.to_i].to_s + text elsif to.to_sym == :comment && text =~ OBSOLETE_REGEX # initialize msgid and msgstr on obsolete translations self.msgid ||= "" self.msgstr ||= "" send("#{to}=",send(to).to_s+text) else #simple form send("#{to}=",send(to).to_s+text) end end |
#complete? ⇒ Boolean
35 36 37 |
# File 'lib/get_pomo/translation.rb', line 35 def complete? not msgid.nil? and not msgstr.nil? end |
#fuzzy=(value) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/get_pomo/translation.rb', line 47 def fuzzy=(value) if value and not fuzzy? add_text "\n#, fuzzy", :to=>:comment else self.comment = comment.to_s.split(/$/).reject{|line|line=~FUZZY_REGEX}.join("\n") end end |
#fuzzy? ⇒ Boolean
39 40 41 |
# File 'lib/get_pomo/translation.rb', line 39 def fuzzy? !!(comment =~ FUZZY_REGEX) end |
#header? ⇒ Boolean
63 64 65 |
# File 'lib/get_pomo/translation.rb', line 63 def header? msgid == "" end |
#obsolete? ⇒ Boolean
43 44 45 |
# File 'lib/get_pomo/translation.rb', line 43 def obsolete? !!(comment =~ OBSOLETE_REGEX) end |
#plural? ⇒ Boolean
55 56 57 |
# File 'lib/get_pomo/translation.rb', line 55 def plural? msgid.is_a? Array or msgstr.is_a? Array end |
#singular? ⇒ Boolean
59 60 61 |
# File 'lib/get_pomo/translation.rb', line 59 def singular? !plural? end |
#to_hash ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/get_pomo/translation.rb', line 26 def to_hash { :msgctxt => msgctxt, :msgid => msgid, :msgstr => msgstr, :comment => comment }.reject { |_,value| value.nil? } end |