123456789_123456789_123456789_123456789_123456789_

Class: YARD::I18n::Locale

Relationships & Source Files
Inherits: Object
Defined in: lib/yard/i18n/locale.rb

Overview

Locale is a unit of translation. It has #name and a set of messages.

Since:

  • 0.8.2

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name) ⇒ Locale

Creates a locale for #name locale.

Parameters:

  • name (String)

    the locale name.

Since:

  • 0.8.2

[ GitHub ]

  
# File 'lib/yard/i18n/locale.rb', line 34

def initialize(name)
  @name = name
  @messages = {}
end

Class Attribute Details

.defaultString? (rw)

Returns:

  • (String, nil)

    the default locale name.

Since:

  • 0.8.4

[ GitHub ]

  
# File 'lib/yard/i18n/locale.rb', line 15

attr_accessor :default

.default=(locale) ⇒ String? (rw)

Returns:

  • (String, nil)

    the default locale name.

Since:

  • 0.8.4

[ GitHub ]

  
# File 'lib/yard/i18n/locale.rb', line 20

attr_accessor :default

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)

    the name of the locale. It used IETF language tag format [language[_territory][.codeset][@modifier]].

See Also:

Since:

  • 0.8.2

[ GitHub ]

  
# File 'lib/yard/i18n/locale.rb', line 29

attr_reader :name

Instance Method Details

#load(locale_directory) ⇒ Boolean

Loads translation messages from +locale_directory+/#name.po.

Parameters:

  • locale_directory (String)

    the directory path that has #name.po.

Returns:

  • (Boolean)

    true if PO file exists, false otherwise.

Since:

  • 0.8.2

[ GitHub ]

  
# File 'lib/yard/i18n/locale.rb', line 44

def load(locale_directory)
  return false if @name.nil?

  po_file = File.join(locale_directory, "#{@name}.po")
  return false unless File.exist?(po_file)

  require "yard/i18n/po_parser"
  return false unless POParser.available?

  po_parser = POParser.new
  @messages.merge!(po_parser.parse(po_file))

  true
end

#translate(message) ⇒ String

Parameters:

  • message (String)

    the translation target message.

Returns:

  • (String)

    translated message. If translation isn't registered, the message is returned.

Since:

  • 0.8.2

[ GitHub ]

  
# File 'lib/yard/i18n/locale.rb', line 62

def translate(message)
  @messages[message] || message
end