Add locale to context registers

This commit is contained in:
Simon Eskildsen
2013-08-30 12:31:57 -04:00
parent 0a2f21386d
commit 40fba9ee6c
4 changed files with 29 additions and 17 deletions
+7 -14
View File
@@ -2,10 +2,14 @@ require 'yaml'
module Liquid
class I18n
DEFAULT_LOCALE = File.join(File.expand_path(File.dirname(__FILE__)), "locales", "en.yml")
class TranslationError < StandardError
end
attr_reader :path
def initialize(path)
def initialize(path = DEFAULT_LOCALE)
@path = path
end
@@ -14,15 +18,8 @@ module Liquid
end
alias_method :t, :translate
class << self
def translate(name, vars = {})
@@global.translate(name, vars)
end
alias_method :t, :translate
def global=(translator)
@@global = translator
end
def locale
@locale ||= YAML.load_file(@path)
end
private
@@ -37,9 +34,5 @@ module Liquid
level[cur] or raise TranslationError, translate("errors.i18n.unknown_translation", :name => name)
end
end
def locale
@locale ||= YAML.load_file(@path)
end
end
end