Class: RDoc::I18n::Text
- Inherits:
-
Object
- Object
- RDoc::I18n::Text
- Defined in:
- lib/rdoc/i18n/text.rb
Overview
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.
Instance Method Summary collapse
-
#extract_messages ⇒ Object
Extracts translation target messages and yields each message.
-
#initialize(raw) ⇒ Text
constructor
Creates a new i18n supported text for
raw
text. -
#translate(locale) ⇒ Object
Translates raw text into
locale
.
Constructor Details
#initialize(raw) ⇒ Text
Creates a new i18n supported text for raw
text.
16 17 18 |
# File 'lib/rdoc/i18n/text.rb', line 16 def initialize(raw) @raw = raw end |
Instance Method Details
#extract_messages ⇒ Object
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.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rdoc/i18n/text.rb', line 31 def parse do |part| case part[:type] when :empty_line # ignore when :paragraph yield(part) end end end |
#translate(locale) ⇒ Object
Translates raw text into locale
.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/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 |