| Class | IRB::Locale |
| In: |
lib/irb/locale.rb
|
| Parent: | Object |
| JPDefaultLocale | = | "ja" |
| LOCALE_DIR | = | "/lc/" |
| load | -> | toplevel_load |
| lang | [R] |
# File lib/irb/locale.rb, line 22
22: def initialize(locale = nil)
23: @lang = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
24: end
# File lib/irb/locale.rb, line 40
40: def String(mes)
41: mes = super(mes)
42: case @lang
43: when /^ja/
44: mes = Kconv::kconv(mes, lc2kconv(@lang))
45: else
46: mes
47: end
48: mes
49: end
# File lib/irb/locale.rb, line 139
139: def find(file , paths = $:)
140: dir = File.dirname(file)
141: dir = "" if dir == "."
142: base = File.basename(file)
143: if dir[0] == ?/ #/
144: return lc_path = search_file(dir, base)
145: else
146: for path in $:
147: if lc_path = search_file(path + "/" + dir, base)
148: return lc_path
149: end
150: end
151: end
152: nil
153: end
# File lib/irb/locale.rb, line 105
105: def load(file, priv=nil)
106: dir = File.dirname(file)
107: dir = "" if dir == "."
108: base = File.basename(file)
109:
110: if /^ja(_JP)?$/ =~ @lang
111: back, @lang = @lang, "C"
112: end
113: begin
114: if dir[0] == ?/ #/
115: lc_path = search_file(dir, base)
116: return real_load(lc_path, priv) if lc_path
117: end
118:
119: for path in $:
120: lc_path = search_file(path + "/" + dir, base)
121: return real_load(lc_path, priv) if lc_path
122: end
123: ensure
124: @lang = back if back
125: end
126: raise LoadError, "No such file to load -- #{file}"
127: end
# File lib/irb/locale.rb, line 63
63: def print(*opts)
64: ary = opts.collect{|opt| String(opt)}
65: super(*ary)
66: end
# File lib/irb/locale.rb, line 73
73: def puts(*opts)
74: ary = opts.collect{|opt| String(opt)}
75: super(*ary)
76: end
# File lib/irb/locale.rb, line 78
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}
81:
82: case file
83: when /\.rb$/
84: begin
85: load(file, priv)
86: $".push file
87: return true
88: rescue LoadError
89: end
90: when /\.(so|o|sl)$/
91: return super
92: end
93:
94: begin
95: load(f = file + ".rb")
96: $".push f #"
97: return true
98: rescue LoadError
99: return ruby_require(file)
100: end
101: end
# File lib/irb/locale.rb, line 28
28: def lc2kconv(lang)
29: case lang
30: when "ja_JP.ujis", "ja_JP.euc", "ja_JP.eucJP"
31: Kconv::EUC
32: when "ja_JP.sjis", "ja_JP.SJIS"
33: Kconv::SJIS
34: when /ja_JP.utf-?8/i
35: Kconv::UTF8
36: end
37: end
# File lib/irb/locale.rb, line 168
168: def lc_path(file = "", lc = @lang)
169: case lc
170: when "C"
171: LOCALE_DIR + file
172: when /^ja/
173: LOCALE_DIR + "ja/" + file
174: else
175: LOCALE_DIR + @lang + "/" + file
176: end
177: end
# File lib/irb/locale.rb, line 129
129: def real_load(path, priv)
130: src = self.String(File.read(path))
131: if priv
132: eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
133: else
134: eval(src, TOPLEVEL_BINDING, path)
135: end
136: end