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.
Class Attribute Summary collapse
-
.default ⇒ String?
The default locale name.
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.
33 34 35 36 |
# File 'lib/yard/i18n/locale.rb', line 33 def initialize(name) @name = name @messages = {} end |
Class Attribute Details
.default ⇒ String?
Returns the default locale name.
11 12 13 |
# File 'lib/yard/i18n/locale.rb', line 11 def default @default end |
Instance Attribute Details
Instance Method Details
#load(locale_directory) ⇒ Boolean
Loads translation messages from locale_directory
/#name.po.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/yard/i18n/locale.rb', line 43 def load(locale_directory) return false if @name.nil? po_file = File.join(locale_directory, "#{@name}.po") return false unless File.exist?(po_file) begin require "gettext/tools/poparser" require "gettext/runtime/mofile" rescue LoadError log.warn "Need gettext gem for i18n feature:" log.warn " gem install gettext" return false end 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.
69 70 71 |
# File 'lib/yard/i18n/locale.rb', line 69 def translate() @messages[] || end |