Module: Idiom::Processing

Included in:
Base
Defined in:
lib/idiom/base.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#post_process(value, lang) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/idiom/base.rb', line 98

def post_process(value, lang)
  value.gsub!(/^\"/, "")
  value.gsub!(/\"$/, "")
  # value.gsub!('"。', '。"')
  # value.gsub!(/^[''"「«]+/, "")
  # value.gsub!(/[''"」»]+$/, "")
  value.gsub!('"', "'")
  # value.gsub!("«", "")
  # value.gsub!("»", "")
  value.gsub!("&lt;", "<")
  value.gsub!("&gt;", ">")
  value.gsub!("{ ", "{")
  value.gsub!(" }", "}")
  value.gsub!("{{_", "{{")
  value.gsub!("_}}", "}}")
  value.gsub!(/\\$/, "")

  value.strip!
  value = "\"#{value}\"" if value.present?

  # Replace substitution vars
  while value =~ /\|([^\|]+)\|/ 
    value.sub! /\|([^\|]+)\|/, "%{#{@substitution_vars[$1.to_i]}}" 
  end

  # Replace pass-through content
  while value =~ /__(.*?)__/
    value.sub! /__(.*?)__/, @pass_through_vars[$1.to_i]
  end

  value
end

#pre_process(value, lang) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/idiom/base.rb', line 62

def pre_process(value, lang)
  # extract %{substitution_var} => @substitution_vars = ['substitution_var']
  #
  # This prevents the translator from seeing the substitution_var, in case it
  # tries to e.g. downcase it or whatever.
  @substitution_vars = []
  while value =~ /%\{([^\}]*)\}/
    value.sub! /%\{([^\}]*)\}/, "|#{@substitution_vars.count}|"
    @substitution_vars << $1
  end

  # extract '''pass through''' / ===pass through===  => @pass_through_vars = ['pass through']
  #
  # This allows string to be passed through without being translated
  # differs from @substitution_vars in that the underscore markup
  # will be stripped from the final result
  @pass_through_vars = []
  while value =~ /(?:(?:===)|(?:'''))(.*?)(?:(?:===)|(?:'''))/
    value.sub! /(?:(?:===)|(?:'''))(.*?)(?:(?:===)|(?:'''))/, "__#{@pass_through_vars.count}__"
    @pass_through_vars  << $1
  end

  vars = []
  index = 0
  while value =~ /(\{\d+\})/
    vars << $1
    value.sub!(/(\{\d+\})/, "[#{index}]")
    index += 1
  end
  
  value.gsub!("{{", "{{_")
  value.gsub!("}}", "_}}")

  value
end