Class IRB::Locale
In: lib/irb/locale.rb
Parent: Object

Methods

String   find   format   gets   lc2kconv   lc_path   load   new   print   printf   puts   readline   real_load   require   search_file  

Constants

JPDefaultLocale = "ja"
LOCALE_DIR = "/lc/"

External Aliases

load -> toplevel_load

Attributes

lang  [R] 

Public Class methods

[Source]

    # 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

Public Instance methods

[Source]

    # 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

[Source]

     # 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

[Source]

    # File lib/irb/locale.rb, line 51
51:     def format(*opts)
52:       String(super(*opts))
53:     end

[Source]

    # File lib/irb/locale.rb, line 55
55:     def gets(*rs)
56:       String(super(*rs))
57:     end

[Source]

     # 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

[Source]

    # File lib/irb/locale.rb, line 63
63:     def print(*opts)
64:       ary = opts.collect{|opt| String(opt)}
65:       super(*ary)
66:     end

[Source]

    # File lib/irb/locale.rb, line 68
68:     def printf(*opts)
69:       s = format(*opts)
70:       print s
71:     end

[Source]

    # File lib/irb/locale.rb, line 73
73:     def puts(*opts)
74:       ary = opts.collect{|opt| String(opt)}
75:       super(*ary)
76:     end

[Source]

    # File lib/irb/locale.rb, line 59
59:     def readline(*rs)
60:       String(super(*rs))
61:     end

[Source]

     # 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

Private Instance methods

[Source]

    # 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

[Source]

     # 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

[Source]

     # 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

[Source]

     # File lib/irb/locale.rb, line 155
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))
158:           return p2
159:         else
160:         end
161:         return p1
162:       else
163:       end
164:       nil
165:     end

[Validate]