lib/liquid/i18n.rb in liquid-3.0.6 vs lib/liquid/i18n.rb in liquid-4.0.0.rc1

- old
+ new

@@ -1,13 +1,12 @@ require 'yaml' module Liquid class I18n - DEFAULT_LOCALE = File.join(File.expand_path(File.dirname(__FILE__)), "locales", "en.yml") + DEFAULT_LOCALE = File.join(File.expand_path(__dir__), "locales", "en.yml") - class TranslationError < StandardError - end + TranslationError = Class.new(StandardError) attr_reader :path def initialize(path = DEFAULT_LOCALE) @path = path @@ -21,14 +20,15 @@ def locale @locale ||= YAML.load_file(@path) end private + def interpolate(name, vars) - name.gsub(/%\{(\w+)\}/) { + name.gsub(/%\{(\w+)\}/) do # raise TranslationError, "Undefined key #{$1} for interpolation in translation #{name}" unless vars[$1.to_sym] "#{vars[$1.to_sym]}" - } + end end 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}"