/usr/lib/ruby/vendor_ruby/wikicloth/i18n.rb is in ruby-wikicloth 0.8.1+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | require 'yaml'
module I18n
class << self
def default_locale
:en
end
def locale
@@locale ||= default_locale
end
def locale=(val)
@@locale = val
end
def t(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
key = args.shift
load_translations
use_locale = @@translations[locale].nil? || @@translations[locale].empty? ? default_locale : locale
if !@@translations[use_locale].nil? && @@translations[use_locale].has_key?(key)
add_vars(@@translations[use_locale][key], options)
elsif use_locale != default_locale && @@translations[default_locale].has_key?(key)
add_vars(@@translations[default_locale][key], options)
else
"translation missing: #{locale}, #{key}"
end
end
def available_locales
load_translations
@@available_locales
end
def load_path
@@load_paths ||= []
end
def load_path=(val)
@@load_paths = val
end
def load_translations
return if initialized?
@@available_locales = []
@@translations = {}
load_path.each do |path|
Dir[path].each do |file|
begin
data = YAML::load(File.read(file))
data.each do |key,value|
@@available_locales << key.to_sym unless @@available_locales.include?(key.to_sym)
@@translations[key.to_sym] ||= {}
import_values(key.to_sym,value)
end
rescue ArgumentError => err
puts "error in #{file}: #{err.message}"
end
end
end
initialized!
end
def initialized?
@@initialized ||= false
end
def initialized!
@@initialized = true
end
# Executes block with given I18n.locale set.
def with_locale(tmp_locale = nil)
if tmp_locale
current_locale = self.locale
self.locale = tmp_locale
end
yield
ensure
self.locale = current_locale if tmp_locale
end
private
def import_values(key,values,prefix=[])
values.each do |k,value|
if value.is_a?(Hash)
import_values(key,value,prefix+[k])
else
@@translations[key.to_sym][(prefix+[k]).join(".")] = value
end
end
end
def add_vars(string, options)
options.each do |key,value|
string.gsub!(/(%\{#{key}\})/, value.to_s)
end
string
end
end
end
|