translate_acts_as_translatable_models 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
  require 'rexml/document'
3
3
  require 'bing_translator'
4
+ require 'htmlentities'
4
5
 
5
6
  desc "Translate your YAML files using Bing."
6
7
  task :translate_acts_as_translatable_models => :environment do
@@ -14,11 +15,14 @@ task :translate_acts_as_translatable_models => :environment do
14
15
  raise "need to specify to=<locale>" unless @to_locale
15
16
 
16
17
  @force_translation = (ENV["force_translation"] == "true")
18
+ @strip_html = (ENV["strip_html"] == "true")
17
19
 
18
20
  @app_id = ENV["app_id"]
19
21
  raise "need to specify app_id=<Your Bing API key>" unless @app_id
20
22
 
21
23
  puts "Translating..."
24
+
25
+ coder = HTMLEntities.new
22
26
 
23
27
  @class.split(",").each do |c|
24
28
  model = c.constantize
@@ -28,6 +32,7 @@ task :translate_acts_as_translatable_models => :environment do
28
32
  model_translated = false
29
33
  model.translatable_fields.each do |field|
30
34
  source = record.send("#{field}_#{@from_locale}")
35
+ source = corder.decode(source) if !source.blank? && @strip_html
31
36
  dest = record.send("#{field}_#{@to_locale}")
32
37
 
33
38
  # only translate if not already translated
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lasse Bunk
@@ -47,6 +47,20 @@ dependencies:
47
47
  version: 0.0.2
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: htmlentities
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :runtime
63
+ version_requirements: *id003
50
64
  description: Ruby on Rails plugin for easy translation of your acts_as_translatable models.
51
65
  email: lassebunk@gmail.com
52
66
  executables: []