air18n 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/air18n/phrase.rb +17 -0
- data/lib/air18n/phrase_revision.rb +9 -0
- data/lib/air18n/phrase_translation.rb +1 -1
- data/lib/air18n/reflection.rb +1 -0
- data/lib/air18n/version.rb +1 -1
- data/lib/generators/air18n/migration/templates/active_record/migration.rb +10 -0
- data/spec/lib/air18n/phrase_spec.rb +27 -0
- data/spec/lib/air18n/phrase_translation_spec.rb +4 -3
- data/spec/spec_helper.rb +2 -1
- metadata +5 -2
data/lib/air18n/phrase.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module Air18n
|
2
2
|
class Phrase < ActiveRecord::Base
|
3
3
|
has_many :phrase_translations, :dependent=>:delete_all
|
4
|
+
has_many :phrase_revisions, :foreign_key => 'key', :primary_key => 'key', :dependent=>:delete_all
|
4
5
|
has_many :phrase_screenshots, :foreign_key => 'phrase_key', :primary_key => 'key', :dependent=>:delete_all
|
5
6
|
|
6
7
|
after_update :mark_translations_stale
|
8
|
+
after_update :record_phrase_revision
|
7
9
|
|
8
10
|
validates_uniqueness_of :key
|
9
11
|
|
@@ -18,6 +20,17 @@ module Air18n
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
23
|
+
def record_phrase_revision
|
24
|
+
value_hash = compute_value_hash
|
25
|
+
LoggingHelper.info "record phrase revision"
|
26
|
+
PhraseRevision.find_or_create_by_key_and_value_hash_and_value(key, value_hash, value)
|
27
|
+
end
|
28
|
+
|
29
|
+
def compute_value_hash
|
30
|
+
Digest::MD5.new.update(value).to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
# TODO(jkb) retire this method, it is very old and ugly.
|
21
34
|
def self.by_key lookup
|
22
35
|
if !@by_key then
|
23
36
|
@by_key = {}
|
@@ -88,5 +101,9 @@ module Air18n
|
|
88
101
|
def is_rich_text?
|
89
102
|
!!(self.value && Phrase.is_rich?(self.value))
|
90
103
|
end
|
104
|
+
|
105
|
+
def revisions_in_order
|
106
|
+
phrase_revisions.order('phrase_revisions.created_at ASC')
|
107
|
+
end
|
91
108
|
end
|
92
109
|
end
|
@@ -37,7 +37,7 @@ module Air18n
|
|
37
37
|
# Sets the source_word_count and source_hash fields.
|
38
38
|
def set_source_hash
|
39
39
|
self.source_word_count = PhraseTranslation.segment(phrase.value).size
|
40
|
-
self.source_hash =
|
40
|
+
self.source_hash = phrase.compute_value_hash
|
41
41
|
end
|
42
42
|
|
43
43
|
# Provides a complete set of latest translations for specified locales, in nested hash format.
|
data/lib/air18n/reflection.rb
CHANGED
data/lib/air18n/version.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
class Air18nMigration < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
+
create_table "phrase_revisions", :force => true do |t|
|
4
|
+
t.string "key"
|
5
|
+
t.text "value"
|
6
|
+
t.string "value_hash"
|
7
|
+
t.datetime "created_at"
|
8
|
+
t.datetime "updated_at"
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index "phrase_revisions", ["key", "value_hash"], :name => "index_phrase_revisions_on_key_and_value_hash"
|
12
|
+
|
3
13
|
create_table "phrase_screenshots", :force => true do |t|
|
4
14
|
t.string "screenshot_url"
|
5
15
|
t.datetime "created_at"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Air18n::Phrase do
|
6
|
+
context 'revisions' do
|
7
|
+
it "should keep track of its revisions" do
|
8
|
+
phrase = FactoryGirl.create(:phrase, :key => 'revisions key')
|
9
|
+
phrase.value = "new value"
|
10
|
+
phrase.save!
|
11
|
+
phrase.phrase_revisions.size.should == 1
|
12
|
+
phrase.phrase_revisions.first.value_hash.should == "14979451a8c46ae1691eb3aedab3359d"
|
13
|
+
|
14
|
+
phrase.value = "second value"
|
15
|
+
phrase.save!
|
16
|
+
revisions = phrase.revisions_in_order
|
17
|
+
revisions.map(&:value_hash).should == ["14979451a8c46ae1691eb3aedab3359d", "5d10ab09a3cd6e0227c2c79fd8e525b7"]
|
18
|
+
|
19
|
+
phrase.value = "new value"
|
20
|
+
phrase.save!
|
21
|
+
revisions = phrase.revisions_in_order
|
22
|
+
revisions.map(&:value_hash).should == ["14979451a8c46ae1691eb3aedab3359d", "5d10ab09a3cd6e0227c2c79fd8e525b7"]
|
23
|
+
Air18n::PhraseRevision.value_from_hash('revisions key', "14979451a8c46ae1691eb3aedab3359d").should == "new value"
|
24
|
+
Air18n::PhraseRevision.value_from_hash('revisions key', "5d10ab09a3cd6e0227c2c79fd8e525b7").should == "second value"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -26,9 +26,10 @@ describe Air18n::PhraseTranslation do
|
|
26
26
|
|
27
27
|
context 'source hash' do
|
28
28
|
it "PhraseTranslation Should get unset when a new translation is made" do
|
29
|
-
|
30
|
-
original_translation.
|
31
|
-
original_translation.
|
29
|
+
phrase = FactoryGirl.create(:phrase, :key => 'source hash phrase key', :value => 'source hash phrase value')
|
30
|
+
original_translation = FactoryGirl.create(:phrase_translation, :phrase => phrase)
|
31
|
+
original_translation.source_word_count.should == 4
|
32
|
+
original_translation.source_hash.should == "b60188f9fd5c5b5e63a412501bd464a2"
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
data/spec/spec_helper.rb
CHANGED
@@ -24,6 +24,8 @@ require "active_record"
|
|
24
24
|
db_name = ENV['DB'] || 'sqlite3'
|
25
25
|
database_yml = File.expand_path('../database.yml', __FILE__)
|
26
26
|
|
27
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
28
|
+
|
27
29
|
if File.exists?(database_yml)
|
28
30
|
active_record_configuration = YAML.load_file(database_yml)
|
29
31
|
|
@@ -33,7 +35,6 @@ if File.exists?(database_yml)
|
|
33
35
|
ActiveRecord::Base.establish_connection(db_name)
|
34
36
|
ActiveRecord::Base.connection
|
35
37
|
|
36
|
-
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
37
38
|
ActiveRecord::Base.default_timezone = :utc
|
38
39
|
|
39
40
|
ActiveRecord::Base.silence do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: air18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2012-09-
|
16
|
+
date: 2012-09-24 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: i18n
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/air18n/logging_helper.rb
|
154
154
|
- lib/air18n/mock_priority.rb
|
155
155
|
- lib/air18n/phrase.rb
|
156
|
+
- lib/air18n/phrase_revision.rb
|
156
157
|
- lib/air18n/phrase_screenshot.rb
|
157
158
|
- lib/air18n/phrase_translation.rb
|
158
159
|
- lib/air18n/prim_and_proper.rb
|
@@ -173,6 +174,7 @@ files:
|
|
173
174
|
- spec/factories.rb
|
174
175
|
- spec/lib/air18n/air18n_spec.rb
|
175
176
|
- spec/lib/air18n/backend_spec.rb
|
177
|
+
- spec/lib/air18n/phrase_spec.rb
|
176
178
|
- spec/lib/air18n/phrase_translation_spec.rb
|
177
179
|
- spec/lib/air18n/prim_and_proper_spec.rb
|
178
180
|
- spec/lib/air18n/pseudo_locales_spec.rb
|
@@ -207,6 +209,7 @@ test_files:
|
|
207
209
|
- spec/factories.rb
|
208
210
|
- spec/lib/air18n/air18n_spec.rb
|
209
211
|
- spec/lib/air18n/backend_spec.rb
|
212
|
+
- spec/lib/air18n/phrase_spec.rb
|
210
213
|
- spec/lib/air18n/phrase_translation_spec.rb
|
211
214
|
- spec/lib/air18n/prim_and_proper_spec.rb
|
212
215
|
- spec/lib/air18n/pseudo_locales_spec.rb
|