gettext_i18n_rails 0.6.6 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gem 'haml'
5
5
  gem 'slim'
6
6
  gem 'hamlet'
7
7
  gem 'ruby_parser'
8
- gem 'gettext'
8
+ gem 'gettext', "2.3.1", :github => "ruby-gettext/gettext" # waiting for 2.3.1 to be released
9
9
  gem 'sqlite3', '~>1.3.6'
10
10
  gem 'rails', ENV['RAILS'] || '~>3'
11
11
  gem 'rake'
@@ -1,8 +1,15 @@
1
+ GIT
2
+ remote: git://github.com/ruby-gettext/gettext.git
3
+ revision: 3c4822399d587831a479df7db2b1b28de0216093
4
+ specs:
5
+ gettext (2.3.1)
6
+ locale
7
+
1
8
  PATH
2
9
  remote: .
3
10
  specs:
4
- gettext_i18n_rails (0.6.6)
5
- fast_gettext
11
+ gettext_i18n_rails (0.7.0)
12
+ fast_gettext (>= 0.4.8)
6
13
 
7
14
  GEM
8
15
  remote: http://rubygems.org/
@@ -38,9 +45,7 @@ GEM
38
45
  builder (3.0.0)
39
46
  diff-lcs (1.1.2)
40
47
  erubis (2.7.0)
41
- fast_gettext (0.6.8)
42
- gettext (2.1.0)
43
- locale (>= 2.0.5)
48
+ fast_gettext (0.6.9)
44
49
  haml (3.1.4)
45
50
  hamlet (0.1)
46
51
  slim (~> 1.0)
@@ -48,7 +53,7 @@ GEM
48
53
  i18n (0.6.0)
49
54
  journey (1.0.4)
50
55
  json (1.7.3)
51
- locale (2.0.5)
56
+ locale (2.0.8)
52
57
  mail (2.4.4)
53
58
  i18n (>= 0.4.0)
54
59
  mime-types (~> 1.16)
@@ -112,7 +117,7 @@ PLATFORMS
112
117
  ruby
113
118
 
114
119
  DEPENDENCIES
115
- gettext
120
+ gettext (= 2.3.1)!
116
121
  gettext_i18n_rails!
117
122
  haml
118
123
  hamlet
data/Rakefile CHANGED
@@ -13,18 +13,17 @@ end
13
13
 
14
14
  # extracted from https://github.com/grosser/project_template
15
15
  rule /^version:bump:.*/ do |t|
16
- sh "git status | grep 'nothing to commit'" # ensure we are not dirty
17
- index = ['major', 'minor','patch'].index(t.name.split(':').last)
18
- file = 'lib/gettext_i18n_rails/version.rb'
16
+ file = "lib/gettext_i18n_rails/version.rb"
19
17
 
18
+ sh "git status | grep 'nothing to commit'" # ensure we are not dirty
19
+ index = ["major", "minor", "patch"].index(t.name.split(':').last)
20
20
  version_file = File.read(file)
21
21
  old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
22
22
  version_parts[index] = version_parts[index].to_i + 1
23
23
  version_parts[2] = 0 if index < 2 # remove patch for minor
24
24
  version_parts[1] = 0 if index < 1 # remove minor for major
25
25
  new_version = version_parts * '.'
26
- File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
27
26
 
27
+ File.open(file,"w"){|f| f.write(version_file.sub(old_version, new_version)) }
28
28
  sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
29
29
  end
30
-
data/Readme.md CHANGED
@@ -203,6 +203,11 @@ lib/tasks/gettext.rake:
203
203
  end
204
204
  end
205
205
 
