gettext_i18n_rails 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,10 @@ source :rubygems
3
3
  gem 'fast_gettext'
4
4
 
5
5
  group :dev do
6
+ gem 'haml'
7
+ gem 'slim'
8
+ gem 'ruby_parser'
9
+ gem 'gettext'
6
10
  gem 'sqlite3', '~>1.3.4'
7
11
  gem 'rails', ENV['RAILS'] || '~>3'
8
12
  gem 'rake'
data/Gemfile.lock CHANGED
@@ -36,13 +36,17 @@ GEM
36
36
  diff-lcs (1.1.2)
37
37
  erubis (2.7.0)
38
38
  fast_gettext (0.5.13)
39
+ gettext (2.1.0)
40
+ locale (>= 2.0.5)
39
41
  git (1.2.5)
42
+ haml (3.1.4)
40
43
  hike (1.2.1)
41
44
  i18n (0.6.0)
42
45
  jeweler (1.6.4)
43
46
  bundler (~> 1.0)
44
47
  git (>= 1.2.5)
45
48
  rake
49
+ locale (2.0.5)
46
50
  mail (2.3.0)
47
51
  i18n (>= 0.4.0)
48
52
  mime-types (~> 1.16)
@@ -84,11 +88,18 @@ GEM
84
88
  rspec-expectations (2.6.0)
85
89
  diff-lcs (~> 1.1.2)
86
90
  rspec-mocks (2.6.0)
91
+ ruby_parser (2.3.1)
92
+ sexp_processor (~> 3.0)
93
+ sexp_processor (3.0.10)
94
+ slim (1.1.0)
95
+ temple (~> 0.3.5)
96
+ tilt (~> 1.3.2)
87
97
  sprockets (2.0.0)
88
98
  hike (~> 1.2)
89
99
  rack (~> 1.0)
90
100
  tilt (~> 1.1, != 1.3.0)
91
101
  sqlite3 (1.3.4)
102
+ temple (0.3.5)
92
103
  thor (0.14.6)
93
104
  tilt (1.3.3)
94
105
  treetop (1.4.10)
@@ -101,8 +112,12 @@ PLATFORMS
101
112
 
102
113
  DEPENDENCIES
103
114
  fast_gettext
115
+ gettext
116
+ haml
104
117
  jeweler
105
118
  rails (~> 3)
106
119
  rake
107
120
  rspec (~> 2)
121
+ ruby_parser
122
+ slim
108
123
  sqlite3 (~> 1.3.4)
data/Readme.md CHANGED
@@ -27,9 +27,13 @@ Setup
27
27
  gem 'gettext_i18n_rails'
28
28
 
29
29
  ##### Optional:
30
- If you want to find translations or build .mo files
30
+ Add `gettext` if you want to find translations or build .mo files<br/>
31
+ Add `ruby_parser` if you want to find translations inside haml files
32
+
33
+
31
34
  # Gemfile
32
35
  gem 'gettext', '>=1.9.3', :require => false, :group => :development
36
+ gem 'ruby_parser', :require => false, :group => :development
33
37
 
34
38
  #### Rails 2
35
39
 
@@ -189,13 +193,13 @@ When you run
189
193
 
190
194
  rake gettext:find
191
195
 
192
- by default the following files are going to be scanned for translations: {app,lib,config,locale}/**/*.{rb,erb,haml}. If
196
+ by default the following files are going to be scanned for translations: {app,lib,config,locale}/**/*.{rb,erb,haml,slim}. If
193
197
  you want to specify a different list, you can redefine files_to_translate in the gettext namespace in a file like
194
198
  lib/tasks/gettext.rake:
195
199
 
196
200
  namespace :gettext do
197
201
  def files_to_translate
198
- Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml,rhtml}")
202
+ Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml,slim,rhtml}")
199
203
  end
200
204
  end
201
205
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gettext_i18n_rails"
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
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 = "2012-01-03"
12
+ s.date = "2012-01-10"
13
13
  s.email = "grosser.michael@gmail.com"
14
14
  s.files = [
15
15
  "Gemfile",
@@ -29,19 +29,22 @@ Gem::Specification.new do |s|
29
29
  "lib/gettext_i18n_rails/model_attributes_finder.rb",
30
30
  "lib/gettext_i18n_rails/railtie.rb",
31
31
  "lib/gettext_i18n_rails/ruby_gettext_extractor.rb",
32
+ "lib/gettext_i18n_rails/slim_parser.rb",
32
33
  "lib/gettext_i18n_rails/string_interpolate_fix.rb",
33
34
  "lib/gettext_i18n_rails/tasks.rb",
34
35
  "lib/tasks/gettext_rails_i18n.rake",
35
36
  "spec/gettext_i18n_rails/action_controller_spec.rb",
36
37
  "spec/gettext_i18n_rails/active_record_spec.rb",
37
38
  "spec/gettext_i18n_rails/backend_spec.rb",
39
+ "spec/gettext_i18n_rails/haml_parser_spec.rb",
40
+ "spec/gettext_i18n_rails/slim_parser_spec.rb",
38
41
  "spec/gettext_i18n_rails/string_interpolate_fix_spec.rb",
39
42
  "spec/gettext_i18n_rails_spec.rb",
40
43
  "spec/spec_helper.rb"
41
44
  ]
