fast_gettext 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
- script: "bundle exec rake"
1
+ script: "rake"
2
2
  rvm:
3
3
  - ree
4
4
  - 1.9.2
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fast_gettext (0.6.8)
4
+ fast_gettext (0.6.9)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- activemodel (3.2.5)
10
- activesupport (= 3.2.5)
9
+ activemodel (3.2.7)
10
+ activesupport (= 3.2.7)
11
11
  builder (~> 3.0.0)
12
- activerecord (3.2.5)
13
- activemodel (= 3.2.5)
14
- activesupport (= 3.2.5)
12
+ activerecord (3.2.7)
13
+ activemodel (= 3.2.7)
14
+ activesupport (= 3.2.7)
15
15
  arel (~> 3.0.2)
16
16
  tzinfo (~> 0.3.29)
17
- activesupport (3.2.5)
17
+ activesupport (3.2.7)
18
18
  i18n (~> 0.6)
19
19
  multi_json (~> 1.0)
20
20
  arel (3.0.2)
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'bundler/gem_tasks'
2
2
 
3
3
  task :default do
4
4
  ['~>2', '~>3'].each do |version|
5
- sh "export AR='#{version}' && (bundle check || bundle) && bundle exec rspec spec"
5
+ sh "export AR='#{version}' && (bundle check || bundle install) && bundle exec rspec spec"
6
6
  end
7
7
  sh "git checkout Gemfile.lock"
8
8
  end
data/Readme.md CHANGED
@@ -50,24 +50,24 @@ Setup
50
50
 
51
51
  From mo files (traditional/default)
52
52
 
53
- FastGettext.add_text_domain('my_app',:path=>'locale')
53
+ FastGettext.add_text_domain('my_app',:path => 'locale')
54
54
 
55
55
  Or po files (less maintenance than mo)
56
56
 
57
- FastGettext.add_text_domain('my_app',:path=>'locale', :type=>:po)
58
- # :ignore_fuzzy => true to silence warnings about fuzzy translations
59
- # :ignore_obsolete => true to silence warnings about obsolete translations
57
+ FastGettext.add_text_domain('my_app',:path => 'locale', :type => :po)
58
+ # :ignore_fuzzy => true to not use fuzzy translations
59
+ # :report_warning => false to hide warnings about obsolete/fuzzy translations
60
60
 
61
61
  Or yaml files (use I18n syntax/indentation)
62
62
 
63
- FastGettext.add_text_domain('my_app',:path=>'config/locales', :type=>:yaml)
63
+ FastGettext.add_text_domain('my_app', :path => 'config/locales', :type => :yaml)
64
64
 
65
65
  Or database (scaleable, good for many locales/translators)
66
66
 
67
67
  # db access is cached <-> only first lookup hits the db
68
68
  require "fast_gettext/translation_repository/db"
69
69
  FastGettext::TranslationRepository::Db.require_models #load and include default models
70
- FastGettext.add_text_domain('my_app', :type=>:db, :model=>TranslationKey)
70
+ FastGettext.add_text_domain('my_app', :type => :db, :model => TranslationKey)
71
71
 
72
72
  ### 3. Choose text domain and locale for translation
73
73
  Do this once in every Thread. (e.g. Rails -> ApplicationController)
