Sha256: 718220e9a7930c66037d6f40de58424aee0bd8eb5606b32e1cd2d21df7bde6a8

Contents?: true

Size: 1.92 KB

Versions: 25

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

describe Locomotive::Steam::Liquid::Filters::Translate do

  let(:source) { "{{ 'welcome_message' | translate }}" }

  let(:site)        { Locomotive::Steam::Site.new(_id: site_id, locales: %w(en fr nb)) }
  let(:services)    { Locomotive::Steam::Services.build_instance }
  let(:translator)  { services.translator }
  let(:assigns)     { {} }
  let(:context)     { ::Liquid::Context.new(assigns, {}, { services: services }) }

  before { services.locale = :en }

  subject { render_template(source, context) }

  context 'missing translation' do

    before { allow(translator).to receive(:translate).and_return(nil) }

    it { is_expected.to eq 'welcome_message' }

  end

  context 'existing translation' do

    before { allow(translator).to receive(:translate).and_return('Hello world') }

    it { is_expected.to eq 'Hello world' }

  end

  describe 'passing a locale and a scope' do

    before { allow(translator).to receive(:translate).and_return('Bonjour monde') }

    describe 'legacy syntax' do

      let(:source) { "{{ 'welcome_message' | translate: 'fr', 'locomotive.default' }}" }
      it { expect(translator).to receive(:translate).with('welcome_message', 'locale' => 'fr', 'scope' => 'locomotive.default'); subject }

    end

    describe 'new syntax' do

      let(:source) { "{{ 'welcome_message' | translate: locale: 'fr', scope: 'locomotive.default' }}" }
      it { expect(translator).to receive(:translate).with('welcome_message', 'locale' => 'fr', 'scope' => 'locomotive.default'); subject }

    end

  end

  describe 'pluralization' do

    let(:translation) { instance_double('Translation', values: { 'en' => '{{ name }} has {{ count }} articles' }) }
    before { expect(translator.repository).to receive(:by_key).with('post_count_two').and_return(translation) }

    let(:source) { "{{ 'post_count' | translate: count: 2, name: 'John' }}" }
    it { expect(subject).to eq('John has 2 articles') }

  end

end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
locomotivecms_steam-1.5.0.beta2 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.5.0.beta1 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.4.1 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.4.0 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.4.0.rc2 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.4.0.rc1 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.4.0.pre.rc.1 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.3.0 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.3.0.rc2 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.1.2 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.2.1 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.3.0.rc1 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.2.0 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.2.0.rc3 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.2.0.rc2 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.2.0.rc1 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.2.0.beta1 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.1.1 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.1.0 spec/integration/liquid/filters/translate_spec.rb
locomotivecms_steam-1.1.0.rc3 spec/integration/liquid/filters/translate_spec.rb