Class: Liquid::I18n

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid/i18n.rb

Constant Summary collapse

DEFAULT_LOCALE =
File.join(File.expand_path(__dir__), "locales", "en.yml")
TranslationError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = DEFAULT_LOCALE) ⇒ I18n

Returns a new instance of I18n.



13
14
15
# File 'lib/liquid/i18n.rb', line 13

def initialize(path = DEFAULT_LOCALE)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/liquid/i18n.rb', line 11

def path
  @path
end

Instance Method Details

#localeObject



22
23
24
# File 'lib/liquid/i18n.rb', line 22

def locale
  @locale ||= YAML.load_file(@path)
end

#translate(name, vars = {}) ⇒ Object Also known as: t



17
18
19
# File 'lib/liquid/i18n.rb', line 17

def translate(name, vars = {})
  interpolate(deep_fetch_translation(name), vars)
end