module AlpacaComplete::LocaleComplete

Constants

LOCALE_PATH

Public Class Methods

complete( path, word ) click to toggle source

return array of list to match word

# File lib/AlpacaComplete/locale_complete.rb, line 9
def complete( path, word )
  opt = { "path" => path }
  comp = Regexp.new("^#{word}")

  get_locale_hash( opt ).select {|v| v.match comp }
end
get_locale( file_path ) click to toggle source

return hash deep_merged config/locales/*/.yml

# File lib/AlpacaComplete/locale_complete.rb, line 34
def get_locale( file_path )
  require 'yaml'

  rails_root  = ::AlpacaComplete::Detect.detect( file_path )
  locale_path = "#{rails_root}/#{LOCALE_PATH}"

  # hash
  locales = Hash.new

  Dir.glob( "#{locale_path}/**/*.yml" ).each do |file|
    locale_hash = YAML::load_file( file )
    locales.deep_merge!(locale_hash)
  end

  locales
end
get_locale_hash( opt={} ) click to toggle source

return hash of locale list. hash key is full_name.

# File lib/AlpacaComplete/locale_complete.rb, line 29
def get_locale_hash( opt={} )
  get_locale( opt["path"] ).join_keys(".")
end
get_locale_list( opt={} ) click to toggle source

return array of locale list.

# File lib/AlpacaComplete/locale_complete.rb, line 17
def get_locale_list( opt={} )
  locales = get_locale_hash(opt)

  res = []
  locales.each do |k, v|
    res << k
  end

  res
end