Class: GetPomo::Translation

Inherits:
Object
  • Object
show all
Defined in:
lib/get_pomo/translation.rb

Constant Summary collapse

FUZZY_REGEX =
/^#,\s*fuzzy/
OBSOLETE_REGEX =
/^#~\s*msgstr/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



5
6
7
# File 'lib/get_pomo/translation.rb', line 5

def comment
  @comment
end

#msgctxtObject

Returns the value of attribute msgctxt.



5
6
7
# File 'lib/get_pomo/translation.rb', line 5

def msgctxt
  @msgctxt
end

#msgidObject

Returns the value of attribute msgid.



5
6
7
# File 'lib/get_pomo/translation.rb', line 5

def msgid
  @msgid
end

#msgstrObject

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,options)
  to = options[: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

Returns:

  • (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

Returns:

  • (Boolean)


39
40
41
# File 'lib/get_pomo/translation.rb', line 39

def fuzzy?
  !!(comment =~ FUZZY_REGEX)
end

#header?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/get_pomo/translation.rb', line 63

def header?
  msgid == ""
end

#obsolete?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/get_pomo/translation.rb', line 43

def obsolete?
  !!(comment =~ OBSOLETE_REGEX)
end

#plural?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


59
60
61
# File 'lib/get_pomo/translation.rb', line 59

def singular?
  !plural?
end

#to_hashObject



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