closes #56
Ivan Youroff
committed May 23, 2013
commit 2217e4d53dd157892401df81289f22eb63d8f1af
Showing 3
changed files with
16 additions
and 6 deletions
locomotive/wagon/liquid/filters/translate.rb b/lib/locomotive/wagon/liquid/filters/translate.rb
+10
-6
| @@ | @@ -4,16 +4,20 @@ module Locomotive |
| module Filters | |
| module Translate | |
| - | def translate(key, locale = nil) |
| - | translation = @context.registers[:mounting_point].translations[key.to_s] |
| + | def translate(key, locale = nil, scope = nil) |
| + | locale ||= I18n.locale.to_s |
| + | if scope.blank? |
| + | translation = @context.registers[:mounting_point].translations[key.to_s] |
| - | if translation |
| - | translation.get(locale) || translation.get(Locomotive::Mounter.locale.to_s) |
| + | if translation |
| + | translation.get(locale) || translation.get(Locomotive::Mounter.locale.to_s) |
| + | else |
| + | "[unknown translation key: #{key}]" |
| + | end |
| else | |
| - | "[unknown translation key: #{key}]" |
| + | I18n.t(key, scope: scope.split('.'), locale: locale) |
| end | |
| end | |
| - | |
| end | |
| ::Liquid::Template.register_filter(Translate) | |
spec/fixtures/default/app/views/pages/index.liquid.haml
+1
-0
| @@ | @@ -90,6 +90,7 @@ title: Home page |
| #footer | |
| #is_templatized{templatized: "{{ page.templatized? }}"} | |
| + | #scoped_translation{scoped_translation: "{{ 'fr' | translate: 'en', 'locomotive.locales' }}"} |
| %p {% locale_switcher %} | |
spec/integration/server/basic_spec.rb
+5
-0
| @@ | @@ -40,6 +40,11 @@ describe Locomotive::Wagon::Server do |
| get '/nb' | |
| last_response.body.should_not =~ /Powered by/ | |
| end | |
| + | |
| + | it 'provides translation in scopes' do |
| + | get '/' |
| + | last_response.body.should =~ /scoped_translation=.French./ |
| + | end |
| it 'returns all the pages' do | |
| get '/all' | |