gettext_i18n_rails 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,26 +2,17 @@ require 'spec/rake/spectask'
2
2
  Spec::Rake::SpecTask.new {|t| t.spec_opts = ['--color']}
3
3
 
4
4
  task :default do
5
- # test with 2.x
6
- puts `VERSION='~>2' rake spec RSPEC_COLOR=1`
7
-
8
- # gem 'activerecord', '>=3' did not work for me, but just require gets the right version...
9
- require 'active_record'
10
- if ActiveRecord::VERSION::MAJOR >= 3
11
- puts `rake spec RSPEC_COLOR=1`
12
- else
13
- 'install rails 3 to get full test coverage...'
14
- end
5
+ puts `rake spec VERSION=2.3.9 RSPEC_COLOR=1`
6
+ puts `rake spec VERSION=3.0.0 RSPEC_COLOR=1`
15
7
  end
16
8
 
17
9
  begin
18
10
  require 'jeweler'
19
- project_name = 'gettext_i18n_rails'
20
11
  Jeweler::Tasks.new do |gem|
21
- gem.name = project_name
12
+ gem.name = 'gettext_i18n_rails'
22
13
  gem.summary = "Simple FastGettext Rails integration."
23
14
  gem.email = "grosser.michael@gmail.com"
24
- gem.homepage = "http://github.com/grosser/#{project_name}"
15
+ gem.homepage = "http://github.com/grosser/#{gem.name}"
25
16
  gem.authors = ["Michael Grosser"]
26
17
  gem.add_dependency 'fast_gettext'
27
18
  end
data/Readme.md CHANGED
@@ -26,23 +26,21 @@ GetText 2.0 will render 1.93 unusable, so only install if you do not have apps t
26
26
  Copy default locales with dates/sentence-connectors/AR-errors you want from e.g.
27
27
  [rails i18n](http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/) into 'config/locales'
28
28
 
29
- If you are not using bundler:
30
-
31
- #config/environment.rb
32
- Rails::Initializer.run do |config|
33
- ...
34
- config.gem "fast_gettext", :version => '>=0.4.8'
35
- #only used for mo/po file generation in development, !do not load(:lib=>false), will needlessly eat ram!
36
- config.gem "gettext", :lib => false, :version => '>=1.9.3'
37
- end
29
+ Rails 2:
30
+
31
+ # config/environment.rb
32
+ config.gem "fast_gettext", :version => '>=0.4.8'
33
+
34
+ # only needed for mo/po file generation in development
35
+ config.gem "gettext", :version => '>=1.9.3', :lib => false
38
36
 
39
- If you are using bundler:
37
+ With bundler:
40
38
 
41
- #Gemfile
42
- gem "fast_gettext", '>=0.4.8'
43
- gem '>=1.9.3', "gettext", :require => false
39
+ # Gemfile
40
+ gem 'fast_gettext', '>=0.4.8'
41
+ gem 'gettext', '>=1.9.3', :require => false
44
42
 
45
- If you installed it as a gem add to your Rakefile
43
+ Installed as gem? Add to your Rakefile:
46
44
 
47
45
  #Rakefile
48
46
  begin
@@ -53,14 +51,14 @@ If you installed it as a gem add to your Rakefile
53
51
 
54
52
  To initialize:
55
53
 
56
- #config/initialisers/fast_gettext.rb
54
+ # config/initializers/fast_gettext.rb
57
55
  FastGettext.add_text_domain 'app', :path => 'locale'
58
56
  FastGettext.default_available_locales = ['en','de'] #all you want to allow
59
57
  FastGettext.default_text_domain = 'app'
60
58
 
61
59
  And in your application:
62
60
 
63
- #app/controllers/application_controller.rb
61
+ # app/controllers/application_controller.rb
64
62
  class ApplicationController < ...
65
63
  before_filter :set_gettext_locale
66
64
 
@@ -101,6 +99,13 @@ You do not have to translate this into english "Model", if you use the
101
99
  namespace-aware translation
102
100
  s_('Car|Model') == 'Model' #when no translation was found
103
101
 
102
+ XSS / html_safe
103
+ ===============
104
+ If you trust your translators and all your usages of % on translations:
105
+ (% on string is atm buggy with always staying html_safe, no matter what was replaced)
106
+ # config/environment.rb
107
+ GettextI18nRails.translations_are_html_safe = true
108
+
104
109
  ActiveRecord - error messages
105
110
  =============================
106
111
  ActiveRecord error messages are translated through Rails::I18n, but