206
+ Using your translations from javascript
207
+ =======================================
208
+
209
+ 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.
210
+
206
211
  [Contributors](http://github.com/grosser/gettext_i18n_rails/contributors)
207
212
  ======
208
213
  - [ruby gettext extractor](http://github.com/retoo/ruby_gettext_extractor/tree/master) from [retoo](http://github.com/retoo)
@@ -227,4 +232,4 @@ lib/tasks/gettext.rake:
227
232
 
228
233
  [Michael Grosser](http://grosser.it)<br/>
229
234
  grosser.michael@gmail.com<br/>
230
- Hereby placed under public domain, do what you want, just do not hold me accountable...
235
+ License: MIT
@@ -9,5 +9,5 @@ Gem::Specification.new name, GettextI18nRails::VERSION do |s|
9
9
  s.homepage = "http://github.com/grosser/#{name}"
10
10
  s.files = `git ls-files`.split("\n")
11
11
  s.license = "MIT"
12
- s.add_runtime_dependency "fast_gettext"
12
+ s.add_runtime_dependency "fast_gettext", ">=0.4.8"
13
13
  end
@@ -1,15 +1,11 @@
1
1
  require 'gettext_i18n_rails/version'
2
+ require 'gettext_i18n_rails/gettext_hooks'
2
3
 
3
4
  module GettextI18nRails
4
- extend self
5
5
  end
6
6
 
7
+ # translate from everywhere
7
8
  require 'fast_gettext'
8
- if Gem::Version.new(FastGettext::VERSION) < Gem::Version.new("0.4.8")
9
- raise "Please upgrade fast_gettext"
10
- end
11
-
12
- # include translations into all the places it needs to go...
13
9
  Object.send(:include, FastGettext::Translation)
14
10
 
15
11
  # make translations html_safe if possible and wanted
@@ -18,11 +14,14 @@ if "".respond_to?(:html_safe?)
18
14
  Object.send(:include, GettextI18nRails::HtmlSafeTranslations)
19
15
  end
20
16
 
17
+ # set up the backend
21
18
  require 'gettext_i18n_rails/backend'
22
19
  I18n.backend = GettextI18nRails::Backend.new
23
20
 
21
+ # make I18n play nice with FastGettext
24
22
  require 'gettext_i18n_rails/i18n_hacks'
25
23
 
24
+ # translate activerecord errors
26
25
  if defined? Rails::Railtie # Rails 3+
27
26
  # load active_model extensions at the correct point in time
28
27
  require 'gettext_i18n_rails/railtie'
@@ -34,4 +33,5 @@ else
34
33
  end
35
34
  end
36
35
 
37
- require 'gettext_i18n_rails/action_controller' if defined?(ActionController) # so that bundle console can work in a rails project
36
+ # make bundle console work in a rails project
37
+ require 'gettext_i18n_rails/action_controller' if defined?(ActionController)
@@ -1,12 +1,15 @@
1
- require 'gettext/utils'
2
- begin
3
- require 'gettext/tools/rgettext'
4
- rescue LoadError #version prior to 2.0
5
- require 'gettext/rgettext'
6
- end
7
-
8
1
  module GettextI18nRails
9
2
  class BaseParser
3
+ # copy AS 3 feature so we can play nicely with AS2 and if rails env is not there
4
+ class << self
5
+ attr_accessor :parser_descendants
6
+ end
7
+ self.parser_descendants = []
8
+
9
+ def self.inherited(subclass)
10
+ parser_descendants << subclass
11
+ end
12
+
10
13
  def self.target?(file)
11
14
  File.extname(file) == ".#{extension}"
12
15
  end
@@ -0,0 +1,31 @@
1
+ module GettextI18nRails
2
+ module GettextHooks
3
+ def self.add_parsers_to_gettext
4
+ return if @add_parsers_to_gettext
5
+ @add_parsers_to_gettext = true
6
+
7
+ require "gettext_i18n_rails/haml_parser"
8
+ require "gettext_i18n_rails/hamlet_parser"
9
+ require "gettext_i18n_rails/slim_parser"
10
+
11
+ GettextI18nRails::BaseParser.parser_descendants.each do |parser|
12
+ xgettext.add_parser(parser)
13
+ end
14
+ end
15
+
16
+ def self.xgettext
17
+ @xgettext ||= begin
18
+ require 'gettext/tools/xgettext' # 2.3+
19
+ GetText::Tools::XGetText
20
+ rescue LoadError
21
+ begin
22
+ require 'gettext/tools/rgettext' # 2.0 - 2.2
23
+ GetText::RGetText
24
+ rescue LoadError # # 1.x
25
+ require 'gettext/rgettext'
26
+ GetText::RGetText
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -11,5 +11,3 @@ module GettextI18nRails
11
11
  end
12
12
  end
13
13
  end
14
-
15
- GetText::RGetText.add_parser(GettextI18nRails::HamlParser)
@@ -11,6 +11,3 @@ module GettextI18nRails
11
11
  end
12
12
  end
13
13
  end
14
-
15
- GetText::RGetText.add_parser(GettextI18nRails::HamletParser)
16
-
@@ -1,17 +1,6 @@
1
1
  # new ruby parser from retoo, that should help extracting "#{_('xxx')}", which is needed especially when parsing haml files
2
- #
3
- #!/usr/bin/ruby
4
- # parser/ruby.rb - look for gettext msg strings in ruby files
5
-
6
- require 'rubygems'
7
2
  require 'ruby_parser'
8
3
 
9
- begin
10
- require 'gettext/tools/rgettext'
11
- rescue LoadError #version prior to 2.0
12
- require 'gettext/rgettext'
13
- end
14
-
15
4
  module RubyGettextExtractor
16
5
  extend self
17
6
 
@@ -11,5 +11,3 @@ module GettextI18nRails
11
11
  end
12
12
  end
13
13
  end
14
-
15
- GetText::RGetText.add_parser(GettextI18nRails::SlimParser)
@@ -2,6 +2,7 @@ namespace :gettext do
2
2
  def load_gettext
3
3
  require 'gettext'
4
4
  require 'gettext/utils'
5
+ require 'gettext_i18n_rails/gettext_hooks'
5
6
  end
6
7
 
7
8
  desc "Create mo-files for L10n"
@@ -13,11 +14,9 @@ namespace :gettext do
13
14
  desc "Update pot/po files."
14
15
  task :find => :environment do
15
16
  load_gettext
16
- $LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib')
17
- require 'gettext_i18n_rails/haml_parser'
18
- require 'gettext_i18n_rails/slim_parser'
19
- require 'gettext_i18n_rails/hamlet_parser'
17
+ $LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib') # needed when installed as plugin
20
18
 
19
+ GettextI18nRails::GettextHooks.add_parsers_to_gettext
21
20
 
22
21
  if GetText.respond_to? :update_pofiles_org
23
22
  if defined?(Rails.application)
@@ -120,6 +119,7 @@ namespace :gettext do
120
119
  ENV['TEXTDOMAIN'] || (FastGettext.text_domain rescue nil) || "app"
121
120
  end
122
121
 
122
+ # do not rename, gettext_i18n_rails_js overwrites this to inject coffee + js
123
123
  def files_to_translate
124
124
  Dir.glob("{app,lib,config,#{locale_path}}/**/*.{rb,erb,haml,slim}")
125
125
  end
@@ -1,3 +1,3 @@
1
1
  module GettextI18nRails
2
- Version = VERSION = '0.6.6'
2
+ Version = VERSION = '0.7.0'
3
3
  end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe GettextI18nRails::GettextHooks do
4
+ describe ".add_parsers_to_gettext" do
5
+ def parsers
6
+ GettextI18nRails::GettextHooks.xgettext # load XGetText
7
+ GettextI18nRails::GettextHooks.instance_variable_set(:@add_parsers_to_gettext, nil) # can add_parsers_to_gettext multiple times
8
+ GetText::Tools::XGetText.class_variable_get(:@@default_parsers)
9
+ end
10
+
11
+ before do
12
+ parsers.clear
13
+ end
14
+
15
+ it "should add all parsers to gettext" do
16
+ expect{
17
+ GettextI18nRails::GettextHooks.add_parsers_to_gettext
18
+ }.to change{ parsers.size }.by(+3)
19
+ end
20
+
21
+ it "should not add them twice" do
22
+ expect{
23
+ GettextI18nRails::GettextHooks.add_parsers_to_gettext
24
+ GettextI18nRails::GettextHooks.add_parsers_to_gettext
25
+ }.to change{ parsers.size }.by(+3)
26
+ end
27
+ end
28
+ end
@@ -79,7 +79,11 @@ class Part < ActiveRecord::Base
79
79
  end
80
80
 
81
81
  class NotConventional < ActiveRecord::Base
82
- set_table_name :not_at_all_conventionals
82
+ if ActiveRecord::VERSION::MAJOR == 3
83
+ self.table_name = :not_at_all_conventionals
84
+ else
85
+ set_table_name :not_at_all_conventionals
86
+ end
83
87
  end
84
88
 
85
89
  class Idea < ActiveRecord::Base
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettext_i18n_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-21 00:00:00.000000000 Z
12
+ date: 2012-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fast_gettext
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 0.4.8
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 0.4.8
30
30
  description:
31
31
  email: michael@grosser.it
32
32
  executables: []
@@ -46,6 +46,7 @@ files:
46
46
  - lib/gettext_i18n_rails/active_record.rb
47
47
  - lib/gettext_i18n_rails/backend.rb
48
48
  - lib/gettext_i18n_rails/base_parser.rb
49
+ - lib/gettext_i18n_rails/gettext_hooks.rb
49
50
  - lib/gettext_i18n_rails/haml_parser.rb
50
51
  - lib/gettext_i18n_rails/hamlet_parser.rb
51
52
  - lib/gettext_i18n_rails/html_safe_translations.rb
@@ -62,6 +63,7 @@ files:
62
63
  - spec/gettext_i18n_rails/active_model_spec.rb
63
64
  - spec/gettext_i18n_rails/active_record_spec.rb
64
65
  - spec/gettext_i18n_rails/backend_spec.rb
66
+ - spec/gettext_i18n_rails/gettext_hooks_spec.rb
65
67
  - spec/gettext_i18n_rails/haml_parser_spec.rb
66
68
  - spec/gettext_i18n_rails/hamlet_parser_spec.rb
67
69
  - spec/gettext_i18n_rails/model_attributes_finder_spec.rb
@@ -84,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
86
  version: '0'
85
87
  segments:
86
88
  - 0
87
- hash: 1353912275182047211
89
+ hash: 1552868683702405680
88
90
  required_rubygems_version: !ruby/object:Gem::Requirement
89
91
  none: false
90
92
  requirements:
@@ -93,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
95
  version: '0'
94
96
  segments:
95
97
  - 0
96
- hash: 1353912275182047211
98
+ hash: 1552868683702405680
97
99
  requirements: []
98
100
  rubyforge_project:
99
101
  rubygems_version: 1.8.24