Sha256: a2f8cfbc11b7d5179cb9e61ceb59eb5be753bff14712260db6ae96907946841a

Contents?: true

Size: 1.8 KB

Versions: 10

Compression:

Stored size: 1.8 KB

Contents

require File.expand_path('spec/spec_helper')

describe 'FastGettext::TranslationRepository::Yaml' do
  before do
    FastGettext.pluralisation_rule = nil
    @rep = FastGettext::TranslationRepository.build('test', :path => File.join('spec', 'locale', 'yaml'), :type => :yaml)
    @rep.is_a?(FastGettext::TranslationRepository::Yaml).should be_true
    FastGettext.locale = 'de'
  end

  it "can be built" do
    @rep.available_locales.sort.should == ['de', 'en']
  end

  it "translates nothing when locale is unsupported" do
    FastGettext.locale = 'xx'
    @rep['simple'].should == nil
  end

  it "does not translated categories" do
    @rep['cars'].should == nil
  end

  it "can translate simple" do
    @rep['simple'].should == 'einfach'
  end

  it "can translate nested" do
    @rep['cars.car'].should == 'Auto'
  end

  it "can pluralize" do
    @rep.plural('cars.axis').should == ['Achse', 'Achsen', nil, nil]
  end

  it "handles unfound plurals with nil" do
    @rep.plural('cars.xxx').should == [nil, nil, nil, nil]
  end

  it "can be used to translate plural forms" do
    FastGettext.stub!(:current_repository).and_return @rep
    FastGettext.n_('cars.axis','cars.axis',2).should == 'Achsen'
    FastGettext.n_('cars.axis',2).should == 'Achsen'
    FastGettext.n_('cars.axis',1).should == 'Achse'
  end

  4.times do |i|
    it "can be used to do wanky pluralisation rules #{i}" do
      FastGettext.stub!(:current_repository).and_return @rep
      @rep.stub!(:pluralisation_rule).and_return lambda{|x| i}
      FastGettext.n_('cars.silly',1).should == i.to_s # cars.silly translations are 0,1,2,3
    end
  end

  it "can use custom pluraliztion rules" do
    FastGettext.locale = 'en'
    {0 => 0, 1 => 1, 2 => 2, 3 => 0}.each do |input, expected|
      @rep.pluralisation_rule.call(input).should == expected
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
fast_gettext-0.6.6 spec/fast_gettext/translation_repository/yaml_spec.rb
fast_gettext-0.6.5 spec/fast_gettext/translation_repository/yaml_spec.rb
fast_gettext-0.6.4 spec/fast_gettext/translation_repository/yaml_spec.rb
fast_gettext-0.6.3 spec/fast_gettext/translation_repository/yaml_spec.rb
fast_gettext-0.6.2 spec/fast_gettext/translation_repository/yaml_spec.rb
fast_gettext-0.6.1 spec/fast_gettext/translation_repository/yaml_spec.rb
fast_gettext-0.6.0 spec/fast_gettext/translation_repository/yaml_spec.rb
fast_gettext-0.5.13 spec/fast_gettext/translation_repository/yaml_spec.rb
fast_gettext-0.5.12 spec/fast_gettext/translation_repository/yaml_spec.rb
fast_gettext-0.5.11 spec/fast_gettext/translation_repository/yaml_spec.rb