Module: AlpacaComplete::LocaleComplete

Defined in:
lib/AlpacaComplete/locale_complete.rb

Constant Summary collapse

LOCALE_PATH =
'config/locales'

Class Method Summary collapse

Class Method Details

.complete(path, word) ⇒ Object

return array of list to match word



9
10
11
12
13
14
# 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) ⇒ Object

return hash deep_merged config/locales/*/.yml



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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 = {}) ⇒ Object

return hash of locale list. hash key is full_name.



29
30
31
# File 'lib/AlpacaComplete/locale_complete.rb', line 29

def get_locale_hash( opt={} )
  get_locale( opt["path"] ).join_keys(".")
end

.get_locale_list(opt = {}) ⇒ Object

return array of locale list.



17
18
19
20
21
22
23
24
25
26
# 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