Module: PoAndXliffConsolidator::Manipulate

Includes:
Logging
Included in:
Combine, Extract
Defined in:
lib/po_and_xliff_consolidator/manipulate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, logger, #logger, logger=

Instance Attribute Details

#reset_identical_msgid_and_msgstrObject

Returns the value of attribute reset_identical_msgid_and_msgstr.



10
11
12
# File 'lib/po_and_xliff_consolidator/manipulate.rb', line 10

def reset_identical_msgid_and_msgstr
  @reset_identical_msgid_and_msgstr
end

#skip_regexesObject

Returns the value of attribute skip_regexes.



9
10
11
# File 'lib/po_and_xliff_consolidator/manipulate.rb', line 9

def skip_regexes
  @skip_regexes
end

#skip_stringsObject

Returns the value of attribute skip_strings.



8
9
10
# File 'lib/po_and_xliff_consolidator/manipulate.rb', line 8

def skip_strings
  @skip_strings
end

Instance Method Details

#add_translation_unit(msgid, msgstr) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/po_and_xliff_consolidator/manipulate.rb', line 59

def add_translation_unit(msgid, msgstr)

  return if should_skip?(msgid)

  if msgid == msgstr
    logger.warn "#{@language_code}: identical msgid and msgstr for: #{msgid}"
    if @reset_identical_msgid_and_msgstr
      msgstr = ''
    end
  end

  tu = TranslateUnit.new(msgid, msgstr)

  if @translation_units.include? tu
    logger.debug "Already found #{tu}"
    @duplicate_count += 1
    return
  end
  @translation_units << tu
  if msgstr == ''
    @untranslated_count += 1
    counter = WordsCounted.count(msgid)
    word_count = counter.token_count
    @untranslated_word_count += word_count
  end

end

#initializeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/po_and_xliff_consolidator/manipulate.rb', line 12

def initialize
  @skip_strings = []
  @skip_regexes = []

  @reset_identical_msgid_and_msgstr = false

  @msgid_regex = /^msgid\s"(.*)"$/
  @msgid_plural_regex = /^msgid_plural\s"(.*)"$/
  @msgstr_regex = /^msgstr\s"(.*)"$/
  @continuation_regex = /^"(.*)"$/

  super
end

#reset_storesObject



36
37
38
39
40
41
42
43
# File 'lib/po_and_xliff_consolidator/manipulate.rb', line 36

def reset_stores
  @translation_units = []
  @headers = []
  @unsolved_blocks = []
  @duplicate_count = 0
  @untranslated_count = 0
  @untranslated_word_count = 0
end

#set_language_codes(language_code) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/po_and_xliff_consolidator/manipulate.rb', line 26

def set_language_codes(language_code)
  if language_code.is_a? Array
    @language_code = language_code[0]
    @xliff_language_code = language_code[1]
  else
    @language_code = language_code
    @xliff_language_code = language_code
  end
end

#should_skip?(msgid) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/po_and_xliff_consolidator/manipulate.rb', line 45

def should_skip?(msgid)
  if skip_strings.include? msgid
    return true
  end

  skip_regexes.each do |skip_regex|
    if skip_regex =~ msgid
      return true
    end
  end

  false
end