air18n 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -234,8 +234,9 @@ module Air18n
234
234
  end
235
235
  end
236
236
  if store_default
237
- phrase = Phrase.find_or_create_by_key(key)
238
- if phrase
237
+ phrase = Phrase.where(:key => key).first
238
+ if phrase.present?
239
+ # A phrase with this key already exists; change its default text.
239
240
  if (overrides_previous_default && phrase.value != default) ||
240
241
  (!overrides_previous_default && phrase.value != default && phrase.value.blank?)
241
242
  phrase.value = default
@@ -249,6 +250,9 @@ module Air18n
249
250
  # again to create it next time automatically.
250
251
  end
251
252
  end
253
+ else
254
+ # Create the phrase for the first time.
255
+ Phrase.create(:key => key, :value => default)
252
256
  end
253
257
 
254
258
  @translation_data[locale][key] = default
@@ -59,14 +59,12 @@ module Air18n
59
59
  -pt.locale.to_s.size
60
60
  end
61
61
  translations_with_language_last.each do |pt|
62
- PhraseTranslation.create_translation(
63
- self.id,
64
- self.key,
65
- pt.locale,
66
- pt.value,
67
- 0, # user ID: 0 means automated
68
- false, # do xss check? no
69
- false # allow verification? no
62
+ PhraseTranslation.create(
63
+ :user_id => 0, # 0 means Automated
64
+ :phrase => self,
65
+ :key => self.key,
66
+ :locale => pt.locale,
67
+ :value => pt.value
70
68
  )
71
69
  end
72
70
  end
@@ -1,3 +1,3 @@
1
1
  module Air18n
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -52,6 +52,8 @@ describe Air18n::Phrase do
52
52
 
53
53
  # Should have three translations auto-populated.
54
54
  @phrase2.phrase_translations.size.should == 3
55
+ @phrase2.phrase_translations.first.phrase_id.should == @phrase2.id
56
+ @phrase2.phrase_translations.first.user_id.should == 0
55
57
 
56
58
  @phrase2.latest_translation(:"zh-TW").id.should < @phrase2.latest_translation(:zh).id
57
59
  end
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.4.2
4
+ version: 0.4.3
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: 2013-03-25 00:00:00.000000000 Z
16
+ date: 2013-03-26 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: i18n