42
45
  s.homepage = "http://github.com/grosser/gettext_i18n_rails"
43
46
  s.require_paths = ["lib"]
44
- s.rubygems_version = "1.8.10"
47
+ s.rubygems_version = "1.8.15"
45
48
  s.summary = "Simple FastGettext Rails integration."
46
49
 
47
50
  if s.respond_to? :specification_version then
@@ -14,18 +14,15 @@ module GettextI18nRails
14
14
  end
15
15
 
16
16
  def parse(file, msgids = [])
17
- return msgids unless load_haml
18
- require 'gettext_i18n_rails/ruby_gettext_extractor'
19
-
20
- text = IO.readlines(file).join
21
-
22
- haml = Haml::Engine.new(text)
23
- code = haml.precompiled
24
- return RubyGettextExtractor.parse_string(code, file, msgids)
17
+ return msgids unless prepare_haml_parsing
18
+ text = File.read(file)
19
+ code = Haml::Engine.new(text).precompiled()
20
+ RubyGettextExtractor.parse_string(code, file, msgids)
25
21
  end
26
22
 
27
- def load_haml
23
+ def prepare_haml_parsing
28
24
  return true if @haml_loaded
25
+
29
26
  begin
30
27
  require "#{::Rails.root.to_s}/vendor/plugins/haml/lib/haml"
31
28
  rescue LoadError
@@ -36,8 +33,11 @@ module GettextI18nRails
36
33
  return false
37
34
  end
38
35
  end
36
+
37
+ require 'gettext_i18n_rails/ruby_gettext_extractor'
39
38
  @haml_loaded = true
40
39
  end
41
40
  end
42
41
  end
42
+
43
43
  GetText::RGetText.add_parser(GettextI18nRails::HamlParser)
@@ -0,0 +1,37 @@
1
+ require 'gettext/tools'
2
+ begin
3
+ require 'gettext/tools/rgettext'
4
+ rescue LoadError #version prior to 2.0
5
+ require 'gettext/rgettext'
6
+ end
7
+
8
+ module GettextI18nRails
9
+ module SlimParser
10
+ module_function
11
+
12
+ def target?(file)
13
+ File.extname(file) == '.slim'
14
+ end
15
+
16
+ def parse(file, msgids = [])
17
+ return msgids unless prepare_slim_parsing
18
+ text = File.read(file)
19
+ code = Slim::Engine.new.call(text)
20
+ RubyGettextExtractor.parse_string(code, file, msgids)
21
+ end
22
+
23
+ def prepare_slim_parsing
24
+ return true if @slim_loaded
25
+ begin
26
+ require 'slim'
27
+ rescue LoadError
28
+ puts "A slim file was found, but slim library could not be found, so nothing will be parsed..."
29
+ return false
30
+ end
31
+ require 'gettext_i18n_rails/ruby_gettext_extractor'
32
+ @slim_loaded = true
33
+ end
34
+ end
35
+ end
36
+
37
+ GetText::RGetText.add_parser(GettextI18nRails::SlimParser)
@@ -15,6 +15,7 @@ namespace :gettext do
15
15
  load_gettext
16
16
  $LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib')
17
17
  require 'gettext_i18n_rails/haml_parser'
18
+ require 'gettext_i18n_rails/slim_parser'
18
19
 
19
20
 
20
21
  if GetText.respond_to? :update_pofiles_org
@@ -120,6 +121,6 @@ namespace :gettext do
120
121
  end
121
122
 
122
123
  def files_to_translate
123
- Dir.glob("{app,lib,config,#{locale_path}}/**/*.{rb,erb,haml}")
124
+ Dir.glob("{app,lib,config,#{locale_path}}/**/*.{rb,erb,haml,slim}")
124
125
  end
125
126
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path("../spec_helper", File.dirname(__FILE__))
1
+ require "spec_helper"
2
2
 
3
3
  FastGettext.silence_errors
4
4
 
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
+ require "spec_helper"
3
3
 
4
4
  FastGettext.silence_errors
5
5
 
@@ -1,4 +1,4 @@
1
- require File.expand_path("../spec_helper", File.dirname(__FILE__))
1
+ require "spec_helper"
2
2
 
3
3
  FastGettext.silence_errors
