In Files

  • rdoc/i18n/text.rb

Parent

Class/Module Index [+]

Quicksearch

RDoc::I18n::Text

An i18n supported text.

This object provides the following two features:

* Extracts translation messages from wrapped raw text.
* Translates wrapped raw text in specified locale.

Wrapped raw text is one of String, RDoc::Comment or Array of them.

Public Class Methods

new(raw) click to toggle source

Creates a new i18n supported text for raw text.

 
               # File rdoc/i18n/text.rb, line 16
def initialize(raw)
  @raw = raw
end
            

Public Instance Methods

extract_messages() click to toggle source

Extracts translation target messages and yields each message.

Each yielded message is a Hash. It consists of the followings:

:type

:paragraph

:paragraph

String (The translation target message itself.)

:line_no

Integer (The line number of the :paragraph is started.)

The above content may be added in the future.

 
               # File rdoc/i18n/text.rb, line 31
def extract_messages
  parse do |part|
    case part[:type]
    when :empty_line
      # ignore
    when :paragraph
      yield(part)
    end
  end
end
            
translate(locale) click to toggle source

Translates raw text into locale.

 
               # File rdoc/i18n/text.rb, line 43
def translate(locale)
  translated_text = ''
  parse do |part|
    case part[:type]
    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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.