class Liquid::I18n
def deep_fetch_translation(name)
def deep_fetch_translation(name) name.split('.').reduce(locale) do |level, cur| level[cur] || raise(TranslationError, "Translation for #{name} does not exist in locale #{path}") end end
def initialize(path = DEFAULT_LOCALE)
def initialize(path = DEFAULT_LOCALE) @path = path end
def interpolate(name, vars)
def interpolate(name, vars) name.gsub(/%\{(\w+)\}/) do # raise TranslationError, "Undefined key #{$1} for interpolation in translation #{name}" unless vars[$1.to_sym] (vars[Regexp.last_match(1).to_sym]).to_s end end
def locale
def locale @locale ||= YAML.load_file(@path) end
def translate(name, vars = {})
def translate(name, vars = {}) interpolate(deep_fetch_translation(name), vars) end