gettext-i18n-rails-0.9.4/0000755000175000017500000000000012151134620014414 5ustar ondrejondrejgettext-i18n-rails-0.9.4/spec/0000755000175000017500000000000012151134620015346 5ustar ondrejondrejgettext-i18n-rails-0.9.4/spec/spec_helper.rb0000644000175000017500000000345612151134620020174 0ustar ondrejondrejrequire 'rubygems' $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__)) require 'tempfile' require 'active_support' require 'active_record' require 'action_controller' require 'action_mailer' require 'fast_gettext' require 'gettext_i18n_rails' require 'temple' begin Gem.all_load_paths rescue puts "Fixing Gem.all_load_paths" module Gem;def self.all_load_paths;[];end;end end # make temple not blow up in rails 2 env class << Temple::Templates alias_method :method_missing_old, :method_missing def method_missing(name, engine, options = {}) name == :Rails || method_missing_old(name, engine, options) end end module Rails def self.root File.dirname(__FILE__) end module VERSION MAJOR = 3 MINOR = 1 PATCH = 0 STRING = "#{MAJOR}.#{MINOR}.#{PATCH}" end end def with_file(content) Tempfile.open('gettext_i18n_rails_specs') do |f| f.write(content) f.close yield f.path end end ActiveRecord::Base.establish_connection( :adapter => "sqlite3", :database => ":memory:" ) ActiveRecord::Schema.define(:version => 1) do create_table :car_seats, :force=>true do |t| t.string :seat_color end create_table :parts, :force=>true do |t| t.string :name t.references :car_seat end create_table :not_at_all_conventionals, :force=>true do |t| t.string :name end end class CarSeat < ActiveRecord::Base validates_presence_of :seat_color, :message=>"translate me" has_many :parts accepts_nested_attributes_for :parts end class Part < ActiveRecord::Base belongs_to :car_seat end class NotConventional < ActiveRecord::Base if ActiveRecord::VERSION::MAJOR == 3 self.table_name = :not_at_all_conventionals else set_table_name :not_at_all_conventionals end end class Idea < ActiveRecord::Base self.abstract_class = true end gettext-i18n-rails-0.9.4/spec/gettext_i18n_rails_spec.rb0000644000175000017500000000473312151134620022431 0ustar ondrejondrejrequire "spec_helper" FastGettext.silence_errors describe GettextI18nRails do before do GettextI18nRails.translations_are_html_safe = nil end it "extends all classes with fast_gettext" do _('test') end describe 'translations_are_html_safe' do before do GettextI18nRails.translations_are_html_safe = nil end it "makes translations not html_safe by default" do _('x').html_safe?.should == false s_('x').html_safe?.should == false n_('x','y',2).html_safe?.should == false String._('x').html_safe?.should == false String.s_('x').html_safe?.should == false String.n_('x','y',2).html_safe?.should == false end it "makes instance translations html_safe when wanted" do GettextI18nRails.translations_are_html_safe = true _('x').html_safe?.should == true s_('x').html_safe?.should == true n_('x','y',2).html_safe?.should == true end it "makes class translations html_safe when wanted" do GettextI18nRails.translations_are_html_safe = true String._('x').html_safe?.should == true String.s_('x').html_safe?.should == true String.n_('x','y',2).html_safe?.should == true end it "does not make everything html_safe" do 'x'.html_safe?.should == false end end it "sets up out backend" do I18n.backend.is_a?(GettextI18nRails::Backend).should be_true end it "has a VERSION" do GettextI18nRails::VERSION.should =~ /^\d+\.\d+\.\d+$/ end describe 'FastGettext I18n interaction' do before do FastGettext.available_locales = nil FastGettext.locale = 'de' end it "links FastGettext with I18n locale" do FastGettext.locale = 'xx' I18n.locale.should == :xx end it "does not set an not-accepted locale to I18n.locale" do FastGettext.available_locales = ['de'] FastGettext.locale = 'xx' I18n.locale.should == :de end it "links I18n.locale and FastGettext.locale" do I18n.locale = :yy FastGettext.locale.should == 'yy' end it "does not set a non-available locale though I18n.locale" do FastGettext.available_locales = ['de'] I18n.locale = :xx FastGettext.locale.should == 'de' I18n.locale.should == :de end it "converts gettext to i18n style for nested locales" do FastGettext.available_locales = ['de_CH'] I18n.locale = :"de-CH" FastGettext.locale.should == 'de_CH' I18n.locale.should == :"de-CH" end end end gettext-i18n-rails-0.9.4/spec/gettext_i18n_rails/0000755000175000017500000000000012151134620021063 5ustar ondrejondrejgettext-i18n-rails-0.9.4/spec/gettext_i18n_rails/active_record_spec.rb0000644000175000017500000000411512151134620025234 0ustar ondrejondrej# coding: utf-8 require "spec_helper" describe ActiveRecord::Base do before do FastGettext.current_cache = {} end describe :human_name do it "is translated through FastGettext" do CarSeat.should_receive(:_).with('Car seat').and_return('Autositz') CarSeat.human_name.should == 'Autositz' end end describe :human_attribute_name do it "translates attributes through FastGettext" do CarSeat.should_receive(:s_).with('CarSeat|Seat color').and_return('Sitz farbe') CarSeat.human_attribute_name(:seat_color).should == 'Sitz farbe' end it "translates nested attributes through FastGettext" do CarSeat.should_receive(:s_).with('CarSeat|Parts|Name').and_return('Handle') CarSeat.human_attribute_name(:"parts.name").should == 'Handle' end end describe :gettext_translation_for_attribute_name do it "translates foreign keys to model name keys" do Part.gettext_translation_for_attribute_name(:car_seat_id).should == 'Car seat' end end describe 'error messages' do let(:model){ c = CarSeat.new c.valid? c } it "translates error messages" do FastGettext.stub!(:current_repository).and_return('translate me'=>"Übersetz mich!") FastGettext._('translate me').should == "Übersetz mich!" model.errors.full_messages.should == ["Seat color Übersetz mich!"] end it "translates scoped error messages" do pending 'scope is no longer added in 3.x' if ActiveRecord::VERSION::MAJOR >= 3 FastGettext.stub!(:current_repository).and_return('activerecord.errors.translate me'=>"Übersetz mich!") FastGettext._('activerecord.errors.translate me').should == "Übersetz mich!" model.errors.full_messages.should == ["Seat color Übersetz mich!"] end it "translates error messages with %{fn}" do pending FastGettext.stub!(:current_repository).and_return('translate me'=>"Übersetz %{fn} mich!") FastGettext._('translate me').should == "Übersetz %{fn} mich!" model.errors[:seat_color].should == ["Übersetz car_seat mich!"] end end end gettext-i18n-rails-0.9.4/spec/gettext_i18n_rails/slim_parser_spec.rb0000644000175000017500000000165212151134620024746 0ustar ondrejondrejrequire "spec_helper" require "gettext_i18n_rails/slim_parser" describe GettextI18nRails::SlimParser do let(:parser){ GettextI18nRails::SlimParser } describe "#target?" do it "targets .slim" do parser.target?('foo/bar/xxx.slim').should == true end it "does not target anything else" do parser.target?('foo/bar/xxx.erb').should == false end end describe "#parse" do it "finds messages in slim" do with_file 'div = _("xxxx")' do |path| parser.parse(path, []).should == [ ["xxxx", "#{path}:1"] ] end end xit "can parse 1.9 syntax" do with_file 'div = _("xxxx", foo: :bar)' do |path| parser.parse(path, []).should == [ ["xxxx", "#{path}:1"] ] end end it "does not find messages in text" do with_file 'div _("xxxx")' do |path| parser.parse(path, []).should == [] end end end end gettext-i18n-rails-0.9.4/spec/gettext_i18n_rails/backend_spec.rb0000644000175000017500000000715512151134620024021 0ustar ondrejondrej# encoding: UTF-8 require "spec_helper" FastGettext.silence_errors describe GettextI18nRails::Backend do before do FastGettext.current_cache = {} end it "redirects calls to another I18n backend" do subject.backend.should_receive(:xxx).with(1,2) subject.xxx(1,2) end describe :available_locales do it "maps them to FastGettext" do FastGettext.should_receive(:available_locales).and_return [:xxx] subject.available_locales.should == [:xxx] end it "and returns an empty array when FastGettext.available_locales is nil" do FastGettext.should_receive(:available_locales).and_return nil subject.available_locales.should == [] end end describe :translate do it "uses gettext when the key is translatable" do FastGettext.should_receive(:current_repository).and_return 'xy.z.u'=>'a' subject.translate('xx','u',:scope=>['xy','z']).should == 'a' end it "interpolates options" do FastGettext.should_receive(:current_repository).and_return 'ab.c'=>'a%{a}b' subject.translate('xx','c',:scope=>['ab'], :a => 'X').should == 'aXb' end it "will not try and interpolate when there are no options given" do FastGettext.should_receive(:current_repository).and_return 'ab.d' => 'a%{a}b' subject.translate('xx', 'd', :scope=>['ab']).should == 'a%{a}b' end it "uses plural translation if count is given" do repo = {'ab.e' => 'existing'} repo.should_receive(:plural).and_return %w(single plural) repo.stub(:pluralisation_rule).and_return nil FastGettext.stub(:current_repository).and_return repo subject.translate('xx', 'ab.e', :count => 1).should == 'single' subject.translate('xx', 'ab.e', :count => 2).should == 'plural' end it "can translate with gettext using symbols" do FastGettext.should_receive(:current_repository).and_return 'xy.z.v'=>'a' subject.translate('xx',:v ,:scope=>['xy','z']).should == 'a' end it "can translate with gettext using a flat scope" do FastGettext.should_receive(:current_repository).and_return 'xy.z.x'=>'a' subject.translate('xx',:x ,:scope=>'xy.z').should == 'a' end it "passes non-gettext keys to default backend" do subject.backend.should_receive(:translate).with('xx', 'c', {}).and_return 'd' # TODO track down why this is called 3 times on 1.8 (only 1 time on 1.9) FastGettext.stub(:current_repository).and_return 'a'=>'b' subject.translate('xx', 'c', {}).should == 'd' end if RUBY_VERSION > "1.9" it "produces UTF-8 when not using FastGettext to fix weird encoding bug" do subject.backend.should_receive(:translate).with('xx', 'c', {}).and_return 'ü'.force_encoding("US-ASCII") FastGettext.should_receive(:current_repository).and_return 'a'=>'b' result = subject.translate('xx', 'c', {}) result.should == 'ü' end it "does not force_encoding on non-strings" do subject.backend.should_receive(:translate).with('xx', 'c', {}).and_return ['aa'] FastGettext.should_receive(:current_repository).and_return 'a'=>'b' result = subject.translate('xx', 'c', {}) result.should == ['aa'] end end # TODO NameError is raised <-> wtf ? xit "uses the super when the key is not translatable" do lambda{subject.translate('xx','y',:scope=>['xy','z'])}.should raise_error(I18n::MissingTranslationData) end end describe :interpolate do it "act as an identity function for an array" do translation = [:month, :day, :year] subject.send(:interpolate, translation, {}).should == translation end end end gettext-i18n-rails-0.9.4/spec/gettext_i18n_rails/active_model/0000755000175000017500000000000012151134620023516 5ustar ondrejondrejgettext-i18n-rails-0.9.4/spec/gettext_i18n_rails/active_model/name_spec.rb0000644000175000017500000000073512151134620026002 0ustar ondrejondrej# encoding: utf-8 require "spec_helper" if ActiveRecord::VERSION::MAJOR >= 3 require "gettext_i18n_rails/active_model/name" describe ActiveModel::Name do before do FastGettext.current_cache = {} end describe 'human' do it "is translated through FastGettext" do name = ActiveModel::Name.new(CarSeat) name.should_receive(:_).with('Car seat').and_return('Autositz') name.human.should == 'Autositz' end end end endgettext-i18n-rails-0.9.4/spec/gettext_i18n_rails/haml_parser_spec.rb0000644000175000017500000000227412151134620024724 0ustar ondrejondrejrequire "spec_helper" require "gettext_i18n_rails/haml_parser" describe GettextI18nRails::HamlParser do let(:parser){ GettextI18nRails::HamlParser } describe "#target?" do it "targets .haml" do parser.target?('foo/bar/xxx.haml').should == true end it "does not target anything else" do parser.target?('foo/bar/xxx.erb').should == false end end describe "#parse" do it "finds messages in haml" do with_file '= _("xxxx")' do |path| parser.parse(path, []).should == [ ["xxxx", "#{path}:1"] ] end end it "finds messages with concatenation" do with_file '= _("xxxx" + "yyyy" + "zzzz")' do |path| parser.parse(path, []).should == [ ["xxxxyyyyzzzz", "#{path}:1"] ] end end it "should parse the 1.9 if ruby_version is 1.9" do if RUBY_VERSION =~ /^1\.9/ with_file '= _("xxxx", x: 1)' do |path| parser.parse(path, []).should == [ ["xxxx", "#{path}:1"] ] end end end it "does not find messages in text" do with_file '_("xxxx")' do |path| parser.parse(path, []).should == [] end end end end gettext-i18n-rails-0.9.4/spec/gettext_i18n_rails/model_attributes_finder_spec.rb0000644000175000017500000000163112151134620027320 0ustar ondrejondrej# coding: utf-8 require "spec_helper" require "gettext_i18n_rails/model_attributes_finder" if Rails::VERSION::MAJOR > 2 module Test class Application < Rails::Application end end end describe GettextI18nRails::ModelAttributesFinder do let(:finder) { GettextI18nRails::ModelAttributesFinder.new } before do Rails.application rescue nil end describe :find do it "returns all AR models" do keys = finder.find({}).keys if Rails::VERSION::MAJOR > 2 keys.should == [CarSeat, NotConventional, Part] else keys.should == [CarSeat, Part] end end it "returns all columns for each model" do attributes = finder.find({}) attributes[CarSeat].should == ['id', 'seat_color'] attributes[NotConventional].should == ['id', 'name'] if Rails::VERSION::MAJOR > 2 attributes[Part].should == ['car_seat_id', 'id', 'name'] end end end gettext-i18n-rails-0.9.4/spec/gettext_i18n_rails/action_controller_spec.rb0000644000175000017500000000245412151134620026147 0ustar ondrejondrejrequire "spec_helper" FastGettext.silence_errors describe ActionController::Base do def reset! fake_session = {} @c.stub!(:session).and_return fake_session fake_cookies = {} @c.stub!(:cookies).and_return fake_cookies @c.params = {} @c.request = stub(:env => {}) end before do #controller @c = ActionController::Base.new reset! #locale FastGettext.available_locales = nil FastGettext.locale = I18n.default_locale = 'fr' FastGettext.available_locales = ['fr','en'] end it "changes the locale" do @c.params = {:locale=>'en'} @c.set_gettext_locale @c.session[:locale].should == 'en' FastGettext.locale.should == 'en' end it "stays with default locale when none was found" do @c.set_gettext_locale @c.session[:locale].should == 'fr' FastGettext.locale.should == 'fr' end it "locale isn't cached over request" do @c.params = {:locale=>'en'} @c.set_gettext_locale @c.session[:locale].should == 'en' reset! @c.set_gettext_locale @c.session[:locale].should == 'fr' end it "reads the locale from the HTTP_ACCEPT_LANGUAGE" do @c.request.stub!(:env).and_return 'HTTP_ACCEPT_LANGUAGE'=>'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3' @c.set_gettext_locale FastGettext.locale.should == 'en' end end gettext-i18n-rails-0.9.4/spec/gettext_i18n_rails/string_interpolate_fix_spec.rb0000644000175000017500000000153212151134620027205 0ustar ondrejondrejrequire "spec_helper" require "gettext_i18n_rails/string_interpolate_fix" describe "String#%" do it "is not safe if it was not safe" do result = ("
%{x}" % {:x => 'a'}) result.should == '
a' result.html_safe?.should == false end xit "stays safe if it was safe" do result = ("
%{x}".html_safe % {:x => 'a'}) result.should == '
a' result.html_safe?.should == true end xit "escapes unsafe added to safe" do result = ("
%{x}".html_safe % {:x => '
'}) result.should == '
<br/>' result.html_safe?.should == true end it "does not escape unsafe if it was unsafe" do result = ("
%{x}" % {:x => '
'}) result.should == '

