# File lib/ramaze/helper/localize.rb, line 73 73: def [](locale) 74: @dict[arg_to_locale(locale)] 75: end
# File lib/ramaze/helper/localize.rb, line 77 77: def []=(locale, dict) 78: @dict[arg_to_locale(locale)] = dict 79: end
# File lib/ramaze/helper/localize.rb, line 81 81: def load(locale, options = {}) 82: if file = options.delete(:yaml) 83: dict = ::YAML.load_file(file) 84: elsif hash = options.delete(:hash) 85: dict = hash 86: elsif marshal = options.delete(:marshal) 87: dict = Marshal.load(File.read(marshal)) 88: else 89: raise ArgumentError, "either :yaml, :marshal, or :hash" 90: end 91: 92: @dict[arg_to_locale(locale)] = dict 93: end
# File lib/ramaze/helper/localize.rb, line 69 69: def locales 70: @dict.keys 71: end
# File lib/ramaze/helper/localize.rb, line 59 59: def lookup(string, locales) 60: locales.each do |locale| 61: next unless dict = self[locale] 62: next unless translated = dict[string] 63: return translated 64: end 65: 66: string 67: end
# File lib/ramaze/helper/localize.rb, line 42 42: def translate(string, locales, substitute) 43: target = string.to_s.dup 44: locales = locales.flatten.uniq 45: 46: if substitute 47: substitute.each do |key, value| 48: target.gsub!(/\{#{Regexp.escape(key)}\}/, lookup(value, locales)) 49: end 50: return target 51: elsif target =~ /\{/ 52: target.gsub!(/\{([^\}]+)\}/){ lookup($1, locales) } 53: return target 54: else 55: lookup(target, locales) 56: end 57: end
# File lib/ramaze/helper/localize.rb, line 97 97: def arg_to_locale(arg, raises = true) 98: if raises and not arg 99: raise(ArgumentError, "%p cannot be converted to a Locale" % arg) 100: end 101: arg.respond_to?(:language) ? arg : ::Locale::Tag.parse(arg.to_s) 102: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.