# File lib/liquid/i18n.rb, line 12 def initialize(path = DEFAULT_LOCALE) @path = path end
# File lib/liquid/i18n.rb, line 21 def locale @locale ||= YAML.load_file(@path) end
# File lib/liquid/i18n.rb, line 16 def translate(name, vars = {}) interpolate(deep_fetch_translation(name), vars) end
# File lib/liquid/i18n.rb, line 33 def deep_fetch_translation(name) name.split('.'.freeze).reduce(locale) do |level, cur| level[cur] or raise TranslationError, "Translation for #{name} does not exist in locale #{path}" end end
# File lib/liquid/i18n.rb, line 26 def interpolate(name, vars) name.gsub(/%\{(\w+)\}/) { # raise TranslationError, "Undefined key #{$1} for interpolation in translation #{name}" unless vars[$1.to_sym] "#{vars[$1.to_sym]}" } end