lib/titlezilla/translator.rb in titlezilla-0.1.2 vs lib/titlezilla/translator.rb in titlezilla-0.1.3
- old
+ new
@@ -17,11 +17,11 @@
@title = override
end
end
def application_title
- @application_title ||= lookup('application')
+ @application_title ||= reverse_lookup('application')
end
def meta_title
[title, application_title].compact.join(::Titlezilla.configuration.separator)
end
@@ -32,15 +32,28 @@
parts = controller_path.to_s.split('/')
parts.map!(&:to_s).map!(&:freeze)
if parts.size > 1
[parts[(0...-1)], parts[-1]]
else
- [nil, parts[0].to_s.freeze]
+ [[], parts[0].to_s.freeze]
end
end
def lookup(*key)
- t_key = [:titles, namespace, key].flatten.compact.join('.')
+ lookup_with_namespace(key, namespace)
+ end
+
+ def reverse_lookup(*key)
+ title_namespace = namespace.dup
+ begin
+ title = lookup_with_namespace(key, title_namespace)
+ return title if title
+ title_namespace.pop
+ end while title_namespace.size >= 0
+ end
+
+ def lookup_with_namespace(keys, namespace)
+ t_key = [:titles, namespace, keys].flatten.compact.join('.')
i18n_set?(t_key) ? I18n.t(t_key, context) : nil
end
def map(action_name)
(::Titlezilla.configuration.action_map[action_name.to_sym] || action_name).to_s.freeze