fast_gettext 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,7 +59,7 @@ Or yaml files (use I18n syntax/indentation)
59
59
  Or database (scaleable, good for many locales/translators)
60
60
  # db access is cached <-> only first lookup hits the db
61
61
  require "fast_gettext/translation_repository/db"
62
- include FastGettext::TranslationRepository::Db.require_models #load and include default models
62
+ FastGettext::TranslationRepository::Db.require_models #load and include default models
63
63
  FastGettext.add_text_domain('my_app', :type=>:db, :model=>TranslationKey)
64
64
 
65
65
  ### 3. Choose text domain and locale for translation
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.5
1
+ 0.5.6
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fast_gettext}
8
- s.version = "0.5.5"
8
+ s.version = "0.5.6"
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"]
@@ -48,9 +48,14 @@ module FastGettext
48
48
  end
49
49
 
50
50
  def self.require_models
51
- require 'fast_gettext/translation_repository/db_models/translation_key'
52
- require 'fast_gettext/translation_repository/db_models/translation_text'
53
- FastGettext::TranslationRepository::DbModels
51
+ folder = "fast_gettext/translation_repository/db_models"
52
+ require "#{folder}/translation_key"
53
+ require "#{folder}/translation_text"
54
+ Module.new do
55
+ def self.included(base)
56
+ puts "you no longer need to include the result of require_models"
57
+ end
58
+ end
54
59
  end
55
60
  end
56
61
  end
@@ -1,37 +1,18 @@
1
- module FastGettext::TranslationRepository
2
- module DbModels
3
- class TranslationKey < ActiveRecord::Base
4
- has_many :translations, :class_name=>'TranslationText'
5
- accepts_nested_attributes_for :translations, :allow_destroy => true
6
-
7
- validates_uniqueness_of :key
8
- validates_presence_of :key
1
+ class TranslationKey < ActiveRecord::Base
2
+ has_many :translations, :class_name => 'TranslationText'
9
3
 
10
- def self.translation(key, locale)
11
- return unless translation_key = find_by_key(key)
12
- return unless translation_text = translation_key.translations.find_by_locale(locale)
13
- translation_text.text
14
- end
4
+ accepts_nested_attributes_for :translations, :allow_destroy => true
15
5
 
16
- def self.available_locales
17
- @@available_locales ||= TranslationText.count(:group=>:locale).keys.sort
18
- end
6
+ validates_uniqueness_of :key
7
+ validates_presence_of :key
19
8
 
20
- # get polymorphic_url FastGettext::... namespace free
21
- # !! copied in translation_text.rb
22
- def self.name
23
- 'TranslationKey'
24
- end
9
+ def self.translation(key, locale)
10
+ return unless translation_key = find_by_key(key)
11
+ return unless translation_text = translation_key.translations.find_by_locale(locale)
12
+ translation_text.text
13
+ end
25
14
 
26
- def self.model_name
27
- if defined? ActiveSupport::ModelName # Rails 2
28
- ActiveSupport::ModelName.new(name)
29
- elsif defined? ActiveModel::Name # Rails 3
30
- ActiveModel::Name.new(self)
31
- else # Fallback
32
- name
33
- end
34
- end
35
- end
15
+ def self.available_locales
16
+ @@available_locales ||= TranslationText.count(:group=>:locale).keys.sort
36
17
  end
37
- end
18
+ end
@@ -1,25 +1,5 @@
1
- module FastGettext::TranslationRepository
2
- module DbModels
3
- class TranslationText < ActiveRecord::Base
4
- belongs_to :key, :class_name=>'TranslationKey'
5
- validates_presence_of :locale
6
- validates_uniqueness_of :locale, :scope=>:translation_key_id
7
-
8
- # get polymorphic_url FastGettext::... namespace free
9
- # !! copied in translation_key.rb
10
- def self.name
11
- 'TranslationKey'
12
- end
13
-
14
- def self.model_name
15
- if defined? ActiveSupport::ModelName # Rails 2
16
- ActiveSupport::ModelName.new(name)
17
- elsif defined? ActiveModel::Name # Rails 3
18
- ActiveModel::Name.new(self)
19
- else # Fallback
20
- name
21
- end
22
- end
23
- end
24
- end
1
+ class TranslationText < ActiveRecord::Base
2
+ belongs_to :key, :class_name=>'TranslationKey'
3
+ validates_presence_of :locale
4
+ validates_uniqueness_of :locale, :scope=>:translation_key_id
25
5
  end
@@ -2,8 +2,7 @@ require 'spec/spec_helper'
2
2
 
3
3
  require 'active_record'
4
4
  require 'fast_gettext/translation_repository/db'
5
-
6
- include FastGettext::TranslationRepository::Db.require_models
5
+ FastGettext::TranslationRepository::Db.require_models
7
6
  describe FastGettext::TranslationRepository::Db do
8
7
 
9
8
  before :all do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 5
9
- version: 0.5.5
8
+ - 6
9
+ version: 0.5.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser