Class: YARD::I18n::Locale
- Inherits:
-
Object
- Object
- YARD::I18n::Locale
- Defined in:
- lib/yard/i18n/locale.rb
Overview
Locale
is a unit of translation. It has #name and a set of messages.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the locale.
Instance Method Summary collapse
-
#initialize(name) ⇒ Locale
constructor
Creates a locale for
name
locale. -
#load(locale_directory) ⇒ Boolean
Loads translation messages from
locale_directory
/#name.po. -
#translate(message) ⇒ String
Translated message.
Constructor Details
#initialize(name) ⇒ Locale
Creates a locale for name
locale.
20 21 22 23 |
# File 'lib/yard/i18n/locale.rb', line 20 def initialize(name) @name = name @messages = {} end |
Instance Attribute Details
Instance Method Details
#load(locale_directory) ⇒ Boolean
Loads translation messages from locale_directory
/#name.po.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/yard/i18n/locale.rb', line 30 def load(locale_directory) po_file = File.join(locale_directory, "#{@name}.po") return false unless File.exist?(po_file) parser = GetText::PoParser.new parser.report_warning = false data = GetText::MoFile.new parser.parse_file(po_file, data) @messages.merge!(data) true end |
#translate(message) ⇒ String
Returns translated message. If tarnslation isn’t registered, the message
is returned.
45 46 47 |
# File 'lib/yard/i18n/locale.rb', line 45 def translate() @messages[] || end |