-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18_n.rb
42 lines (36 loc) · 1004 Bytes
/
i18_n.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Neo
module I18N
attr_accessor :phrases
def initialize
@phrases = {}
language_files.each {|file| require file }
end
# gets the language files of modules and Neo
def language_files
paths = []
# find in application
paths << "#{Neo.app_dir}/modules/*/i18_n/*.rb"
# find in Neo
paths << "#{Neo.dir}/i18_n/*.rb"
paths.reduce([]) {|files, path| files + Dir[path]}
end
def translate(phrase, lang)
Neo::Exceptions::SystemError.new("Can't find the phrases for language:#{lang}").raise if @phrases[lang].nil?
found = @phrases[lang].find{|i| i[0]==phrase}
if found.nil?
puts "Can't find a translation for #{phrase}. Returning original one"
phrase
else
found[1]
end
end
def change_lang(lang)
Neo::Config[:lang] = lang
end
def add(lang, phrase_array)
@phrases[lang] ||= []
@phrases[lang] += phrase_array
end
make_modular
end
end