' result.html_safe?.should == false end it "does not break array replacement" do "%ssd" % ['a'].should == "asd" end end gettext-i18n-rails-0.9.4/Gemfile.lock0000644000175000017500000000524612151134620016645 0ustar ondrejondrejPATH remote: . specs: gettext_i18n_rails (0.9.4) fast_gettext (>= 0.4.8) GEM remote: http://rubygems.org/ specs: actionmailer (3.2.13) actionpack (= 3.2.13) mail (~> 2.5.3) actionpack (3.2.13) activemodel (= 3.2.13) activesupport (= 3.2.13) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) rack (~> 1.4.5) rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) activemodel (3.2.13) activesupport (= 3.2.13) builder (~> 3.0.0) activerecord (3.2.13) activemodel (= 3.2.13) activesupport (= 3.2.13) arel (~> 3.0.2) tzinfo (~> 0.3.29) activeresource (3.2.13) activemodel (= 3.2.13) activesupport (= 3.2.13) activesupport (3.2.13) i18n (= 0.6.1) multi_json (~> 1.0) appraisal (0.5.1) bundler rake arel (3.0.2) builder (3.0.4) bump (0.3.9) diff-lcs (1.1.3) erubis (2.7.0) fast_gettext (0.7.0) gettext (2.3.7) levenshtein locale haml (3.1.7) hike (1.2.1) i18n (0.6.1) journey (1.0.4) json (1.7.7) levenshtein (0.2.2) locale (2.0.8) mail (2.5.3) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.21) multi_json (1.7.1) polyglot (0.3.3) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) rack-ssl (1.3.3) rack rack-test (0.6.2) rack (>= 1.0) rails (3.2.13) actionmailer (= 3.2.13) actionpack (= 3.2.13) activerecord (= 3.2.13) activeresource (= 3.2.13) activesupport (= 3.2.13) bundler (~> 1.0) railties (= 3.2.13) railties (3.2.13) actionpack (= 3.2.13) activesupport (= 3.2.13) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.0.3) rdoc (3.12.2) json (~> 1.4) rspec (2.12.0) rspec-core (~> 2.12.0) rspec-expectations (~> 2.12.0) rspec-mocks (~> 2.12.0) rspec-core (2.12.2) rspec-expectations (2.12.1) diff-lcs (~> 1.1.3) rspec-mocks (2.12.1) ruby_parser (3.1.1) sexp_processor (~> 4.1) sexp_processor (4.1.3) slim (1.3.6) temple (~> 0.5.5) tilt (~> 1.3.3) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.7) temple (0.5.5) thor (0.17.0) tilt (1.3.6) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) PLATFORMS ruby DEPENDENCIES appraisal bump gettext gettext_i18n_rails! haml rails rake rspec ruby_parser (>= 3) slim sqlite3 gettext-i18n-rails-0.9.4/gemfiles/0000755000175000017500000000000012151134620016207 5ustar ondrejondrejgettext-i18n-rails-0.9.4/gemfiles/rails32.gemfile0000644000175000017500000000037112151134620021021 0ustar ondrejondrej# This file was generated by Appraisal source :rubygems gem "appraisal" gem "haml" gem "slim" gem "hamlet" gem "ruby_parser" gem "gettext", "2.3.1" gem "sqlite3", "~>1.3.6" gem "rake" gem "rspec", "~>2" gem "rails", "~>3.2.0" gemspec :path=>"../"gettext-i18n-rails-0.9.4/gemfiles/rails.3.1.gemfile0000644000175000017500000000036012151134620021152 0ustar ondrejondrej# This file was generated by Appraisal source "http://rubygems.org" gem "appraisal" gem "bump" gem "gettext" gem "haml" gem "rake" gem "ruby_parser", ">= 3" gem "rspec" gem "slim" gem "sqlite3" gem "rails", "~>3.1.0" gemspec :path=>"../"gettext-i18n-rails-0.9.4/gemfiles/rails30.gemfile.lock0000644000175000017500000000505412151134620021751 0ustar ondrejondrejPATH remote: /Users/mgrosser/code/tools/gettext_i18n_rails specs: gettext_i18n_rails (0.7.1) fast_gettext (>= 0.4.8) GEM remote: http://rubygems.org/ specs: abstract (1.0.0) actionmailer (3.0.17) actionpack (= 3.0.17) mail (~> 2.2.19) actionpack (3.0.17) activemodel (= 3.0.17) activesupport (= 3.0.17) builder (~> 2.1.2) erubis (~> 2.6.6) i18n (~> 0.5.0) rack (~> 1.2.5) rack-mount (~> 0.6.14) rack-test (~> 0.5.7) tzinfo (~> 0.3.23) activemodel (3.0.17) activesupport (= 3.0.17) builder (~> 2.1.2) i18n (~> 0.5.0) activerecord (3.0.17) activemodel (= 3.0.17) activesupport (= 3.0.17) arel (~> 2.0.10) tzinfo (~> 0.3.23) activeresource (3.0.17) activemodel (= 3.0.17) activesupport (= 3.0.17) activesupport (3.0.17) appraisal (0.5.0) bundler rake arel (2.0.10) builder (2.1.2) diff-lcs (1.1.3) erubis (2.6.6) abstract (>= 1.0.0) fast_gettext (0.6.9) gettext (2.3.1) locale haml (3.1.7) hamlet (0.5.0.1) slim (~> 1.0.0) i18n (0.5.0) json (1.7.5) locale (2.0.8) mail (2.2.19) activesupport (>= 2.3.6) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) polyglot (0.3.3) rack (1.2.5) rack-mount (0.6.14) rack (>= 1.0.0) rack-test (0.5.7) rack (>= 1.0) rails (3.0.17) actionmailer (= 3.0.17) actionpack (= 3.0.17) activerecord (= 3.0.17) activeresource (= 3.0.17) activesupport (= 3.0.17) bundler (~> 1.0) railties (= 3.0.17) railties (3.0.17) actionpack (= 3.0.17) activesupport (= 3.0.17) rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.4) rake (0.9.2.2) rdoc (3.12) json (~> 1.4) rspec (2.11.0) rspec-core (~> 2.11.0) rspec-expectations (~> 2.11.0) rspec-mocks (~> 2.11.0) rspec-core (2.11.1) rspec-expectations (2.11.3) diff-lcs (~> 1.1.3) rspec-mocks (2.11.3) ruby_parser (2.3.1) sexp_processor (~> 3.0) sexp_processor (3.2.0) slim (1.0.4) temple (~> 0.3.4) tilt (~> 1.3.2) sqlite3 (1.3.6) temple (0.3.5) thor (0.14.6) tilt (1.3.3) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.35) PLATFORMS ruby DEPENDENCIES appraisal gettext (= 2.3.1) gettext_i18n_rails! haml hamlet rails (~> 3.0.0) rake rspec (~> 2) ruby_parser slim sqlite3 (~> 1.3.6) gettext-i18n-rails-0.9.4/gemfiles/rails31.gemfile.lock0000644000175000017500000000534112151134620021751 0ustar ondrejondrejPATH remote: /Users/mgrosser/code/tools/gettext_i18n_rails specs: gettext_i18n_rails (0.7.1) fast_gettext (>= 0.4.8) GEM remote: http://rubygems.org/ specs: actionmailer (3.1.8) actionpack (= 3.1.8) mail (~> 2.3.3) actionpack (3.1.8) activemodel (= 3.1.8) activesupport (= 3.1.8) builder (~> 3.0.0) erubis (~> 2.7.0) i18n (~> 0.6) rack (~> 1.3.6) rack-cache (~> 1.2) rack-mount (~> 0.8.2) rack-test (~> 0.6.1) sprockets (~> 2.0.4) activemodel (3.1.8) activesupport (= 3.1.8) builder (~> 3.0.0) i18n (~> 0.6) activerecord (3.1.8) activemodel (= 3.1.8) activesupport (= 3.1.8) arel (~> 2.2.3) tzinfo (~> 0.3.29) activeresource (3.1.8) activemodel (= 3.1.8) activesupport (= 3.1.8) activesupport (3.1.8) multi_json (>= 1.0, < 1.3) appraisal (0.5.1) bundler rake arel (2.2.3) builder (3.0.4) diff-lcs (1.1.3) erubis (2.7.0) fast_gettext (0.6.11) gettext (2.3.1) locale haml (3.1.7) hamlet (0.5.0.1) slim (~> 1.0.0) hike (1.2.1) i18n (0.6.1) json (1.7.5) locale (2.0.8) mail (2.3.3) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) multi_json (1.2.0) polyglot (0.3.3) rack (1.3.6) rack-cache (1.2) rack (>= 0.4) rack-mount (0.8.3) rack (>= 1.0.0) rack-ssl (1.3.2) rack rack-test (0.6.2) rack (>= 1.0) rails (3.1.8) actionmailer (= 3.1.8) actionpack (= 3.1.8) activerecord (= 3.1.8) activeresource (= 3.1.8) activesupport (= 3.1.8) bundler (~> 1.0) railties (= 3.1.8) railties (3.1.8) actionpack (= 3.1.8) activesupport (= 3.1.8) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.6) rake (0.9.2.2) rdoc (3.12) json (~> 1.4) rspec (2.11.0) rspec-core (~> 2.11.0) rspec-expectations (~> 2.11.0) rspec-mocks (~> 2.11.0) rspec-core (2.11.1) rspec-expectations (2.11.3) diff-lcs (~> 1.1.3) rspec-mocks (2.11.3) ruby_parser (3.0.1) sexp_processor (~> 4.1) sexp_processor (4.1.2) slim (1.0.4) temple (~> 0.3.4) tilt (~> 1.3.2) sprockets (2.0.4) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.6) temple (0.3.5) thor (0.14.6) tilt (1.3.3) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.35) PLATFORMS ruby DEPENDENCIES appraisal gettext (= 2.3.1) gettext_i18n_rails! haml hamlet rails (~> 3.1.0) rake rspec (~> 2) ruby_parser slim sqlite3 (~> 1.3.6) gettext-i18n-rails-0.9.4/gemfiles/rails31.gemfile0000644000175000017500000000037112151134620021020 0ustar ondrejondrej# This file was generated by Appraisal source :rubygems gem "appraisal" gem "haml" gem "slim" gem "hamlet" gem "ruby_parser" gem "gettext", "2.3.1" gem "sqlite3", "~>1.3.6" gem "rake" gem "rspec", "~>2" gem "rails", "~>3.1.0" gemspec :path=>"../"gettext-i18n-rails-0.9.4/gemfiles/rails.2.3.gemfile.lock0000644000175000017500000000271212151134620022105 0ustar ondrejondrejPATH remote: /Users/mgrosser/code/tools/gettext_i18n_rails specs: gettext_i18n_rails (0.9.2) fast_gettext (>= 0.4.8) GEM remote: http://rubygems.org/ specs: actionmailer (2.3.14) actionpack (= 2.3.14) actionpack (2.3.14) activesupport (= 2.3.14) rack (~> 1.1.0) activerecord (2.3.14) activesupport (= 2.3.14) activeresource (2.3.14) activesupport (= 2.3.14) activesupport (2.3.14) appraisal (0.5.1) bundler rake bump (0.3.9) diff-lcs (1.1.3) fast_gettext (0.7.0) gettext (2.3.7) levenshtein locale haml (3.1.7) levenshtein (0.2.2) locale (2.0.8) rack (1.1.3) rails (2.3.14) actionmailer (= 2.3.14) actionpack (= 2.3.14) activerecord (= 2.3.14) activeresource (= 2.3.14) activesupport (= 2.3.14) rake (>= 0.8.3) rake (10.0.3) rspec (2.12.0) rspec-core (~> 2.12.0) rspec-expectations (~> 2.12.0) rspec-mocks (~> 2.12.0) rspec-core (2.12.2) rspec-expectations (2.12.1) diff-lcs (~> 1.1.3) rspec-mocks (2.12.1) ruby_parser (3.1.1) sexp_processor (~> 4.1) sexp_processor (4.1.3) slim (1.3.6) temple (~> 0.5.5) tilt (~> 1.3.3) sqlite3 (1.3.7) temple (0.5.5) tilt (1.3.3) PLATFORMS ruby DEPENDENCIES appraisal bump gettext gettext_i18n_rails! haml rails (~> 2.3.0) rake rspec ruby_parser (>= 3) slim sqlite3 gettext-i18n-rails-0.9.4/gemfiles/rails23.gemfile0000644000175000017500000000037112151134620021021 0ustar ondrejondrej# This file was generated by Appraisal source :rubygems gem "appraisal" gem "haml" gem "slim" gem "hamlet" gem "ruby_parser" gem "gettext", "2.3.1" gem "sqlite3", "~>1.3.6" gem "rake" gem "rspec", "~>2" gem "rails", "~>2.3.0" gemspec :path=>"../"gettext-i18n-rails-0.9.4/gemfiles/rails.3.0.gemfile0000644000175000017500000000036012151134620021151 0ustar ondrejondrej# This file was generated by Appraisal source "http://rubygems.org" gem "appraisal" gem "bump" gem "gettext" gem "haml" gem "rake" gem "ruby_parser", ">= 3" gem "rspec" gem "slim" gem "sqlite3" gem "rails", "~>3.0.0" gemspec :path=>"../"gettext-i18n-rails-0.9.4/gemfiles/rails.2.3.gemfile0000644000175000017500000000036012151134620021153 0ustar ondrejondrej# This file was generated by Appraisal source "http://rubygems.org" gem "appraisal" gem "bump" gem "gettext" gem "haml" gem "rake" gem "ruby_parser", ">= 3" gem "rspec" gem "slim" gem "sqlite3" gem "rails", "~>2.3.0" gemspec :path=>"../"gettext-i18n-rails-0.9.4/gemfiles/rails.3.2.gemfile0000644000175000017500000000036012151134620021153 0ustar ondrejondrej# This file was generated by Appraisal source "http://rubygems.org" gem "appraisal" gem "bump" gem "gettext" gem "haml" gem "rake" gem "ruby_parser", ">= 3" gem "rspec" gem "slim" gem "sqlite3" gem "rails", "~>3.2.0" gemspec :path=>"../"gettext-i18n-rails-0.9.4/gemfiles/rails.3.0.gemfile.lock0000644000175000017500000000504412151134620022104 0ustar ondrejondrejPATH remote: /Users/mgrosser/code/tools/gettext_i18n_rails specs: gettext_i18n_rails (0.9.2) fast_gettext (>= 0.4.8) GEM remote: http://rubygems.org/ specs: abstract (1.0.0) actionmailer (3.0.17) actionpack (= 3.0.17) mail (~> 2.2.19) actionpack (3.0.17) activemodel (= 3.0.17) activesupport (= 3.0.17) builder (~> 2.1.2) erubis (~> 2.6.6) i18n (~> 0.5.0) rack (~> 1.2.5) rack-mount (~> 0.6.14) rack-test (~> 0.5.7) tzinfo (~> 0.3.23) activemodel (3.0.17) activesupport (= 3.0.17) builder (~> 2.1.2) i18n (~> 0.5.0) activerecord (3.0.17) activemodel (= 3.0.17) activesupport (= 3.0.17) arel (~> 2.0.10) tzinfo (~> 0.3.23) activeresource (3.0.17) activemodel (= 3.0.17) activesupport (= 3.0.17) activesupport (3.0.17) appraisal (0.5.1) bundler rake arel (2.0.10) builder (2.1.2) bump (0.3.9) diff-lcs (1.1.3) erubis (2.6.6) abstract (>= 1.0.0) fast_gettext (0.7.0) gettext (2.3.7) levenshtein locale haml (3.1.7) i18n (0.5.0) json (1.7.6) levenshtein (0.2.2) locale (2.0.8) mail (2.2.19) activesupport (>= 2.3.6) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) polyglot (0.3.3) rack (1.2.5) rack-mount (0.6.14) rack (>= 1.0.0) rack-test (0.5.7) rack (>= 1.0) rails (3.0.17) actionmailer (= 3.0.17) actionpack (= 3.0.17) activerecord (= 3.0.17) activeresource (= 3.0.17) activesupport (= 3.0.17) bundler (~> 1.0) railties (= 3.0.17) railties (3.0.17) actionpack (= 3.0.17) activesupport (= 3.0.17) rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.4) rake (10.0.3) rdoc (3.12) json (~> 1.4) rspec (2.12.0) rspec-core (~> 2.12.0) rspec-expectations (~> 2.12.0) rspec-mocks (~> 2.12.0) rspec-core (2.12.2) rspec-expectations (2.12.1) diff-lcs (~> 1.1.3) rspec-mocks (2.12.1) ruby_parser (3.1.1) sexp_processor (~> 4.1) sexp_processor (4.1.3) slim (1.3.6) temple (~> 0.5.5) tilt (~> 1.3.3) sqlite3 (1.3.7) temple (0.5.5) thor (0.14.6) tilt (1.3.3) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.35) PLATFORMS ruby DEPENDENCIES appraisal bump gettext gettext_i18n_rails! haml rails (~> 3.0.0) rake rspec ruby_parser (>= 3) slim sqlite3 gettext-i18n-rails-0.9.4/gemfiles/rails.3.1.gemfile.lock0000644000175000017500000000533012151134620022103 0ustar ondrejondrejPATH remote: /Users/mgrosser/code/tools/gettext_i18n_rails specs: gettext_i18n_rails (0.9.2) fast_gettext (>= 0.4.8) GEM remote: http://rubygems.org/ specs: actionmailer (3.1.8) actionpack (= 3.1.8) mail (~> 2.3.3) actionpack (3.1.8) activemodel (= 3.1.8) activesupport (= 3.1.8) builder (~> 3.0.0) erubis (~> 2.7.0) i18n (~> 0.6) rack (~> 1.3.6) rack-cache (~> 1.2) rack-mount (~> 0.8.2) rack-test (~> 0.6.1) sprockets (~> 2.0.4) activemodel (3.1.8) activesupport (= 3.1.8) builder (~> 3.0.0) i18n (~> 0.6) activerecord (3.1.8) activemodel (= 3.1.8) activesupport (= 3.1.8) arel (~> 2.2.3) tzinfo (~> 0.3.29) activeresource (3.1.8) activemodel (= 3.1.8) activesupport (= 3.1.8) activesupport (3.1.8) multi_json (>= 1.0, < 1.3) appraisal (0.5.1) bundler rake arel (2.2.3) builder (3.0.4) bump (0.3.9) diff-lcs (1.1.3) erubis (2.7.0) fast_gettext (0.7.0) gettext (2.3.7) levenshtein locale haml (3.1.7) hike (1.2.1) i18n (0.6.1) json (1.7.6) levenshtein (0.2.2) locale (2.0.8) mail (2.3.3) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) multi_json (1.2.0) polyglot (0.3.3) rack (1.3.6) rack-cache (1.2) rack (>= 0.4) rack-mount (0.8.3) rack (>= 1.0.0) rack-ssl (1.3.2) rack rack-test (0.6.2) rack (>= 1.0) rails (3.1.8) actionmailer (= 3.1.8) actionpack (= 3.1.8) activerecord (= 3.1.8) activeresource (= 3.1.8) activesupport (= 3.1.8) bundler (~> 1.0) railties (= 3.1.8) railties (3.1.8) actionpack (= 3.1.8) activesupport (= 3.1.8) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.6) rake (10.0.3) rdoc (3.12) json (~> 1.4) rspec (2.12.0) rspec-core (~> 2.12.0) rspec-expectations (~> 2.12.0) rspec-mocks (~> 2.12.0) rspec-core (2.12.2) rspec-expectations (2.12.1) diff-lcs (~> 1.1.3) rspec-mocks (2.12.1) ruby_parser (3.1.1) sexp_processor (~> 4.1) sexp_processor (4.1.3) slim (1.3.6) temple (~> 0.5.5) tilt (~> 1.3.3) sprockets (2.0.4) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.7) temple (0.5.5) thor (0.14.6) tilt (1.3.3) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.35) PLATFORMS ruby DEPENDENCIES appraisal bump gettext gettext_i18n_rails! haml rails (~> 3.1.0) rake rspec ruby_parser (>= 3) slim sqlite3 gettext-i18n-rails-0.9.4/gemfiles/rails23.gemfile.lock0000644000175000017500000000272212151134620021752 0ustar ondrejondrejPATH remote: /Users/mgrosser/code/tools/gettext_i18n_rails specs: gettext_i18n_rails (0.7.1) fast_gettext (>= 0.4.8) GEM remote: http://rubygems.org/ specs: actionmailer (2.3.14) actionpack (= 2.3.14) actionpack (2.3.14) activesupport (= 2.3.14) rack (~> 1.1.0) activerecord (2.3.14) activesupport (= 2.3.14) activeresource (2.3.14) activesupport (= 2.3.14) activesupport (2.3.14) appraisal (0.5.0) bundler rake diff-lcs (1.1.3) fast_gettext (0.6.9) gettext (2.3.1) locale haml (3.1.7) hamlet (0.5.0.1) slim (~> 1.0.0) locale (2.0.8) rack (1.1.3) rails (2.3.14) actionmailer (= 2.3.14) actionpack (= 2.3.14) activerecord (= 2.3.14) activeresource (= 2.3.14) activesupport (= 2.3.14) rake (>= 0.8.3) rake (0.9.2.2) rspec (2.11.0) rspec-core (~> 2.11.0) rspec-expectations (~> 2.11.0) rspec-mocks (~> 2.11.0) rspec-core (2.11.1) rspec-expectations (2.11.3) diff-lcs (~> 1.1.3) rspec-mocks (2.11.3) ruby_parser (2.3.1) sexp_processor (~> 3.0) sexp_processor (3.2.0) slim (1.0.4) temple (~> 0.3.4) tilt (~> 1.3.2) sqlite3 (1.3.6) temple (0.3.5) tilt (1.3.3) PLATFORMS ruby DEPENDENCIES appraisal gettext (= 2.3.1) gettext_i18n_rails! haml hamlet rails (~> 2.3.0) rake rspec (~> 2) ruby_parser slim sqlite3 (~> 1.3.6) gettext-i18n-rails-0.9.4/gemfiles/rails30.gemfile0000644000175000017500000000037112151134620021017 0ustar ondrejondrej# This file was generated by Appraisal source :rubygems gem "appraisal" gem "haml" gem "slim" gem "hamlet" gem "ruby_parser" gem "gettext", "2.3.1" gem "sqlite3", "~>1.3.6" gem "rake" gem "rspec", "~>2" gem "rails", "~>3.0.0" gemspec :path=>"../"gettext-i18n-rails-0.9.4/gemfiles/rails.3.2.gemfile.lock0000644000175000017500000000533212151134620022106 0ustar ondrejondrejPATH remote: /Users/mgrosser/code/tools/gettext_i18n_rails specs: gettext_i18n_rails (0.9.2) fast_gettext (>= 0.4.8) GEM remote: http://rubygems.org/ specs: actionmailer (3.2.11) actionpack (= 3.2.11) mail (~> 2.4.4) actionpack (3.2.11) activemodel (= 3.2.11) activesupport (= 3.2.11) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) rack (~> 1.4.0) rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) activemodel (3.2.11) activesupport (= 3.2.11) builder (~> 3.0.0) activerecord (3.2.11) activemodel (= 3.2.11) activesupport (= 3.2.11) arel (~> 3.0.2) tzinfo (~> 0.3.29) activeresource (3.2.11) activemodel (= 3.2.11) activesupport (= 3.2.11) activesupport (3.2.11) i18n (~> 0.6) multi_json (~> 1.0) appraisal (0.5.1) bundler rake arel (3.0.2) builder (3.0.4) bump (0.3.9) diff-lcs (1.1.3) erubis (2.7.0) fast_gettext (0.7.0) gettext (2.3.7) levenshtein locale haml (3.1.7) hike (1.2.1) i18n (0.6.1) journey (1.0.4) json (1.7.6) levenshtein (0.2.2) locale (2.0.8) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) multi_json (1.5.0) polyglot (0.3.3) rack (1.4.4) rack-cache (1.2) rack (>= 0.4) rack-ssl (1.3.2) rack rack-test (0.6.2) rack (>= 1.0) rails (3.2.11) actionmailer (= 3.2.11) actionpack (= 3.2.11) activerecord (= 3.2.11) activeresource (= 3.2.11) activesupport (= 3.2.11) bundler (~> 1.0) railties (= 3.2.11) railties (3.2.11) actionpack (= 3.2.11) activesupport (= 3.2.11) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.0.3) rdoc (3.12) json (~> 1.4) rspec (2.12.0) rspec-core (~> 2.12.0) rspec-expectations (~> 2.12.0) rspec-mocks (~> 2.12.0) rspec-core (2.12.2) rspec-expectations (2.12.1) diff-lcs (~> 1.1.3) rspec-mocks (2.12.1) ruby_parser (3.1.1) sexp_processor (~> 4.1) sexp_processor (4.1.3) slim (1.3.6) temple (~> 0.5.5) tilt (~> 1.3.3) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.7) temple (0.5.5) thor (0.16.0) tilt (1.3.3) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.35) PLATFORMS ruby DEPENDENCIES appraisal bump gettext gettext_i18n_rails! haml rails (~> 3.2.0) rake rspec ruby_parser (>= 3) slim sqlite3 gettext-i18n-rails-0.9.4/gemfiles/rails32.gemfile.lock0000644000175000017500000000526112151134620021753 0ustar ondrejondrejPATH remote: /Users/mgrosser/code/tools/gettext_i18n_rails specs: gettext_i18n_rails (0.7.1) fast_gettext (>= 0.4.8) GEM remote: http://rubygems.org/ specs: actionmailer (3.2.8) actionpack (= 3.2.8) mail (~> 2.4.4) actionpack (3.2.8) activemodel (= 3.2.8) activesupport (= 3.2.8) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) rack (~> 1.4.0) rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.1.3) activemodel (3.2.8) activesupport (= 3.2.8) builder (~> 3.0.0) activerecord (3.2.8) activemodel (= 3.2.8) activesupport (= 3.2.8) arel (~> 3.0.2) tzinfo (~> 0.3.29) activeresource (3.2.8) activemodel (= 3.2.8) activesupport (= 3.2.8) activesupport (3.2.8) i18n (~> 0.6) multi_json (~> 1.0) appraisal (0.5.1) bundler rake arel (3.0.2) builder (3.0.4) diff-lcs (1.1.3) erubis (2.7.0) fast_gettext (0.6.11) gettext (2.3.1) locale haml (3.1.7) hamlet (0.5.0.1) slim (~> 1.0.0) hike (1.2.1) i18n (0.6.1) journey (1.0.4) json (1.7.5) locale (2.0.8) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) multi_json (1.3.7) polyglot (0.3.3) rack (1.4.1) rack-cache (1.2) rack (>= 0.4) rack-ssl (1.3.2) rack rack-test (0.6.2) rack (>= 1.0) rails (3.2.8) actionmailer (= 3.2.8) actionpack (= 3.2.8) activerecord (= 3.2.8) activeresource (= 3.2.8) activesupport (= 3.2.8) bundler (~> 1.0) railties (= 3.2.8) railties (3.2.8) actionpack (= 3.2.8) activesupport (= 3.2.8) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (0.9.2.2) rdoc (3.12) json (~> 1.4) rspec (2.11.0) rspec-core (~> 2.11.0) rspec-expectations (~> 2.11.0) rspec-mocks (~> 2.11.0) rspec-core (2.11.1) rspec-expectations (2.11.3) diff-lcs (~> 1.1.3) rspec-mocks (2.11.3) ruby_parser (3.0.1) sexp_processor (~> 4.1) sexp_processor (4.1.2) slim (1.0.4) temple (~> 0.3.4) tilt (~> 1.3.2) sprockets (2.1.3) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.6) temple (0.3.5) thor (0.16.0) tilt (1.3.3) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.35) PLATFORMS ruby DEPENDENCIES appraisal gettext (= 2.3.1) gettext_i18n_rails! haml hamlet rails (~> 3.2.0) rake rspec (~> 2) ruby_parser slim sqlite3 (~> 1.3.6) gettext-i18n-rails-0.9.4/.travis.yml0000644000175000017500000000004112151134620016520 0ustar ondrejondrejrvm: - ree - 1.9.3 - 2.0.0 gettext-i18n-rails-0.9.4/Appraisals0000644000175000017500000000027012151134620016435 0ustar ondrejondrejversions = ['3.0', '3.1', '3.2'] versions.unshift '2.3' if RUBY_VERSION =~ /^1/ versions.each do |version| appraise "rails.#{version}" do gem "rails", "~>#{version}.0" end end gettext-i18n-rails-0.9.4/gettext_i18n_rails.gemspec0000644000175000017500000000071512151134620021501 0ustar ondrejondrej$LOAD_PATH.unshift File.expand_path("../lib", __FILE__) name = "gettext_i18n_rails" require "#{name}/version" Gem::Specification.new name, GettextI18nRails::VERSION do |s| s.summary = "Simple FastGettext Rails integration." s.authors = ["Michael Grosser"] s.email = "michael@grosser.it" s.homepage = "http://github.com/grosser/#{name}" s.files = `git ls-files`.split("\n") s.license = "MIT" s.add_runtime_dependency "fast_gettext", ">=0.4.8" end gettext-i18n-rails-0.9.4/Gemfile0000644000175000017500000000026012151134620015705 0ustar ondrejondrejsource 'http://rubygems.org' gemspec gem 'appraisal' gem 'bump' gem 'gettext' gem 'haml' gem 'rails' gem 'rake' gem 'ruby_parser', '>= 3' gem 'rspec' gem 'slim' gem 'sqlite3' gettext-i18n-rails-0.9.4/Readme.md0000644000175000017500000002154712151134620016144 0ustar ondrejondrej[FastGettext](http://github.com/grosser/fast_gettext) / Rails integration. Translate via FastGettext, use any other I18n backend as extension/fallback. Rails does: `I18n.t('syntax.with.lots.of.dots')` with nested yml files We do: `_('Just translate my damn text!')` with simple, flat mo/po/yml files or directly from db To use I18n calls add a `syntax.with.lots.of.dots` translation. [See it working in the example application.](https://github.com/grosser/gettext_i18n_rails_example) Setup ===== ### Installation #### Rails 3 ##### As plugin: rails plugin install git://github.com/grosser/gettext_i18n_rails.git # Gemfile gem 'fast_gettext', '>=0.4.8' ##### As gem: # Gemfile gem 'gettext_i18n_rails' ##### Optional: Add `gettext` if you want to find translations or build .mo files
Add `ruby_parser` if you want to find translations inside haml/slim files # Gemfile gem 'gettext', '>=1.9.3', :require => false, :group => :development gem 'ruby_parser', :require => false, :group => :development #### Rails 2 ##### As plugin: script/plugin install git://github.com/grosser/gettext_i18n_rails.git sudo gem install fast_gettext # config/environment.rb config.gem "fast_gettext", :version => '>=0.4.8' ##### As gem: gem install gettext_i18n_rails # config/environment.rb config.gem 'gettext_i18n_rails' #Rakefile begin require "gettext_i18n_rails/tasks" rescue LoadError puts "gettext_i18n_rails is not installed, you probably should run 'rake gems:install' or 'bundle install'." end ##### Optional: If you want to find translations or build .mo files # config/environments/development.rb config.gem "gettext", :version => '>=1.9.3', :lib => false ### Locales & initialisation Copy default locales with dates/sentence-connectors/AR-errors you want from e.g. [rails i18n](http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/) into 'config/locales' To initialize: # config/initializers/fast_gettext.rb FastGettext.add_text_domain 'app', :path => 'locale', :type => :po FastGettext.default_available_locales = ['en','de'] #all you want to allow FastGettext.default_text_domain = 'app' And in your application: # app/controllers/application_controller.rb class ApplicationController < ... before_filter :set_gettext_locale Translating =========== Performance is almost the same for all backends since translations are cached after first use. ### Option A: .po files FastGettext.add_text_domain 'app', :path => 'locale', :type => :po - use some _('translations') - run `rake gettext:find`, to let GetText find all translations used - (optional) run `rake gettext:store_model_attributes`, to parse the database for columns that can be translated - if this is your first translation: `cp locale/app.pot locale/de/app.po` for every locale you want to use - translate messages in 'locale/de/app.po' (leave msgstr blank and msgstr == msgid) New translations will be marked "fuzzy", search for this and remove it, so that they will be used. Obsolete translations are marked with ~#, they usually can be removed since they are no longer needed #### Unfound translations with rake gettext:find Dynamic translations like `_("x"+"u")` cannot be fond. You have 4 options: - add `N_('xu')` somewhere else in the code, so the parser sees it - add `N_('xu')` in a totally separate file like `locale/unfound_translations.rb`, so the parser sees it - use the [gettext_test_log rails plugin ](http://github.com/grosser/gettext_test_log) to find all translations that where used while testing - add a Logger to a translation Chain, so every unfound translations is logged ([example]((http://github.com/grosser/fast_gettext))) ### Option B: Traditional .po/.mo files FastGettext.add_text_domain 'app', :path => 'locale' - follow Option A - run `rake gettext:pack` to write binary GetText .mo files ### Option C: Database Most scalable method, all translators can work simultaneously and online. Easiest to use with the [translation database Rails engine](http://github.com/grosser/translation_db_engine). Translations can be edited under `/translation_keys` FastGettext::TranslationRepository::Db.require_models FastGettext.add_text_domain 'app', :type => :db, :model => TranslationKey I18n ==== I18n.locale <==> FastGettext.locale.to_sym I18n.locale = :de <==> FastGettext.locale = 'de' Any call to I18n that matches a gettext key will be translated through FastGettext. Namespaces ========== Car|Model means Model in namespace Car. You do not have to translate this into english "Model", if you use the namespace-aware translation s_('Car|Model') == 'Model' #when no translation was found XSS / html_safe =============== If you trust your translators and all your usages of % on translations:
# config/environment.rb GettextI18nRails.translations_are_html_safe = true String % vs html_safe is buggy (can be used for XSS on 1.8 and is always non-safe in 1.9)
My recommended fix is: `require 'gettext_i18n_rails/string_interpolate_fix'` - safe stays safe (escape added strings) - unsafe stays unsafe (do not escape added strings) ActiveRecord - error messages ============================= ActiveRecord error messages are translated through Rails::I18n, but model names and model attributes are translated through FastGettext. Therefore a validation error on a BigCar's wheels_size needs `_('big car')` and `_('BigCar|Wheels size')` to display localized. The model/attribute translations can be found through `rake gettext:store_model_attributes`, (which ignores some commonly untranslated columns like id,type,xxx_count,...). Error messages can be translated through FastGettext, if the ':message' is a translation-id or the matching Rails I18n key is translated. ####Option A: Define a translation for "I need my rating!" and use it as message. validates_inclusion_of :rating, :in=>1..5, :message=>N_('I need my rating!') ####Option B: validates_inclusion_of :rating, :in=>1..5 Make a translation for the I18n key: `activerecord.errors.models.rating.attributes.rating.inclusion` ####Option C: Add a translation to each config/locales/*.yml files en: activerecord: errors: models: rating: attributes: rating: inclusion: " -- please choose!" The [rails I18n guide](http://guides.rubyonrails.org/i18n.html) can help with Option B and C. Plurals ======= FastGettext supports pluralization n_('Apple','Apples',3) == 'Apples' Abnormal plurals like e.g. Polish that has 4 different can also be addressed, see [FastGettext Readme](http://github.com/grosser/fast_gettext) Customizing list of translatable files ====================================== When you run rake gettext:find by default the following files are going to be scanned for translations: {app,lib,config,locale}/**/*.{rb,erb,haml,slim}. If you want to specify a different list, you can redefine files_to_translate in the gettext namespace in a file like lib/tasks/gettext.rake: namespace :gettext do def files_to_translate Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml,slim,rhtml}") end end Using your translations from javascript ======================================= If want to use your .PO files on client side javascript you should have a look at the [GettextI18nRailsJs](https://github.com/nubis/gettext_i18n_rails_js) extension. [Contributors](http://github.com/grosser/gettext_i18n_rails/contributors) ====== - [ruby gettext extractor](http://github.com/retoo/ruby_gettext_extractor/tree/master) from [retoo](http://github.com/retoo) - [Paul McMahon](http://github.com/pwim) - [Duncan Mac-Vicar P](http://duncan.mac-vicar.com/blog) - [Ramihajamalala Hery](http://my.rails-royce.org) - [J. Pablo Fernández](http://pupeno.com) - [Anh Hai Trinh](http://blog.onideas.ws) - [ed0h](http://github.com/ed0h) - [Nikos Dimitrakopoulos](http://blog.nikosd.com) - [Ben Tucker](http://btucker.net/) - [Kamil Śliwak](https://github.com/cameel) - [Paul McMahon](https://github.com/pwim) - [Rainux Luo](https://github.com/rainux) - [Lucas Hills](https://github.com/2potatocakes) - [Ladislav Slezák](https://github.com/lslezak) - [Greg Weber](https://github.com/gregwebs) - [Sean Kirby](https://github.com/sskirby) - [Julien Letessier](https://github.com/mezis) - [Seb Bacon](https://github.com/sebbacon) - [Ramón Cahenzli](https://github.com/psy-q) - [rustygeldmacher](https://github.com/rustygeldmacher) - [Jeroen Knoops](https://github.com/JeroenKnoops) - [Ivan Necas](https://github.com/iNecas) - [Andrey Chernih](https://github.com/AndreyChernyh) - [Imre Farkas](https://github.com/ifarkas) [Michael Grosser](http://grosser.it)
grosser.michael@gmail.com
License: MIT
[![Build Status](https://travis-ci.org/grosser/gettext_i18n_rails.png)](https://travis-ci.org/grosser/gettext_i18n_rails) gettext-i18n-rails-0.9.4/metadata.yml0000644000175000017500000000646712151134620016734 0ustar ondrejondrej--- !ruby/object:Gem::Specification name: gettext_i18n_rails version: !ruby/object:Gem::Version version: 0.9.4 prerelease: platform: ruby authors: - Michael Grosser autorequire: bindir: bin cert_chain: [] date: 2013-04-12 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: fast_gettext requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 0.4.8 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 0.4.8 description: email: michael@grosser.it executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - .travis.yml - Appraisals - Gemfile - Gemfile.lock - Rakefile - Readme.md - gemfiles/rails.2.3.gemfile - gemfiles/rails.2.3.gemfile.lock - gemfiles/rails.3.0.gemfile - gemfiles/rails.3.0.gemfile.lock - gemfiles/rails.3.1.gemfile - gemfiles/rails.3.1.gemfile.lock - gemfiles/rails.3.2.gemfile - gemfiles/rails.3.2.gemfile.lock - gemfiles/rails23.gemfile - gemfiles/rails23.gemfile.lock - gemfiles/rails30.gemfile - gemfiles/rails30.gemfile.lock - gemfiles/rails31.gemfile - gemfiles/rails31.gemfile.lock - gemfiles/rails32.gemfile - gemfiles/rails32.gemfile.lock - gettext_i18n_rails.gemspec - init.rb - lib/gettext_i18n_rails.rb - lib/gettext_i18n_rails/action_controller.rb - lib/gettext_i18n_rails/active_model.rb - lib/gettext_i18n_rails/active_model/name.rb - lib/gettext_i18n_rails/active_model/translation.rb - lib/gettext_i18n_rails/active_record.rb - lib/gettext_i18n_rails/backend.rb - lib/gettext_i18n_rails/base_parser.rb - lib/gettext_i18n_rails/gettext_hooks.rb - lib/gettext_i18n_rails/haml_parser.rb - lib/gettext_i18n_rails/html_safe_translations.rb - lib/gettext_i18n_rails/i18n_hacks.rb - lib/gettext_i18n_rails/model_attributes_finder.rb - lib/gettext_i18n_rails/railtie.rb - lib/gettext_i18n_rails/ruby_gettext_extractor.rb - lib/gettext_i18n_rails/slim_parser.rb - lib/gettext_i18n_rails/string_interpolate_fix.rb - lib/gettext_i18n_rails/tasks.rb - lib/gettext_i18n_rails/version.rb - lib/tasks/gettext_rails_i18n.rake - spec/gettext_i18n_rails/action_controller_spec.rb - spec/gettext_i18n_rails/active_model/name_spec.rb - spec/gettext_i18n_rails/active_record_spec.rb - spec/gettext_i18n_rails/backend_spec.rb - spec/gettext_i18n_rails/haml_parser_spec.rb - spec/gettext_i18n_rails/model_attributes_finder_spec.rb - spec/gettext_i18n_rails/slim_parser_spec.rb - spec/gettext_i18n_rails/string_interpolate_fix_spec.rb - spec/gettext_i18n_rails_spec.rb - spec/spec_helper.rb homepage: http://github.com/grosser/gettext_i18n_rails licenses: - MIT post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: 3233874037614167619 required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: 3233874037614167619 requirements: [] rubyforge_project: rubygems_version: 1.8.25 signing_key: specification_version: 3 summary: Simple FastGettext Rails integration. test_files: [] gettext-i18n-rails-0.9.4/init.rb0000644000175000017500000000070112151134620015702 0ustar ondrejondrejbegin require 'config/initializers/session_store' rescue LoadError # weird bug, when run with rake rails reports error that session # store is not configured, this fixes it somewhat... end if Rails::VERSION::MAJOR > 2 require 'gettext_i18n_rails' else #requires fast_gettext to be present. #We give rails a chance to install it using rake gems:install, by loading it later. config.after_initialize { require 'gettext_i18n_rails' } endgettext-i18n-rails-0.9.4/.gitignore0000644000175000017500000000002012151134620016374 0ustar ondrejondrej.idea pkg/*.gem gettext-i18n-rails-0.9.4/lib/0000755000175000017500000000000012151134620015162 5ustar ondrejondrejgettext-i18n-rails-0.9.4/lib/tasks/0000755000175000017500000000000012151134620016307 5ustar ondrejondrejgettext-i18n-rails-0.9.4/lib/tasks/gettext_rails_i18n.rake0000644000175000017500000000011212151134620022662 0ustar ondrejondrejrequire File.join(File.dirname(__FILE__), "/../gettext_i18n_rails/tasks") gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails.rb0000644000175000017500000000204512151134620021225 0ustar ondrejondrejrequire 'gettext_i18n_rails/version' require 'gettext_i18n_rails/gettext_hooks' module GettextI18nRails end # translate from everywhere require 'fast_gettext' Object.send(:include, FastGettext::Translation) # make translations html_safe if possible and wanted if "".respond_to?(:html_safe?) require 'gettext_i18n_rails/html_safe_translations' Object.send(:include, GettextI18nRails::HtmlSafeTranslations) end # set up the backend require 'gettext_i18n_rails/backend' I18n.backend = GettextI18nRails::Backend.new # make I18n play nice with FastGettext require 'gettext_i18n_rails/i18n_hacks' # translate activerecord errors if defined? Rails::Railtie # Rails 3+ # load active_model extensions at the correct point in time require 'gettext_i18n_rails/railtie' else if defined? ActiveRecord require 'gettext_i18n_rails/active_record' elsif defined?(ActiveModel) require 'gettext_i18n_rails/active_model' end end # make bundle console work in a rails project require 'gettext_i18n_rails/action_controller' if defined?(ActionController) gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/0000755000175000017500000000000012151134620020677 5ustar ondrejondrejgettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/backend.rb0000644000175000017500000000412312151134620022613 0ustar ondrejondrejmodule GettextI18nRails #translates i18n calls to gettext calls class Backend @@translate_defaults = true cattr_accessor :translate_defaults attr_accessor :backend RUBY19 = (RUBY_VERSION > "1.9") def initialize(*args) self.backend = I18n::Backend::Simple.new(*args) end def available_locales FastGettext.available_locales || [] end def translate(locale, key, options) if gettext_key = gettext_key(key, options) translation = if options[:count] FastGettext.n_(gettext_key, options[:count]) else FastGettext._(gettext_key) end interpolate(translation, options) else result = backend.translate(locale, key, options) (RUBY19 and result.is_a?(String)) ? result.force_encoding("UTF-8") : result end end def method_missing(method, *args) backend.send(method, *args) end protected def gettext_key(key, options) flat_key = flatten_key key, options if FastGettext.key_exist?(flat_key) flat_key elsif self.class.translate_defaults [*options[:default]].each do |default| #try the scoped(more specific) key first e.g. 'activerecord.errors.my custom message' flat_key = flatten_key default, options return flat_key if FastGettext.key_exist?(flat_key) #try the short key thereafter e.g. 'my custom message' return default if FastGettext.key_exist?(default) end return nil end end def interpolate(string, values) if string.respond_to?(:%) reserved_keys = if defined?(I18n::RESERVED_KEYS) # rails 3+ I18n::RESERVED_KEYS else I18n::Backend::Base::RESERVED_KEYS end options = values.except(*reserved_keys) options.any? ? (string % options) : string else string end end def flatten_key key, options scope = [*(options[:scope] || [])] scope.empty? ? key.to_s : "#{scope*'.'}.#{key}" end end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/model_attributes_finder.rb0000644000175000017500000001055512151134620026127 0ustar ondrejondrejrequire 'rails/version' require 'rails' if Rails::VERSION::MAJOR > 2 module GettextI18nRails #write all found models/columns to a file where GetTexts ruby parser can find them def store_model_attributes(options) file = options[:to] || 'locale/model_attributes.rb' begin File.open(file,'w') do |f| f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!" ModelAttributesFinder.new.find(options).each do |model,column_names| f.puts("_('#{model.humanize_class_name}')") #all columns namespaced under the model column_names.each do |attribute| translation = model.gettext_translation_for_attribute_name(attribute) f.puts("_('#{translation}')") end end f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!" end rescue puts "[Error] Attribute extraction failed. Removing incomplete file (#{file})" File.delete(file) raise end end module_function :store_model_attributes class ModelAttributesFinder # options: # :ignore_tables => ['cars',/_settings$/,...] # :ignore_columns => ['id',/_id$/,...] # current connection ---> {'cars'=>['model_name','type'],...} def find(options) found = ActiveSupport::OrderedHash.new([]) models.each do |model| next if model.abstract_class table_name = model.table_name next if ignored?(table_name,options[:ignore_tables]) model.columns.each do |column| found[model] += [column.name] unless ignored?(column.name,options[:ignore_columns]) end found[model].sort! end found end def models if Rails::VERSION::MAJOR > 2 Rails.application.eager_load! # make sure that all models are loaded so that direct_descendants works ::ActiveRecord::Base.direct_descendants else ::ActiveRecord::Base.connection.tables.map {|t| table_name_to_namespaced_model(t) } end.compact.sort {|c1, c2| c1.name <=> c2.name} end def ignored?(name,patterns) return false unless patterns patterns.detect{|p|p.to_s==name.to_s or (p.is_a?(Regexp) and name=~p)} end private # Tries to find the model class corresponding to specified table name. # Takes into account that the model can be defined in a namespace. # Searches only up to one level deep - won't find models nested in two # or more modules. # # Note that if we allow namespaces, the conversion can be ambiguous, i.e. # if the table is named "aa_bb_cc" and AaBbCc, Aa::BbCc and AaBb::Cc are # all defined there's no absolute rule that tells us which one to use. # This method prefers the less nested one and, if there are two at # the same level, the one with shorter module name. def table_name_to_namespaced_model(table_name) # First assume that there are no namespaces model = to_class(table_name.singularize.camelcase) return model if model != nil # If you were wrong, assume that the model is in a namespace. # Iterate over the underscores and try to substitute each of them # for a slash that camelcase() replaces with the scope operator (::). underscore_position = table_name.index('_') while underscore_position != nil namespaced_table_name = table_name.dup namespaced_table_name[underscore_position] = '/' model = to_class(namespaced_table_name.singularize.camelcase) return model if model != nil underscore_position = table_name.index('_', underscore_position + 1) end # The model either is not defined or is buried more than one level # deep in a module hierarchy return nil end # Checks if there is a class of specified name and if so, returns # the class object. Otherwise returns nil. def to_class(name) # I wanted to use Module.const_defined?() here to avoid relying # on exceptions for normal program flow but it's of no use. # If class autoloading is enabled, the constant may be undefined # but turn out to be present when we actually try to use it. begin constant = name.constantize rescue NameError return nil rescue LoadError => e $stderr.puts "failed to load '#{name}', ignoring (#{e.class}: #{e.message})" return nil end return constant.is_a?(Class) ? constant : nil end end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/haml_parser.rb0000644000175000017500000000046712151134620023530 0ustar ondrejondrejrequire 'gettext_i18n_rails/base_parser' module GettextI18nRails class HamlParser < BaseParser def self.extension "haml" end def self.convert_to_code(text) Haml::Engine.new(text).precompiled() end end end GettextI18nRails::GettextHooks.add_parser GettextI18nRails::HamlParser gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/active_model.rb0000644000175000017500000000014512151134620023657 0ustar ondrejondrejrequire 'gettext_i18n_rails/active_model/name' require 'gettext_i18n_rails/active_model/translation' gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/action_controller.rb0000644000175000017500000000062012151134620024742 0ustar ondrejondrejclass ActionController::Base def set_gettext_locale requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale locale = FastGettext.set_locale(requested_locale) session[:locale] = locale I18n.locale = locale # some weird overwriting in action-controller makes this necessary ... see I18nProxy end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/tasks.rb0000644000175000017500000001022012151134620022344 0ustar ondrejondrejnamespace :gettext do def load_gettext require 'gettext' require 'gettext/utils' end desc "Create mo-files for L10n" task :pack => :environment do load_gettext GetText.create_mofiles(true, locale_path, locale_path) end desc "Update pot/po files." task :find => :environment do load_gettext $LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib') # needed when installed as plugin require "gettext_i18n_rails/haml_parser" require "gettext_i18n_rails/slim_parser" if GetText.respond_to? :update_pofiles_org if defined?(Rails.application) msgmerge = Rails.application.config.gettext_i18n_rails.msgmerge end msgmerge ||= %w[--sort-output --no-location --no-wrap] GetText.update_pofiles_org( text_domain, files_to_translate, "version 0.0.1", :po_root => locale_path, :msgmerge => msgmerge ) else #we are on a version < 2.0 puts "install new GetText with gettext:install to gain more features..." #kill ar parser... require 'gettext/parser/active_record' module GetText module ActiveRecordParser module_function def init(x);end end end #parse files.. (models are simply parsed as ruby files) GetText.update_pofiles( text_domain, files_to_translate, "version 0.0.1", locale_path ) end end # This is more of an example, ignoring # the columns/tables that mostly do not need translation. # This can also be done with GetText::ActiveRecord # but this crashed too often for me, and # IMO which column should/should-not be translated does not # belong into the model # # You can get your translations from GetText::ActiveRecord # by adding this to you gettext:find task # # require 'active_record' # gem "gettext_activerecord", '>=0.1.0' #download and install from github # require 'gettext_activerecord/parser' desc "write the model attributes to /model_attributes.rb" task :store_model_attributes => :environment do FastGettext.silence_errors require 'gettext_i18n_rails/model_attributes_finder' require 'gettext_i18n_rails/active_record' storage_file = "#{locale_path}/model_attributes.rb" puts "writing model translations to: #{storage_file}" ignore_tables = [/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions', 'delayed_jobs'] GettextI18nRails.store_model_attributes( :to => storage_file, :ignore_columns => [/_id$/, 'id', 'type', 'created_at', 'updated_at'], :ignore_tables => ignore_tables ) end desc "add a new language" task :add_language, [:language] => :environment do |_, args| language = args.language || ENV["LANGUAGE"] # Let's do some pre-verification of the environment. if language.nil? puts "You need to specify the language to add. Either 'LANGUAGE=eo rake gettext:add_languange' or 'rake gettext:add_languange[eo]'" next end pot = File.join(locale_path, "#{text_domain}.pot") if !File.exists? pot puts "You don't have a pot file yet, you probably should run 'rake gettext:find' at least once. Tried '#{pot}'." next end # Create the directory for the new language. dir = File.join(locale_path, language) puts "Creating directory #{dir}" Dir.mkdir dir # Create the po file for the new language. new_po = File.join(locale_path, language, "#{text_domain}.po") puts "Initializing #{new_po} from #{pot}." system "msginit --locale=#{language} --input=#{pot} --output=#{new_po}" end def locale_path path = FastGettext.translation_repositories[text_domain].instance_variable_get(:@options)[:path] rescue nil path || File.join(Rails.root, "locale") end def text_domain # if your textdomain is not 'app': require the environment before calling e.g. gettext:find OR add TEXTDOMAIN=my_domain ENV['TEXTDOMAIN'] || (FastGettext.text_domain rescue nil) || "app" end # do not rename, gettext_i18n_rails_js overwrites this to inject coffee + js def files_to_translate Dir.glob("{app,lib,config,#{locale_path}}/**/*.{rb,erb,haml,slim}") end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/railtie.rb0000644000175000017500000000112412151134620022653 0ustar ondrejondrejmodule GettextI18nRails class Railtie < ::Rails::Railtie config.gettext_i18n_rails = ActiveSupport::OrderedOptions.new config.gettext_i18n_rails.msgmerge = %w[--sort-output --no-location --no-wrap] config.gettext_i18n_rails.use_for_active_record_attributes = true rake_tasks do require 'gettext_i18n_rails/tasks' end config.after_initialize do |app| if app.config.gettext_i18n_rails.use_for_active_record_attributes ActiveSupport.on_load :active_record do require 'gettext_i18n_rails/active_model' end end end end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/html_safe_translations.rb0000644000175000017500000000103312151134620025764 0ustar ondrejondrejmodule GettextI18nRails mattr_accessor :translations_are_html_safe module HtmlSafeTranslations # also make available on class methods def self.included(base) base.extend self end def _(*args) html_safe_if_wanted super end def n_(*args) html_safe_if_wanted super end def s_(*args) html_safe_if_wanted super end private def html_safe_if_wanted(text) return text unless GettextI18nRails.translations_are_html_safe text.to_s.html_safe end end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/gettext_hooks.rb0000644000175000017500000000107012151134620024111 0ustar ondrejondrejmodule GettextI18nRails module GettextHooks # shoarter call / maybe the interface changes again ... def self.add_parser(parser) xgettext.add_parser(parser) end def self.xgettext @xgettext ||= begin require 'gettext/tools/xgettext' # 2.3+ GetText::Tools::XGetText rescue LoadError begin require 'gettext/tools/rgettext' # 2.0 - 2.2 GetText::RGetText rescue LoadError # # 1.x require 'gettext/rgettext' GetText::RGetText end end end end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/string_interpolate_fix.rb0000644000175000017500000000103112151134620026001 0ustar ondrejondrejneeded = "".respond_to?(:html_safe) and ( "".html_safe % {:x => '
'} == '
' or not ("".html_safe % {:x=>'a'}).html_safe? ) if needed class String alias :interpolate_without_html_safe :% def %(*args) if args.first.is_a?(Hash) and html_safe? safe_replacement = Hash[args.first.map{|k,v| [k,ERB::Util.h(v)] }] interpolate_without_html_safe(safe_replacement).html_safe else interpolate_without_html_safe(*args).dup # make sure its not html_safe end end end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/version.rb0000644000175000017500000000007212151134620022710 0ustar ondrejondrejmodule GettextI18nRails Version = VERSION = '0.9.4' end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/active_model/0000755000175000017500000000000012151134620023332 5ustar ondrejondrejgettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/active_model/name.rb0000644000175000017500000000017012151134620024575 0ustar ondrejondrejmodule ActiveModel Name.class_eval do def human(options={}) _(@klass.humanize_class_name) end end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/active_model/translation.rb0000644000175000017500000000120412151134620026212 0ustar ondrejondrejmodule ActiveModel module Translation # CarDealer.sales_count -> s_('CarDealer|Sales count') -> 'Sales count' if no translation was found def human_attribute_name(attribute, *args) s_(gettext_translation_for_attribute_name(attribute)) end def gettext_translation_for_attribute_name(attribute) attribute = attribute.to_s if attribute.ends_with?('_id') humanize_class_name(attribute) else "#{self}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}" end end def humanize_class_name(name=nil) name ||= self.to_s name.underscore.humanize end end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/active_record.rb0000644000175000017500000000043412151134620024036 0ustar ondrejondrejrequire 'gettext_i18n_rails/active_model/translation' class ActiveRecord::Base extend ActiveModel::Translation def self.human_attribute_name(*args) super(*args) end # method deprecated in Rails 3.1 def self.human_name(*args) _(self.humanize_class_name) end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/ruby_gettext_extractor.rb0000644000175000017500000000646412151134620026056 0ustar ondrejondrej# new ruby parser from retoo, that should help extracting "#{_('xxx')}", which is needed especially when parsing haml files require 'ruby_parser' module RubyGettextExtractor extend self def parse(file, targets = []) # :nodoc: content = File.read(file) parse_string(content, file, targets) end def parse_string(content, file, targets=[]) # file is just for information in error messages parser = if RUBY_VERSION =~ /^1\.8/ Extractor18.new(file, targets) else Extractor19.new(file, targets) end parser.run(content) end def target?(file) # :nodoc: return file =~ /\.rb$/ end module ExtractorMethods def initialize(filename, targets) @filename = filename @targets = Hash.new @results = [] targets.each do |a| k, v = a # things go wrong if k already exists, but this # should not happen (according to the gettext doc) @targets[k] = a @results << a end super() end def run(content) # ruby parser has an ugly bug which causes that several \000's take # ages to parse. This avoids this probelm by stripping them away (they probably wont appear in keys anyway) # See bug report: http://rubyforge.org/tracker/index.php?func=detail&aid=26898&group_id=439&atid=1778 safe_content = content.gsub(/\\\d\d\d/, '') self.parse(safe_content) return @results end def extract_string(node) if node.first == :str return node.last elsif node.first == :call type, recv, meth, args = node # node has to be in form of "string"+"other_string" return nil unless recv && meth == :+ first_part = extract_string(recv) second_part = extract_string(args) return nil unless first_part && second_part return first_part.to_s + second_part.to_s else return nil end end def extract_key(args, seperator) key = nil if args.size == 2 key = extract_string(args.value) else # this could be n_("aaa","aaa2",1) # all strings arguemnts are extracted and joined with \004 or \000 arguments = args[1..(-1)] res = [] arguments.each do |a| str = extract_string(a) # only add strings res << str if str end return nil if res.empty? key = res.join(seperator) end return nil unless key key.gsub!("\n", '\n') key.gsub!("\t", '\t') key.gsub!("\0", '\0') return key end def new_call recv, meth, args = nil # we dont care if the method is called on a a object if recv.nil? if (meth == :_ || meth == :p_ || meth == :N_ || meth == :pgettext || meth == :s_) key = extract_key(args, "\004") elsif meth == :n_ key = extract_key(args, "\000") else # skip end if key res = @targets[key] unless res res = [key] @results << res @targets[key] = res end res << "#{@filename}:#{lexer.lineno}" end end super recv, meth, args end end class Extractor18 < Ruby18Parser include ExtractorMethods end class Extractor19 < Ruby19Parser include ExtractorMethods end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/i18n_hacks.rb0000644000175000017500000000104012151134620023147 0ustar ondrejondrejI18n::Config # autoload module I18n class Config def locale FastGettext.locale.gsub("_","-").to_sym end def locale=(new_locale) FastGettext.locale=(new_locale) end end # backport I18n.with_locale if it does not exist # Executes block with given I18n.locale set. def self.with_locale(tmp_locale = nil) if tmp_locale current_locale = self.locale self.locale = tmp_locale end yield ensure self.locale = current_locale if tmp_locale end unless defined? I18n.with_locale end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/base_parser.rb0000644000175000017500000000206312151134620023513 0ustar ondrejondrejrequire 'gettext_i18n_rails/gettext_hooks' module GettextI18nRails class BaseParser def self.target?(file) File.extname(file) == ".#{extension}" end def self.parse(file, msgids = []) return msgids unless load_library code = convert_to_code(File.read(file)) RubyGettextExtractor.parse_string(code, file, msgids) rescue Racc::ParseError => e $stderr.puts "file ignored: ruby_parser cannot read #{extension} files with 1.9 syntax --- #{file}: (#{e.message.strip})" return msgids end def self.load_library return true if @library_loaded begin require "#{::Rails.root.to_s}/vendor/plugins/#{extension}/lib/#{extension}" rescue LoadError begin require extension # From gem rescue LoadError puts "A #{extension} file was found, but #{extension} library could not be found, so nothing will be parsed..." return false end end require 'gettext_i18n_rails/ruby_gettext_extractor' @library_loaded = true end end end gettext-i18n-rails-0.9.4/lib/gettext_i18n_rails/slim_parser.rb0000644000175000017500000000045612151134620023551 0ustar ondrejondrejrequire 'gettext_i18n_rails/base_parser' module GettextI18nRails class SlimParser < BaseParser def self.extension "slim" end def self.convert_to_code(text) Slim::Engine.new.call(text) end end end GettextI18nRails::GettextHooks.add_parser GettextI18nRails::SlimParser gettext-i18n-rails-0.9.4/Rakefile0000644000175000017500000000031512151134620016060 0ustar ondrejondrejrequire 'bundler/gem_tasks' require 'appraisal' require 'bump/tasks' task :spec do sh "rspec spec" end task :default do sh "bundle exec rake appraisal:install && bundle exec rake appraisal spec" end