Class: IRB::Locale

Inherits:
Object show all
Defined in:
lib/irb/locale.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale = nil) ⇒ Locale

Returns a new instance of Locale.



22
23
24
# File 'lib/irb/locale.rb', line 22

def initialize(locale = nil)
  @lang = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C" 
end

Instance Attribute Details

#langObject (readonly)

Returns the value of attribute lang



26
27
28
# File 'lib/irb/locale.rb', line 26

def lang
  @lang
end

Instance Method Details

#find(file, paths = $:) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/irb/locale.rb', line 139

def find(file , paths = $:)
  dir = File.dirname(file)
  dir = "" if dir == "."
  base = File.basename(file)
  if dir[0] == ?/ #/
	  return lc_path = search_file(dir, base)
  else
	for path in $:
	  if lc_path = search_file(path + "/" + dir, base)
 return lc_path
	  end
	end
  end
  nil
end

#format(*opts) ⇒ Object



51
52
53
# File 'lib/irb/locale.rb', line 51

def format(*opts)
  String(super(*opts))
end

#gets(*rs) ⇒ Object



55
56
57
# File 'lib/irb/locale.rb', line 55

def gets(*rs)
  String(super(*rs))
end

#load(file, priv = nil) ⇒ Object Also known as: toplevel_load

Raises:

  • (LoadError)


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/irb/locale.rb', line 105

def load(file, priv=nil)
  dir = File.dirname(file)
  dir = "" if dir == "."
  base = File.basename(file)

  if /^ja(_JP)?$/ =~ @lang
 	back, @lang = @lang, "C"
  end
  begin
	if dir[0] == ?/ #/
	  lc_path = search_file(dir, base)
	  return real_load(lc_path, priv) if lc_path
	end
	
	for path in $:
	  lc_path = search_file(path + "/" + dir, base)
	  return real_load(lc_path, priv) if lc_path
	end
  ensure
	@lang = back if back
  end
  raise LoadError, "No such file to load -- #{file}"
end


63
64
65
66
# File 'lib/irb/locale.rb', line 63

def print(*opts)
  ary = opts.collect{|opt| String(opt)}
  super(*ary)
end

#printf(*opts) ⇒ Object



68
69
70
71
# File 'lib/irb/locale.rb', line 68

def printf(*opts)
  s = format(*opts)
  print s
end

#puts(*opts) ⇒ Object



73
74
75
76
# File 'lib/irb/locale.rb', line 73

def puts(*opts)
  ary = opts.collect{|opt| String(opt)}
  super(*ary)
end

#readline(*rs) ⇒ Object



59
60
61
# File 'lib/irb/locale.rb', line 59

def readline(*rs)
  String(super(*rs))
end

#require(file, priv = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/irb/locale.rb', line 78

def require(file, priv = nil)
  rex = Regexp.new("lc/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
  return false if $".find{|f| f =~ rex}

  case file
  when /\.rb$/
	begin
	  load(file, priv)
	  $".push file
	  return true
	rescue LoadError
	end
  when /\.(so|o|sl)$/
	return super
  end

  begin
	load(f = file + ".rb")
	$".push f  #"
	return true
  rescue LoadError
	return ruby_require(file)
  end
end

#String(mes) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/irb/locale.rb', line 40

def String(mes)
  mes = super(mes)
  case @lang
  when /^ja/
	mes = Kconv::kconv(mes, lc2kconv(@lang))
  else
	mes
  end
  mes
end