4
4
 
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+ require "gettext_i18n_rails/haml_parser"
3
+
4
+ describe GettextI18nRails::HamlParser do
5
+ let(:parser){ GettextI18nRails::HamlParser }
6
+
7
+ describe "#target?" do
8
+ it "targets .haml" do
9
+ parser.target?('foo/bar/xxx.haml').should == true
10
+ end
11
+
12
+ it "does not target anything else" do
13
+ parser.target?('foo/bar/xxx.erb').should == false
14
+ end
15
+ end
16
+
17
+ describe "#parse" do
18
+ it "finds messages in haml" do
19
+ with_file '= _("xxxx")' do |path|
20
+ parser.parse(path, []).should == [
21
+ ["xxxx", "#{path}:1"]
22
+ ]
23
+ end
24
+ end
25
+
26
+ it "does not find messages in text" do
27
+ with_file '_("xxxx")' do |path|
28
+ parser.parse(path, []).should == []
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+ require "gettext_i18n_rails/slim_parser"
3
+
4
+ describe GettextI18nRails::SlimParser do
5
+ let(:parser){ GettextI18nRails::SlimParser }
6
+
7
+ describe "#target?" do
8
+ it "targets .slim" do
9
+ parser.target?('foo/bar/xxx.slim').should == true
10
+ end
11
+
12
+ it "does not target anything else" do
13
+ parser.target?('foo/bar/xxx.erb').should == false
14
+ end
15
+ end
16
+
17
+ describe "#parse" do
18
+ it "finds messages in slim" do
19
+ with_file 'div = _("xxxx")' do |path|
20
+ parser.parse(path, []).should == [
21
+ ["xxxx", "#{path}:1"]
22
+ ]
23
+ end
24
+ end
25
+
26
+ it "does not find messages in text" do
27
+ with_file 'div _("xxxx")' do |path|
28
+ parser.parse(path, []).should == []
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
- require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
- require 'gettext_i18n_rails/string_interpolate_fix'
1
+ require "spec_helper"
2
+ require "gettext_i18n_rails/string_interpolate_fix"
3
3
 
4
4
  describe "String#%" do
5
5
  it "is not safe if it was not safe" do
@@ -1,4 +1,4 @@
1
- require File.expand_path("spec_helper", File.dirname(__FILE__))
1
+ require "spec_helper"
2
2
 
3
3
  FastGettext.silence_errors
4
4
 
data/spec/spec_helper.rb CHANGED
@@ -2,9 +2,38 @@ require 'rubygems'
2
2
 
3
3
  $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
4
4
 
5
+ require 'tempfile'
5
6
  require 'active_support'
6
7
  require 'active_record'
7
8
  require 'action_controller'
8
9
  require 'action_mailer'
9
10
  require 'fast_gettext'
10
11
  require 'gettext_i18n_rails'
12
+
13
+ begin
14
+ Gem.all_load_paths
15
+ rescue
16
+ puts "Fixing Gem.all_load_paths"
17
+ module Gem;def self.all_load_paths;[];end;end
18
+ end
19
+
20
+ module Rails
21
+ def self.root
22
+ File.dirname(__FILE__)
23
+ end
24
+
25
+ module VERSION
26
+ MAJOR = 3
27
+ MINOR = 1
28
+ PATCH = 0
29
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
30
+ end
31
+ end
32
+
33
+ def with_file(content)
34
+ Tempfile.open('gettext_i18n_rails_specs') do |f|
35
+ f.write(content)
36
+ f.close
37
+ yield f.path
38
+ end
39
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettext_i18n_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Grosser
@@ -15,10 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-03 00:00:00 Z
18
+ date: 2012-01-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
21
+ prerelease: false
22
+ type: :runtime
23
+ requirement: &id001 !ruby/object:Gem::Requirement
22
24
  none: false
23
25
  requirements:
24
26
  - - ">="
@@ -27,10 +29,8 @@ dependencies:
27
29
  segments:
28
30
  - 0
29
31
  version: "0"
30
- requirement: *id001
31
- prerelease: false
32
- type: :runtime
33
32
  name: fast_gettext
33
+ version_requirements: *id001
34
34
  description:
35
35
  email: grosser.michael@gmail.com
36
36
  executables: []
@@ -57,12 +57,15 @@ files:
57
57
  - lib/gettext_i18n_rails/model_attributes_finder.rb
58
58
  - lib/gettext_i18n_rails/railtie.rb
59
59
  - lib/gettext_i18n_rails/ruby_gettext_extractor.rb
60
+ - lib/gettext_i18n_rails/slim_parser.rb
60
61
  - lib/gettext_i18n_rails/string_interpolate_fix.rb
61
62
  - lib/gettext_i18n_rails/tasks.rb
62
63
  - lib/tasks/gettext_rails_i18n.rake
63
64
  - spec/gettext_i18n_rails/action_controller_spec.rb
64
65
  - spec/gettext_i18n_rails/active_record_spec.rb
65
66
  - spec/gettext_i18n_rails/backend_spec.rb
67
+ - spec/gettext_i18n_rails/haml_parser_spec.rb
68
+ - spec/gettext_i18n_rails/slim_parser_spec.rb
66
69
  - spec/gettext_i18n_rails/string_interpolate_fix_spec.rb
67
70
  - spec/gettext_i18n_rails_spec.rb
68
71
  - spec/spec_helper.rb
@@ -95,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
98
  requirements: []
96
99
 
97
100
  rubyforge_project:
98
- rubygems_version: 1.8.10
101
+ rubygems_version: 1.8.15
99
102
  signing_key:
100
103
  specification_version: 3
101
104
  summary: Simple FastGettext Rails integration.