Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/irb
File: locale.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# irb/locale.rb - internationalization module
[2] Fix | Delete
# $Release Version: 0.9.6$
[3] Fix | Delete
# $Revision$
[4] Fix | Delete
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
[5] Fix | Delete
#
[6] Fix | Delete
# --
[7] Fix | Delete
#
[8] Fix | Delete
#
[9] Fix | Delete
#
[10] Fix | Delete
module IRB # :nodoc:
[11] Fix | Delete
class Locale
[12] Fix | Delete
[13] Fix | Delete
LOCALE_NAME_RE = %r[
[14] Fix | Delete
(?<language>[[:alpha:]]{2,3})
[15] Fix | Delete
(?:_ (?<territory>[[:alpha:]]{2,3}) )?
[16] Fix | Delete
(?:\. (?<codeset>[^@]+) )?
[17] Fix | Delete
(?:@ (?<modifier>.*) )?
[18] Fix | Delete
]x
[19] Fix | Delete
LOCALE_DIR = "/lc/"
[20] Fix | Delete
[21] Fix | Delete
@@legacy_encoding_alias_map = {}.freeze
[22] Fix | Delete
@@loaded = []
[23] Fix | Delete
[24] Fix | Delete
def initialize(locale = nil)
[25] Fix | Delete
@override_encoding = nil
[26] Fix | Delete
@lang = @territory = @encoding_name = @modifier = nil
[27] Fix | Delete
@locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
[28] Fix | Delete
if m = LOCALE_NAME_RE.match(@locale)
[29] Fix | Delete
@lang, @territory, @encoding_name, @modifier = m[:language], m[:territory], m[:codeset], m[:modifier]
[30] Fix | Delete
[31] Fix | Delete
if @encoding_name
[32] Fix | Delete
begin load 'irb/encoding_aliases.rb'; rescue LoadError; end
[33] Fix | Delete
if @encoding = @@legacy_encoding_alias_map[@encoding_name]
[34] Fix | Delete
warn(("%s is obsolete. use %s" % ["#{@lang}_#{@territory}.#{@encoding_name}", "#{@lang}_#{@territory}.#{@encoding.name}"]), uplevel: 1)
[35] Fix | Delete
end
[36] Fix | Delete
@encoding = Encoding.find(@encoding_name) rescue nil
[37] Fix | Delete
end
[38] Fix | Delete
end
[39] Fix | Delete
@encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
[40] Fix | Delete
end
[41] Fix | Delete
[42] Fix | Delete
attr_reader :lang, :territory, :modifier
[43] Fix | Delete
[44] Fix | Delete
def encoding
[45] Fix | Delete
@override_encoding || @encoding
[46] Fix | Delete
end
[47] Fix | Delete
[48] Fix | Delete
def String(mes)
[49] Fix | Delete
mes = super(mes)
[50] Fix | Delete
if encoding
[51] Fix | Delete
mes.encode(encoding, undef: :replace)
[52] Fix | Delete
else
[53] Fix | Delete
mes
[54] Fix | Delete
end
[55] Fix | Delete
end
[56] Fix | Delete
[57] Fix | Delete
def format(*opts)
[58] Fix | Delete
String(super(*opts))
[59] Fix | Delete
end
[60] Fix | Delete
[61] Fix | Delete
def gets(*rs)
[62] Fix | Delete
String(super(*rs))
[63] Fix | Delete
end
[64] Fix | Delete
[65] Fix | Delete
def readline(*rs)
[66] Fix | Delete
String(super(*rs))
[67] Fix | Delete
end
[68] Fix | Delete
[69] Fix | Delete
def print(*opts)
[70] Fix | Delete
ary = opts.collect{|opt| String(opt)}
[71] Fix | Delete
super(*ary)
[72] Fix | Delete
end
[73] Fix | Delete
[74] Fix | Delete
def printf(*opts)
[75] Fix | Delete
s = format(*opts)
[76] Fix | Delete
print s
[77] Fix | Delete
end
[78] Fix | Delete
[79] Fix | Delete
def puts(*opts)
[80] Fix | Delete
ary = opts.collect{|opt| String(opt)}
[81] Fix | Delete
super(*ary)
[82] Fix | Delete
end
[83] Fix | Delete
[84] Fix | Delete
def require(file, priv = nil)
[85] Fix | Delete
rex = Regexp.new("lc/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
[86] Fix | Delete
return false if $".find{|f| f =~ rex}
[87] Fix | Delete
[88] Fix | Delete
case file
[89] Fix | Delete
when /\.rb$/
[90] Fix | Delete
begin
[91] Fix | Delete
load(file, priv)
[92] Fix | Delete
$".push file
[93] Fix | Delete
return true
[94] Fix | Delete
rescue LoadError
[95] Fix | Delete
end
[96] Fix | Delete
when /\.(so|o|sl)$/
[97] Fix | Delete
return super
[98] Fix | Delete
end
[99] Fix | Delete
[100] Fix | Delete
begin
[101] Fix | Delete
load(f = file + ".rb")
[102] Fix | Delete
$".push f #"
[103] Fix | Delete
return true
[104] Fix | Delete
rescue LoadError
[105] Fix | Delete
return ruby_require(file)
[106] Fix | Delete
end
[107] Fix | Delete
end
[108] Fix | Delete
[109] Fix | Delete
alias toplevel_load load
[110] Fix | Delete
[111] Fix | Delete
def load(file, priv=nil)
[112] Fix | Delete
found = find(file)
[113] Fix | Delete
if found
[114] Fix | Delete
unless @@loaded.include?(found)
[115] Fix | Delete
@@loaded << found # cache
[116] Fix | Delete
return real_load(found, priv)
[117] Fix | Delete
end
[118] Fix | Delete
else
[119] Fix | Delete
raise LoadError, "No such file to load -- #{file}"
[120] Fix | Delete
end
[121] Fix | Delete
end
[122] Fix | Delete
[123] Fix | Delete
def find(file , paths = $:)
[124] Fix | Delete
dir = File.dirname(file)
[125] Fix | Delete
dir = "" if dir == "."
[126] Fix | Delete
base = File.basename(file)
[127] Fix | Delete
[128] Fix | Delete
if dir.start_with?('/')
[129] Fix | Delete
return each_localized_path(dir, base).find{|full_path| File.readable? full_path}
[130] Fix | Delete
else
[131] Fix | Delete
return search_file(paths, dir, base)
[132] Fix | Delete
end
[133] Fix | Delete
end
[134] Fix | Delete
[135] Fix | Delete
private
[136] Fix | Delete
def real_load(path, priv)
[137] Fix | Delete
src = MagicFile.open(path){|f| f.read}
[138] Fix | Delete
if priv
[139] Fix | Delete
eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
[140] Fix | Delete
else
[141] Fix | Delete
eval(src, TOPLEVEL_BINDING, path)
[142] Fix | Delete
end
[143] Fix | Delete
end
[144] Fix | Delete
[145] Fix | Delete
# @param paths load paths in which IRB find a localized file.
[146] Fix | Delete
# @param dir directory
[147] Fix | Delete
# @param file basename to be localized
[148] Fix | Delete
#
[149] Fix | Delete
# typically, for the parameters and a <path> in paths, it searches
[150] Fix | Delete
# <path>/<dir>/<locale>/<file>
[151] Fix | Delete
def search_file(lib_paths, dir, file)
[152] Fix | Delete
each_localized_path(dir, file) do |lc_path|
[153] Fix | Delete
lib_paths.each do |libpath|
[154] Fix | Delete
full_path = File.join(libpath, lc_path)
[155] Fix | Delete
return full_path if File.readable?(full_path)
[156] Fix | Delete
end
[157] Fix | Delete
redo if defined?(Gem) and Gem.try_activate(lc_path)
[158] Fix | Delete
end
[159] Fix | Delete
nil
[160] Fix | Delete
end
[161] Fix | Delete
[162] Fix | Delete
def each_localized_path(dir, file)
[163] Fix | Delete
return enum_for(:each_localized_path) unless block_given?
[164] Fix | Delete
each_sublocale do |lc|
[165] Fix | Delete
yield lc.nil? ? File.join(dir, LOCALE_DIR, file) : File.join(dir, LOCALE_DIR, lc, file)
[166] Fix | Delete
end
[167] Fix | Delete
end
[168] Fix | Delete
[169] Fix | Delete
def each_sublocale
[170] Fix | Delete
if @lang
[171] Fix | Delete
if @territory
[172] Fix | Delete
if @encoding_name
[173] Fix | Delete
yield "#{@lang}_#{@territory}.#{@encoding_name}@#{@modifier}" if @modifier
[174] Fix | Delete
yield "#{@lang}_#{@territory}.#{@encoding_name}"
[175] Fix | Delete
end
[176] Fix | Delete
yield "#{@lang}_#{@territory}@#{@modifier}" if @modifier
[177] Fix | Delete
yield "#{@lang}_#{@territory}"
[178] Fix | Delete
end
[179] Fix | Delete
if @encoding_name
[180] Fix | Delete
yield "#{@lang}.#{@encoding_name}@#{@modifier}" if @modifier
[181] Fix | Delete
yield "#{@lang}.#{@encoding_name}"
[182] Fix | Delete
end
[183] Fix | Delete
yield "#{@lang}@#{@modifier}" if @modifier
[184] Fix | Delete
yield "#{@lang}"
[185] Fix | Delete
end
[186] Fix | Delete
yield nil
[187] Fix | Delete
end
[188] Fix | Delete
end
[189] Fix | Delete
end
[190] Fix | Delete
[191] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function