@@ -221,6 +221,7 @@ Mo/Po-file parsing from Masao Mutoh, see vendor/README
221
221
  - [Rainux Luo](http://rainux.org)
222
222
  - [Dmitry Borodaenko](https://github.com/angdraug)
223
223
  - [Kouhei Sutou](https://github.com/kou)
224
+ - [Hoang Nghiem](https://github.com/hoangnghiem)
224
225
 
225
226
  [Michael Grosser](http://grosser.it)<br/>
226
227
  michael@grosser.it<br/>
@@ -2,7 +2,6 @@ require 'fast_gettext/mo_file'
2
2
  module FastGettext
3
3
  # Responsibility:
4
4
  # - abstract po files for Po Repository
5
- # TODO refactor...
6
5
  class PoFile
7
6
  def self.to_mo_file(file, options={})
8
7
  require 'fast_gettext/vendor/poparser'
@@ -1,11 +1,13 @@
1
1
  class TranslationKey < ActiveRecord::Base
2
- has_many :translations, :class_name => 'TranslationText'
2
+ has_many :translations, :class_name => 'TranslationText', :dependent => :destroy
3
3
 
4
4
  accepts_nested_attributes_for :translations, :allow_destroy => true
5
5
 
6
6
  validates_uniqueness_of :key
7
7
  validates_presence_of :key
8
8
 
9
+ attr_accessible :key, :translations, :translations_attributes
10
+
9
11
  def self.translation(key, locale)
10
12
  return unless translation_key = find_by_key(key)
11
13
  return unless translation_text = translation_key.translations.find_by_locale(locale)
@@ -15,4 +17,4 @@ class TranslationKey < ActiveRecord::Base
15
17
  def self.available_locales
16
18
  @@available_locales ||= TranslationText.count(:group=>:locale).keys.sort
17
19
  end
18
- end
20
+ end
@@ -1,5 +1,6 @@
1
1
  class TranslationText < ActiveRecord::Base
2
- belongs_to :key, :class_name=>'TranslationKey'
2
+ belongs_to :translation_key, :class_name => 'TranslationKey'
3
3
  validates_presence_of :locale
4
4
  validates_uniqueness_of :locale, :scope=>:translation_key_id
5
- end
5
+ attr_accessible :text, :locale, :translation_key, :translation_key_id
6
+ end
@@ -1,3 +1,3 @@
1
1
  module FastGettext
2
- VERSION = Version = '0.6.8'
2
+ VERSION = Version = '0.6.9'
3
3
  end
@@ -1,23 +1,25 @@
1
- require "spec_helper"
2
-
1
+ require 'spec_helper'
3
2
  require 'active_record'
4
3
  require 'fast_gettext/translation_repository/db'
4
+ require 'support/be_accessible_matcher'
5
+
5
6
  FastGettext::TranslationRepository::Db.require_models
6
- describe FastGettext::TranslationRepository::Db do
7
7
 
8
+ describe FastGettext::TranslationRepository::Db do
8
9
  before :all do
9
- ActiveRecord::Base.establish_connection({
10
+ ActiveRecord::Base.establish_connection(
10
11
  :adapter => "sqlite3",
11
12
  :database => ":memory:"
12
- })
13
+ )
13
14
 
14
15
  #create model table
15
- #TODO surpress output ?
16
+ ActiveRecord::Migration.verbose = false
16
17
  ActiveRecord::Schema.define(:version => 1) do
17
18
  create_table :translation_keys do |t|
18
19
  t.string :key, :unique=>true, :null=>false
19
20
  t.timestamps
20
21
  end
22
+
21
23
  create_table :translation_texts do |t|
22
24
  t.string :text, :locale
23
25
  t.integer :translation_key_id, :null=>false
@@ -34,8 +36,8 @@ describe FastGettext::TranslationRepository::Db do
34
36
  end
35
37
 
36
38
  def create_translation(key, text)
37
- translation_key = TranslationKey.create!(:key=>key)
38
- TranslationText.create!(:translation_key_id=>translation_key.id, :text=>text, :locale=>'de')
39
+ translation_key = TranslationKey.create!(:key => key)
40
+ TranslationText.create!(:translation_key_id => translation_key.id, :text => text, :locale => "de")
39
41
  end
40
42
 
41
43
  it "reads locales from the db" do
@@ -67,4 +69,35 @@ describe FastGettext::TranslationRepository::Db do
67
69
  create_translation 'Axis||||Axis', 'Achse||||Achsen'
68
70
  @rep.plural('Axis','Axis').should == ['Achse','Achsen']
69
71
  end
72
+
73
+ it "removes texts when key is removed" do
74
+ t = create_translation("a", "b")
75
+ expect{
76
+ expect{
77
+ t.translation_key.destroy
78
+ }.to change{ TranslationText.count }.by(-1)
79
+ }.to change{ TranslationKey.count }.by(-1)
80
+ end
81
+
82
+ it "model attributes should be accessible" do
83
+ key = TranslationKey.new(:key => 'New Key', :translations_attributes => { '0' => {:text => 'New Key En', :locale => 'en'}})
84
+
85
+ key.key.should == 'New Key'
86
+
87
+ key.should be_accessible(:key)
88
+ key.should be_accessible(:translations)
89
+ key.should be_accessible(:translations_attributes)
90
+ key.should_not be_accessible(:created_at)
91
+
92
+ translation = key.translations.first
93
+
94
+ translation.text.should == 'New Key En'
95
+ translation.locale.should == 'en'
96
+
97
+ translation.should be_accessible(:locale)
98
+ translation.should be_accessible(:text)
99
+ translation.should be_accessible(:translation_key)
100
+ translation.should be_accessible(:translation_key_id)
101
+ translation.should_not be_accessible(:created_at)
102
+ end
70
103
  end
@@ -5,9 +5,7 @@ describe String do
5
5
  if RUBY_VERSION > '1.9'
6
6
  yield
7
7
  else
8
- pending do
9
- yield
10
- end
8
+ pending "does not work on 1.8"
11
9
  end
12
10
  end
13
11
 
@@ -0,0 +1,8 @@
1
+ RSpec::Matchers.define :be_accessible do |attribute|
2
+ match do |response|
3
+ response.class.accessible_attributes.include?(attribute.to_s)
4
+ end
5
+ description { "be accessible :#{attribute}" }
6
+ failure_message_for_should { ":#{attribute} should be accessible" }
7
+ failure_message_for_should_not { ":#{attribute} should not be accessible" }
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_gettext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.6.9
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-15 00:00:00.000000000 Z
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: michael@grosser.it
@@ -95,6 +95,7 @@ files:
95
95
  - spec/locale/yaml/notfound.yml
96
96
  - spec/obsolete_locale/de/test.po
97
97
  - spec/spec_helper.rb
98
+ - spec/support/be_accessible_matcher.rb
98
99
  homepage: http://github.com/grosser/fast_gettext
99
100
  licenses:
100
101
  - MIT
@@ -110,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
111
  version: '0'
111
112
  segments:
112
113
  - 0
113
- hash: -3956951288386353458
114
+ hash: 4402652659877715881
114
115
  required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  none: false
116
117
  requirements:
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  version: '0'
120
121
  segments:
121
122
  - 0
122
- hash: -3956951288386353458
123
+ hash: 4402652659877715881
123
124
  requirements: []
124
125
  rubyforge_project:
125
126
  rubygems_version: 1.8.24