2 # irb/locale.rb - internationalization module
3 # $Release Version: 0.9.5$
5 # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
6 # by Keiju ISHITSUKA(keiju@ruby-lang.org)
13 autoload :Kconv, "kconv"
17 @RCS_ID='-$Id: locale.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
19 JPDefaultLocale = "ja"
22 def initialize(locale = nil)
23 @lang = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
30 when "ja_JP.ujis", "ja_JP.euc", "ja_JP.eucJP"
32 when "ja_JP.sjis", "ja_JP.SJIS"
44 mes = Kconv::kconv(mes, lc2kconv(@lang))
64 ary = opts.collect{|opt| String(opt)}
74 ary = opts.collect{|opt| String(opt)}
78 def require(file, priv = nil)
79 rex = Regexp.new("lc/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
80 return false if $".find{|f| f =~ rex}
95 load(f = file + ".rb")
99 return ruby_require(file)
103 alias toplevel_load load
105 def load(file, priv=nil)
106 dir = File.dirname(file)
107 dir = "" if dir == "."
108 base = File.basename(file)
110 if /^ja(_JP)?$/ =~ @lang
111 back, @lang = @lang, "C"
115 lc_path = search_file(dir, base)
116 return real_load(lc_path, priv) if lc_path
120 lc_path = search_file(path + "/" + dir, base)
121 return real_load(lc_path, priv) if lc_path
126 raise LoadError, "No such file to load -- #{file}"
129 def real_load(path, priv)
130 src = self.String(File.read(path))
132 eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
134 eval(src, TOPLEVEL_BINDING, path)
139 def find(file , paths = $:)
140 dir = File.dirname(file)
141 dir = "" if dir == "."
142 base = File.basename(file)
144 return lc_path = search_file(dir, base)
147 if lc_path = search_file(path + "/" + dir, base)
155 def search_file(path, file)
156 if File.exist?(p1 = path + lc_path(file, "C"))
157 if File.exist?(p2 = path + lc_path(file))
168 def lc_path(file = "", lc = @lang)
173 LOCALE_DIR + "ja/" + file
175 LOCALE_DIR + @lang + "/" + file