Class: YARD::I18n::Text
- Inherits:
-
Object
- Object
- YARD::I18n::Text
- Defined in:
- lib/yard/i18n/text.rb
Overview
Provides some convenient features for translating a text.
Instance Method Summary collapse
-
#extract_messages {|:attribute, name, value, line_no| ... } ⇒ void
Extracts translation target messages from @input.
-
#initialize(input, options = {}) ⇒ Text
constructor
Creates a text object that has translation related features for the input text.
-
#translate(locale) ⇒ String
Translates into
locale
.
Constructor Details
#initialize(input, options = {}) ⇒ Text
Creates a text object that has translation related features for the input text.
11 12 13 14 |
# File 'lib/yard/i18n/text.rb', line 11 def initialize(input, ={}) @input = input @options = end |
Instance Method Details
#extract_messages {|:attribute, name, value, line_no| ... } ⇒ void
This method returns an undefined value.
Extracts translation target messages from @input.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/yard/i18n/text.rb', line 34 def parse do |part| line_no = part[:line_no] case part[:type] when :markup, :empty_line # ignore when :attribute yield(:attribute, part[:name], part[:value], part[:line_no]) when :paragraph yield(:paragraph, part[:paragraph], part[:line_no]) end end end |
#translate(locale) ⇒ String
Translates into locale
.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/yard/i18n/text.rb', line 52 def translate(locale) translated_text = "" parse do |part| case part[:type] when :markup translated_text << part[:line] when :attribute prefix = "#{part[:prefix]}#{part[:name]}#{part[:infix]}" value = locale.translate(part[:value]) suffix = part[:suffix] translated_text << "#{prefix}#{value}#{suffix}" when :paragraph translated_text << locale.translate(part[:paragraph]) when :empty_line translated_text << part[:line] else raise "should not reach here: unexpected type: #{type}" end end translated_text end |