@@ -150,6 +155,12 @@ Sometimes translations like `_("x"+"u")` cannot be fond. You have 4 options:
150
155
  - add a Logger to a translation Chain, so every unfound translations is logged ([example]((http://github.com/grosser/fast_gettext)))
151
156
 
152
157
 
158
+ TODO
159
+ =====
160
+ - add Railtie for rake tasks on Rails 3
161
+ - fix % on string to respect html_safe: `("<a>%{x}</a>".html_safe % {:x=>'<script>y</script>'})` should escape the `<script>y</script>` part)
162
+ - refactor Readme
163
+
153
164
  Contributors
154
165
  ======
155
166
  - [ruby gettext extractor](http://github.com/retoo/ruby_gettext_extractor/tree/master) from [retoo](http://github.com/retoo)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gettext_i18n_rails}
8
- s.version = "0.2.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-09-25}
12
+ s.date = %q{2010-09-27}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.files = [
15
15
  ".gitignore",
@@ -12,7 +12,7 @@ end
12
12
  # include translations into all the places it needs to go...
13
13
  Object.send(:include, FastGettext::Translation)
14
14
 
15
- # make translations html_safe if needed
15
+ # make translations html_safe if possible and wanted
16
16
  if "".respond_to?(:html_safe?)
17
17
  require 'gettext_i18n_rails/html_safe_translations'
18
18
  Object.send(:include, GettextI18nRails::HtmlSafeTranslations)
@@ -1,19 +1,29 @@
1
1
  module GettextI18nRails
2
+ mattr_accessor :translations_are_html_safe
3
+
2
4
  module HtmlSafeTranslations
5
+ # also make available on class methods
3
6
  def self.included(base)
4
7
  base.extend self
5
8
  end
6
9
 
7
10
  def _(*args)
8
- super(*args).to_s.html_safe
11
+ html_safe_if_wanted super
9
12
  end
10
13
 
11
14
  def n_(*args)
12
- super(*args).to_s.html_safe
15
+ html_safe_if_wanted super
13
16
  end
14
17
 
15
18
  def s_(*args)
16
- super(*args).to_s.html_safe
19
+ html_safe_if_wanted super
20
+ end
21
+
22
+ private
23
+
24
+ def html_safe_if_wanted(text)
25
+ return text unless GettextI18nRails.translations_are_html_safe
26
+ text.to_s.html_safe
17
27
  end
18
28
  end
19
29
  end
@@ -3,10 +3,47 @@ require File.expand_path("spec_helper", File.dirname(__FILE__))
3
3
  FastGettext.silence_errors
4
4
 
5
5
  describe GettextI18nRails do
6
+ before do
7
+ GettextI18nRails.translations_are_html_safe = nil
8
+ end
9
+
6
10
  it "extends all classes with fast_gettext" do
7
11
  _('test')
8
12
  end
9
13
 
14
+ describe 'translations_are_html_safe' do
15
+ before do
16
+ GettextI18nRails.translations_are_html_safe = nil
17
+ end
18
+
19
+ it "makes translations not html_safe by default" do
20
+ _('x').html_safe?.should == false
21
+ s_('x').html_safe?.should == false
22
+ n_('x','y',2).html_safe?.should == false
23
+ String._('x').html_safe?.should == false
24
+ String.s_('x').html_safe?.should == false
25
+ String.n_('x','y',2).html_safe?.should == false
26
+ end
27
+
28
+ it "makes instance translations html_safe when wanted" do
29
+ GettextI18nRails.translations_are_html_safe = true
30
+ _('x').html_safe?.should == true
31
+ s_('x').html_safe?.should == true
32
+ n_('x','y',2).html_safe?.should == true
33
+ end
34
+
35
+ it "makes class translations html_safe when wanted" do
36
+ GettextI18nRails.translations_are_html_safe = true
37
+ String._('x').html_safe?.should == true
38
+ String.s_('x').html_safe?.should == true
39
+ String.n_('x','y',2).html_safe?.should == true
40
+ end
41
+
42
+ it "does not make everything html_safe" do
43
+ 'x'.html_safe?.should == false
44
+ end
45
+ end
46
+
10
47
  it "sets up out backend" do
11
48
  I18n.backend.is_a?(GettextI18nRails::Backend).should be_true
12
49
  end
@@ -37,7 +74,7 @@ describe GettextI18nRails do
37
74
  FastGettext.locale.should == 'yy'
38
75
  end
39
76
 
40
- it "does not set a non-available locale thorugh I18n.locale" do
77
+ it "does not set a non-available locale though I18n.locale" do
41
78
  FastGettext.available_locales = ['de']
42
79
  I18n.locale = :xx
43
80
  FastGettext.locale.should == 'de'
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'rubygems'
2
2
  if ENV['VERSION']
3
3
  puts "running VERSION #{ENV['VERSION']}"
4
+ gem 'actionpack', ENV['VERSION']
4
5
  gem 'activerecord', ENV['VERSION']
5
6
  gem 'activesupport', ENV['VERSION']
6
- gem 'actionpack', ENV['VERSION']
7
7
  gem 'actionmailer', ENV['VERSION']
8
8
  end
9
9
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 4
9
- version: 0.2.4
8
+ - 5
9
+ version: 0.2.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-25 00:00:00 +02:00
17
+ date: 2010-09-27 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency