class YARD::I18n::Locale

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

@since 0.8.2

Attributes

default[RW]

@return [String, nil] the default locale name. @since 0.8.4

name[R]

@return [String] the name of the locale. It used IETF language

tag format +[language[_territory][.codeset][@modifier]]+.

@see tools.ietf.org/rfc/bcp/bcp47.txt

BCP 47 - Tags for Identifying Languages

Public Class Methods

default=(locale) click to toggle source
# File lib/yard/i18n/locale.rb, line 20
def default=(locale)
  @@default = locale
end
new(name) click to toggle source

Creates a locale for name locale.

@param [String] name the locale name.

# File lib/yard/i18n/locale.rb, line 34
def initialize(name)
  @name = name
  @messages = {}
end

Public Instance Methods

load(locale_directory) click to toggle source

Loads translation messages from locale_directory/{#name}.po.

@param [String] locale_directory the directory path that has

{#name}.po.

@return [Boolean] true if PO file exists, false otherwise.

# 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) click to toggle source

@param [String] message the translation target message. @return [String] translated message. If tarnslation isn't

registered, the +message+ is returned.
# File lib/yard/i18n/locale.rb, line 62
def translate(message)
  @messages[message] || message
end