grosser-fast_gettext 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -48,9 +48,9 @@ Easy to maintain especially with many translations and multiple locales.
48
48
  An example migration for ActiveRecord can be found in `exaples/db/migration`.
49
49
  This is usable with any model DataMapper/Sequel or any other(non-database) backend, the only thing you need to do is respond to the self.translation(key, locale) call.
50
50
  The default plural seperator is `||||` but you may overwrite it (or suggest a better one..).
51
- include FastGettext::TranslationRepository::DB.require_models
51
+ include FastGettext::TranslationRepository::Db.require_models #load and include default models
52
52
  FastGettext.add_text_domain('my_app', :type=>:db, :model=>TranslationKey)
53
- #the model should be the model that represents the keys, you can use FastGettext::TranslationRepository::DBModel::TranslationKey
53
+ #the model should be the model that represents the keys, you can use FastGettext::TranslationRepository::DbModel::TranslationKey
54
54
 
55
55
  To get started have a look at the default models in `lib/fast_gettext/translation_repository/db/translation_key`.
56
56
 
@@ -158,7 +158,7 @@ FAQ
158
158
  TODO
159
159
  ====
160
160
  - some cleanup required, repositories should not have locale
161
- - DB::TranslationKey responds_to? :available_locales should be false when it is not defined, maybe testing bug
161
+ - DbModel::TranslationKey responds_to? :available_locales should be false when it is not defined, maybe testing bug
162
162
  - use `default_locale=(x)` internally, atm the default is available_locales.first || 'en'
163
163
  - use `default_text_domain=(x)` internally, atm default is nil...
164
164
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 4
4
- :patch: 4
4
+ :patch: 5
@@ -2,17 +2,17 @@ class CreateTranslationTables < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :translation_keys do |t|
4
4
  t.string :key, :unique=>true, :null=>false
5
- t.add_index :key
6
5
  t.timestamps
7
6
  end
8
-
7
+ add_index :translation_keys, :key #I am not sure if this helps....
8
+
9
9
  create_table :translation_texts do |t|
10
10
  t.text :text
11
11
  t.string :locale
12
12
  t.integer :translation_key_id, :null=>false
13
- t.add_index :translation_key_id
14
13
  t.timestamps
15
14
  end
15
+ add_index :translation_texts, :translation_key_id
16
16
  end
17
17
 
18
18
  def self.down
@@ -10,7 +10,7 @@ module FastGettext
10
10
  # only constraints:
11
11
  # key: find_by_key, translations
12
12
  # translation: text, locale
13
- class DB
13
+ class Db
14
14
  def initialize(name,options={})
15
15
  @model = options[:model]
16
16
  end
@@ -50,7 +50,7 @@ module FastGettext
50
50
  def self.require_models
51
51
  require 'fast_gettext/translation_repository/db_models/translation_key'
52
52
  require 'fast_gettext/translation_repository/db_models/translation_text'
53
- FastGettext::TranslationRepository::DBModels
53
+ FastGettext::TranslationRepository::DbModels
54
54
  end
55
55
  end
56
56
  end
@@ -1,5 +1,5 @@
1
1
  module FastGettext::TranslationRepository
2
- module DBModels
2
+ module DbModels
3
3
  class TranslationKey < ActiveRecord::Base
4
4
  has_many :translations, :class_name=>'TranslationText'
5
5
  validates_uniqueness_of :key
@@ -10,6 +10,15 @@ module FastGettext::TranslationRepository
10
10
  return unless translation_text = translation_key.translations.find_by_locale(locale)
11
11
  translation_text.text
12
12
  end
13
+
14
+ def self.available_locales
15
+ @@available_locales ||= TranslationText.count(:group=>:locale).keys.sort
16
+ end
17
+
18
+ #this is only for ActiveSupport to get polymorphic_url FastGettext::... namespace free
19
+ def self.model_name
20
+ ActiveSupport::ModelName.new('TranslationKey')
21
+ end
13
22
  end
14
23
  end
15
24
  end
@@ -1,5 +1,5 @@
1
1
  module FastGettext::TranslationRepository
2
- module DBModels
2
+ module DbModels
3
3
  class TranslationText < ActiveRecord::Base
4
4
  belongs_to :key, :class_name=>'TranslationKey'
5
5
  validates_presence_of :locale, :text
@@ -3,9 +3,9 @@ require File.join(current_folder,'..','..','spec_helper')
3
3
 
4
4
  require 'activerecord'
5
5
  require 'fast_gettext/translation_repository/db'
6
- include FastGettext::TranslationRepository::DB.require_models
6
+ include FastGettext::TranslationRepository::Db.require_models
7
7
 
8
- describe FastGettext::TranslationRepository::DB do
8
+ describe FastGettext::TranslationRepository::Db do
9
9
  before :all do
10
10
  ActiveRecord::Base.establish_connection({
11
11
  :adapter => "sqlite3",
@@ -31,7 +31,7 @@ describe FastGettext::TranslationRepository::DB do
31
31
  TranslationKey.delete_all
32
32
  TranslationText.delete_all
33
33
  FastGettext.locale = 'de'
34
- @rep = FastGettext::TranslationRepository::DB.new('x', :model=>TranslationKey)
34
+ @rep = FastGettext::TranslationRepository::Db.new('x', :model=>TranslationKey)
35
35
  end
36
36
 
37
37
  def create_translation(key, text)
@@ -39,9 +39,12 @@ describe FastGettext::TranslationRepository::DB do
39
39
  TranslationText.create!(:translation_key_id=>translation_key.id, :text=>text, :locale=>'de')
40
40
  end
41
41
 
42
- it "can be built" do
43
- # pending #this is weird, it responds to :available_locales, but it is not defined...
44
- @rep.available_locales.should == []
42
+ it "reads locales from the db" do
43
+ locales = ['de','en','es']
44
+ locales.reverse.each do |locale|
45
+ TranslationText.create!(:translation_key_id=>1, :text=>'asdasd', :locale=>locale)
46
+ end
47
+ @rep.available_locales.should == locales
45
48
  end
46
49
 
47
50
  it "has no pluralisation_rule by default" do
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # ---- requirements
2
+ require 'rubygems'
2
3
  $LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
3
4
  require 'fast_gettext'
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grosser-fast_gettext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-25 00:00:00 -07:00
12
+ date: 2009-04-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15