2 # irb/locale.rb - internationalization module
3 # $Release Version: 0.9.5$
5 # by Keiju ISHITSUKA(keiju@ruby-lang.org)
12 autoload :Kconv, "kconv"
18 JPDefaultLocale = "ja"
21 def initialize(locale = nil)
22 @lang = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
29 when "ja_JP.ujis", "ja_JP.euc", "ja_JP.eucJP", "ja_JP.EUC-JP"
31 when "ja_JP.sjis", "ja_JP.SJIS"
43 mes = Kconv::kconv(mes, lc2kconv(@lang))
63 ary = opts.collect{|opt| String(opt)}
73 ary = opts.collect{|opt| String(opt)}
77 def require(file, priv = nil)
78 rex = Regexp.new("lc/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
79 return false if $".find{|f| f =~ rex}
94 load(f = file + ".rb")
98 return ruby_require(file)
102 alias toplevel_load load
104 def load(file, priv=nil)
105 dir = File.dirname(file)
106 dir = "" if dir == "."
107 base = File.basename(file)
109 if /^ja(_JP)?$/ =~ @lang
110 back, @lang = @lang, "C"
114 lc_path = search_file(dir, base)
115 return real_load(lc_path, priv) if lc_path
119 lc_path = search_file(path + "/" + dir, base)
120 return real_load(lc_path, priv) if lc_path
125 raise LoadError, "No such file to load -- #{file}"
128 def real_load(path, priv)
129 src = self.String(File.read(path))
131 eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
133 eval(src, TOPLEVEL_BINDING, path)
138 def find(file , paths = $:)
139 dir = File.dirname(file)
140 dir = "" if dir == "."
141 base = File.basename(file)
143 return lc_path = search_file(dir, base)
146 if lc_path = search_file(path + "/" + dir, base)
154 def search_file(path, file)
155 if File.exist?(p1 = path + lc_path(file, "C"))
156 if File.exist?(p2 = path + lc_path(file))
167 def lc_path(file = "", lc = @lang)
172 LOCALE_DIR + "ja/" + file
174 LOCALE_DIR + @lang + "/" + file