Interface to translations of human text used in a project.

Methods
#
L
M
N
P
Attributes
[R] locale

The locale into which the #[] method will translate phrases.

Class Public methods
new(project_install_dir)
# File lib/inochi/init.rb, line 175
    def initialize project_install_dir
      # load language translations dynamically
        lang_dir = File.join(project_install_dir, 'lang')

        @phrases_by_language = Hash.new do |cache, language|
          # store the phrase upon failure so that
          # the phrases() method will know about it
          phrases = Hash.new {|h,k| h[k] = nil }

          lang_file = File.join(lang_dir, "#{language}.yaml")
          lang_data = YAML.load_file(lang_file) rescue nil
          phrases.merge! lang_data if lang_data

          cache[language] = phrases
        end

      # detect user's preferred locale
      self.locale = ENV['LC_ALL'] || ENV['LC_MESSAGES'] || ENV['LANG']
    end
Instance Public methods
[](phrase, *words)

Translates the given phrase into the target locale (see locale and locale=) and then substitutes the given placeholder arguments into the translation (see Kernel#sprintf).

If a translation is not available for the given phrase, then the given phrase will be used as-is, untranslated.

# File lib/inochi/init.rb, line 223
    def [] phrase, *words
      translate @language, phrase, *words
    end
locale=(locale)
# File lib/inochi/init.rb, line 198
    def locale= locale
      @locale = locale.to_s

      # extract the language portion of the locale
      language  = @locale[/^[[:alpha:]]+/].to_s
      @language = language =~ /^(C|POSIX)?$/i ? :en : language.downcase.to_sym
    end
method_missing(meth, *args)

Provides access to translations in any language, regardless of the target locale (see locale and locale=).

For example, you can access Japanese translations via the jp method even if the target locale is French.

# File lib/inochi/init.rb, line 234
    def method_missing meth, *args
      # ISO 639 language codes come in alpha-2 and alpha-3 forms
      if meth.to_s =~ /^[a-z]{2,3}$/
        translate meth, *args
      else
        super
      end
    end
phrases()

Returns all phrases that underwent (or attempted) translation via this object.

# File lib/inochi/init.rb, line 210
    def phrases
      @phrases_by_language.values.map {|h| h.keys }.flatten.uniq.sort
    end