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.
- data/README.markdown +1 -1
- data/VERSION +1 -1
- data/fast_gettext.gemspec +1 -1
- data/lib/fast_gettext/translation_repository/db.rb +8 -3
- data/lib/fast_gettext/translation_repository/db_models/translation_key.rb +13 -32
- data/lib/fast_gettext/translation_repository/db_models/translation_text.rb +4 -24
- data/spec/fast_gettext/translation_repository/db_spec.rb +1 -2
- metadata +2 -2
data/README.markdown
CHANGED
@@ -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
|
-
|
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.
|
1
|
+
0.5.6
|
data/fast_gettext.gemspec
CHANGED
@@ -48,9 +48,14 @@ module FastGettext
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def self.require_models
|
51
|
-
|
52
|
-
require
|
53
|
-
|
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
|
-
|
2
|
-
|
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
|
-
|
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
|
-
|
17
|
-
|
18
|
-
end
|
6
|
+
validates_uniqueness_of :key
|
7
|
+
validates_presence_of :key
|
19
8
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
27
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|