2013-04-24 00:40:09 -04:00
|
|
|
module I18n
|
|
|
|
# this accelerates translation a tiny bit (halves the time it takes)
|
|
|
|
class << self
|
|
|
|
alias_method :translate_no_cache, :translate
|
|
|
|
alias_method :reload_no_cache!, :reload!
|
|
|
|
LRU_CACHE_SIZE = 2000
|
|
|
|
|
|
|
|
def reload!
|
|
|
|
@cache = nil
|
|
|
|
reload_no_cache!
|
|
|
|
end
|
|
|
|
|
|
|
|
def translate(*args)
|
|
|
|
@cache ||= LruRedux::ThreadSafeCache.new(LRU_CACHE_SIZE)
|
|
|
|
found = true
|
2014-02-26 12:42:16 -05:00
|
|
|
k = [args, config.locale, config.backend.object_id]
|
|
|
|
t = @cache.fetch(k) { found = false }
|
2013-04-24 00:40:09 -04:00
|
|
|
unless found
|
2014-02-26 12:42:16 -05:00
|
|
|
begin
|
|
|
|
t = translate_no_cache(*args)
|
|
|
|
rescue MissingInterpolationArgument
|
|
|
|
options = args.last.is_a?(Hash) ? args.pop.dup : {}
|
|
|
|
options.merge!(locale: config.default_locale)
|
|
|
|
key = args.shift
|
|
|
|
t = translate_no_cache(key, options)
|
|
|
|
ensure
|
|
|
|
t = @cache[k] = t.freeze
|
|
|
|
end
|
2013-04-24 00:40:09 -04:00
|
|
|
end
|
2014-02-17 19:14:35 -05:00
|
|
|
t
|
2013-04-24 00:40:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :t, :translate
|
|
|
|
end
|
|
|
|
end
|