translate_acts_as_translatable_models 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translate_acts_as_translatable_models
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lasse Bunk
@@ -15,26 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-18 00:00:00 Z
18
+ date: 2012-05-19 00:00:00 Z
19
19
  dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: acts_as_translatable
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
32
- type: :runtime
33
- version_requirements: *id001
34
20
  - !ruby/object:Gem::Dependency
35
21
  name: bing_translator
36
22
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
38
24
  none: false
39
25
  requirements:
40
26
  - - ~>
@@ -46,8 +32,8 @@ dependencies:
46
32
  - 2
47
33
  version: 0.0.2
48
34
  type: :runtime
49
- version_requirements: *id002
50
- description: Ruby on Rails plugin to translate your acts_as_translatable models using Bing.
35
+ version_requirements: *id001
36
+ description: Ruby on Rails plugin for easy translation of your acts_as_translatable models.
51
37
  email: lassebunk@gmail.com
52
38
  executables: []
53
39
 
@@ -57,7 +43,6 @@ extra_rdoc_files: []
57
43
 
58
44
  files:
59
45
  - lib/railtie.rb
60
- - lib/tasks/acts_as_translatable_task.rake
61
46
  - lib/translate_acts_as_translatable_models.rb
62
47
  homepage: http://github.com/lassebunk/translate_acts_as_translatable_models
63
48
  licenses: []
@@ -91,6 +76,6 @@ rubyforge_project:
91
76
  rubygems_version: 1.8.21
92
77
  signing_key:
93
78
  specification_version: 3
94
- summary: Ruby on Rails plugin to translate your acts_as_translatable models using Bing.
79
+ summary: Ruby on Rails plugin for easy translation of your acts_as_translatable models.
95
80
  test_files: []
96
81
 
@@ -1,65 +0,0 @@
1
- require 'net/http'
2
- require 'rexml/document'
3
- require 'bing_translator'
4
-
5
- desc "Translate your YAML files using Bing."
6
- task :translate_acts_as_translatable_models => :environment do
7
- @class = ENV["class"]
8
- raise "need to specify class=Category or class=Category,Product" unless @class
9
-
10
- @from_locale = ENV["from"]
11
- raise "need to specify from=<locale>" unless @from_locale
12
-
13
- @to_locale = ENV["to"]
14
- raise "need to specify to=<locale>" unless @to_locale
15
-
16
- @force_translation = (ENV["force_translation"] == "true")
17
-
18
- @app_id = ENV["app_id"]
19
- raise "need to specify app_id=<Your Bing API key>" unless @app_id
20
-
21
- puts "Translating..."
22
-
23
- @class.split(",").each do |c|
24
- model = c.constantize
25
- model.enable_locale_fallbacks = false
26
-
27
- model.all.each do |record|
28
- model_translated = false
29
- model.translatable_fields.each do |field|
30
- source = record.send("#{field}_#{@from_locale}")
31
- dest = record.send("#{field}_#{@to_locale}")
32
-
33
- # only translate if not already translated
34
- if !source.blank? && (@force_translation || dest.blank?)
35
- dest = translate_string(source)
36
- puts "#{source} => #{dest}"
37
-
38
- unless dest.blank?
39
- record.send "#{field}_#{@to_locale}=", dest
40
- model_translated = true
41
- end
42
- end
43
- end
44
-
45
- # only save model if it has been translated
46
- if model_translated
47
- puts "Saving #{model}..."
48
- record.save
49
- end
50
- end
51
- end
52
-
53
- puts "Done!"
54
- end
55
-
56
- def translate_string(source)
57
- return "" unless source
58
-
59
- # translate using Microsoft Bing
60
- translator.translate(source, :from => @from_locale, :to => @to_locale)
61
- end
62
-
63
- def translator
64
- @translator ||= BingTranslator.new @app_id
65
- end