Object
A message container for a locale.
This object provides the following two features:
* Loads translated messages from .po file. * Translates a message into the locale.
The name of the locale. It uses IETF language tag format +[language[.codeset]]+.
See also BCP 47 - Tags for Identifying Languages.
Returns the locale object for locale_name.
# File rdoc/i18n/locale.rb, line 18
def [](locale_name)
@@locales[locale_name] ||= new(locale_name)
end
Loads translation messages from
locale_directory/+@name+/rdoc.po or
locale_directory/+@name+.po. The former has high priority.
This method requires gettext gem for parsing .po file. If you don’t have
gettext gem, this method doesn’t load .po file. This method warns and
returns false.
Returns true if succeeded, false otherwise.
# File rdoc/i18n/locale.rb, line 62
def load(locale_directory)
return false if @name.nil?
po_file_candidates = [
File.join(locale_directory, @name, 'rdoc.po'),
File.join(locale_directory, "#{@name}.po"),
]
po_file = po_file_candidates.find do |po_file_candidate|
File.exist?(po_file_candidate)
end
return false unless po_file
begin
require 'gettext/po_parser'
require 'gettext/mo'
rescue LoadError
warn('Need gettext gem for i18n feature:')
warn(' gem install gettext')
return false
end
po_parser = GetText::POParser.new
messages = GetText::MO.new
po_parser.report_warning = false
po_parser.parse_file(po_file, messages)
@messages.merge!(messages)
true
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.