Class: ZLocalize::IdentifierExpression
- Inherits:
-
Expression
- Object
- Expression
- ZLocalize::IdentifierExpression
- Defined in:
- lib/zlocalize/source_parser.rb
Overview
Basic identifier expression
Direct Known Subclasses
ArrayExpression, HashElementExpression, HashExpression, NumberExpression, RangeExpression, StringExpression, SymbolExpression
Instance Attribute Summary collapse
-
#name ⇒ Object
:nodoc: all.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
Attributes inherited from Expression
#char_no, #line_no, #sub_method, #text
Instance Method Summary collapse
-
#display(indent = 0) ⇒ Object
Used for debugging.
-
#initialize(line_no, char_no, name) ⇒ IdentifierExpression
constructor
A new instance of IdentifierExpression.
- #to_entry_string ⇒ Object
-
#to_translation_entry(filename) ⇒ Object
Convert ourselves to a Hash or an Array of Hashes which each represent a call to a translate method.
Methods inherited from Expression
#is_translate_call, #prefix, #set_text
Constructor Details
#initialize(line_no, char_no, name) ⇒ IdentifierExpression
Returns a new instance of IdentifierExpression.
58 59 60 61 62 63 |
# File 'lib/zlocalize/source_parser.rb', line 58 def initialize(line_no,char_no,name) @name = name @parameters = [] @sub_method = nil super(line_no,char_no) end |
Instance Attribute Details
#name ⇒ Object
:nodoc: all
55 56 57 |
# File 'lib/zlocalize/source_parser.rb', line 55 def name @name end |
#parameters ⇒ Object
Returns the value of attribute parameters.
56 57 58 |
# File 'lib/zlocalize/source_parser.rb', line 56 def parameters @parameters end |
Instance Method Details
#display(indent = 0) ⇒ Object
Used for debugging
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/zlocalize/source_parser.rb', line 66 def display(indent = 0) i = prefix(indent) i << "#{self.class.name} (#{line_no},#{char_no}): #{@name} (#{parameters.size} parameters)\n" @parameters.each { |p| i << p.display(indent+2) } unless @sub_method.nil? i << prefix(indent+1) + "sub-method:\n" i << @sub_method.display(indent+2) end i end |
#to_entry_string ⇒ Object
105 106 107 |
# File 'lib/zlocalize/source_parser.rb', line 105 def to_entry_string "(identifier '#{name}')".force_encoding("UTF-8") end |
#to_translation_entry(filename) ⇒ Object
Convert ourselves to a Hash or an Array of Hashes which each represent a call to a translate method. Will only output something if this expression is an actual call to _
or n_
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/zlocalize/source_parser.rb', line 80 def to_translation_entry(filename) if ['_','n_'].include?(@name) params = @parameters.dup elsif @name == 'ZLocalize' && @sub_method.is_a?(IdentifierExpression) && ['pluralize','translate'].include?(@sub_method.name) params = @sub_method.parameters.dup else return nil end if params.size > 0 p1 = params.shift # we only collect litteral strings and Arrays entry = [] if [StringExpression,ArrayExpression].include?(p1.class) entry << TranslationEntry.new( 'plural' => @name == 'n_', 'source' => p1.to_entry_string, 'references' => [ "#{filename}:#{p1.line_no}" ]) end # collect all other parameters to this call, in case they are themselves calls to nested _("") params.each { |p| entry << p.to_translation_entry(filename) } return entry.flatten.compact else nil end end |