lib/alephant/renderer/engines/mustache.rb in alephant-renderer-0.0.5 vs lib/alephant/renderer/engines/mustache.rb in alephant-renderer-0.0.6
- old
+ new
@@ -1,7 +1,8 @@
require 'alephant/logger'
require 'mustache'
+require 'i18n'
module Alephant
module Renderer
class Mustache
include ::Alephant::Logger
@@ -11,10 +12,12 @@
def initialize(template_file, base_path, model)
@template_file = template_file
@base_path = base_path
@model = model
+ load_translations_from base_path
+
logger.info("Renderer.initialize: end with @base_path set to #{@base_path}")
end
def render
logger.info("Renderer.render: rendered template #{template_file}")
@@ -29,9 +32,31 @@
File.open(template_location).read
rescue Exception => e
logger.error("Renderer.template: view template #{template_file} not found")
end
end
+
+ private
+
+ def load_translations_from(base_path)
+ if I18n.load_path.empty?
+ I18n.config.enforce_available_locales = false
+ I18n.load_path << i18n_load_path_from(base_path)
+ I18n.backend.load_translations
+ end
+ end
+
+ def i18n_load_path_from(base_path)
+ Dir[
+ File.join(
+ Pathname.new(base_path).parent,
+ 'locale',
+ '*.yml')
+ ]
+ .flatten
+ .uniq
+ end
+
end
end
end