linguara 0.0.6 → 0.0.7
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.
- data/VERSION +1 -1
- data/lib/linguara.rb +19 -9
- data/lib/linguara/translation.rb +8 -8
- data/lib/linguara/utils.rb +32 -0
- data/linguara.gemspec +2 -2
- data/spec/linguara_spec.rb +1 -7
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/linguara.rb
CHANGED
@@ -18,16 +18,26 @@ module Linguara
|
|
18
18
|
yield(configuration)
|
19
19
|
end
|
20
20
|
|
21
|
-
# Use this method in your controller to
|
22
|
-
def accept_translation(
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
# Use this method in your controller to accept and save incoming translations
|
22
|
+
def accept_translation(body, params)
|
23
|
+
#raise ActiveRecord::StatementInvalid, 'Authorization data is missing or invalid' #TODO
|
24
|
+
raise 'Malformed request body' if params[:translation].blank?
|
25
|
+
target_language = params[:translation][:target_language]
|
26
|
+
|
27
|
+
doc = Nokogiri::XML(body)
|
28
|
+
|
29
|
+
paragraphs = doc.xpath('/translation/completed_translation/content/paragraph')
|
30
|
+
paragraphs.each do |p|
|
31
|
+
log("DOC: #{p.attribute('id')} --- #{p.inner_html}")
|
32
|
+
key = p.attribute('id').to_s
|
33
|
+
value = p.inner_html.to_s
|
34
|
+
|
35
|
+
linguara_name, class_name,id,order,field_name = key.split('_')
|
26
36
|
original_locale = I18n.locale
|
27
37
|
element = class_name.constantize.find(id)
|
28
38
|
|
29
39
|
I18n.locale = target_language
|
30
|
-
element.send("#{field_name}=", value.gsub(/<p>(.*?)<\/p>/, "\\1\n") )
|
40
|
+
element.send("#{field_name}=", value.gsub(/<p>(.*?)<\/p>/, "\\1\n") ).gsub(/<br {0,1}\/{0,1}>/, "\n")
|
31
41
|
element.save(false)
|
32
42
|
I18n.locale = original_locale
|
33
43
|
end
|
@@ -49,19 +59,19 @@ module Linguara
|
|
49
59
|
# Sends languages request
|
50
60
|
def send_languages_request(options={})
|
51
61
|
url= URI.parse("#{Linguara.configuration.server_path}api/languages.xml")
|
52
|
-
send_linguara_request(url, :get)
|
62
|
+
send_linguara_request(url, :get, options_to_xml(options))
|
53
63
|
end
|
54
64
|
|
55
65
|
# Sends specializations request
|
56
66
|
def send_specializations_request(options = {})
|
57
67
|
url= URI.parse("#{Linguara.configuration.server_path}api/specializations.xml")
|
58
|
-
send_linguara_request(url, :get)
|
68
|
+
send_linguara_request(url, :get, options_to_xml(options))
|
59
69
|
end
|
60
70
|
|
61
71
|
# Sends translators request
|
62
72
|
def send_translators_request(options = {})
|
63
73
|
url= URI.parse("#{Linguara.configuration.server_path}api/translators.xml")
|
64
|
-
send_linguara_request(url, :get)
|
74
|
+
send_linguara_request(url, :get, options_to_xml(options))
|
65
75
|
end
|
66
76
|
|
67
77
|
def available_languages
|
data/lib/linguara/translation.rb
CHANGED
@@ -3,10 +3,9 @@ class Translation
|
|
3
3
|
attr_accessor :translation_hash, :element
|
4
4
|
|
5
5
|
def initialize(element,options = {})
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
6
|
+
options[:translation] ||= {}
|
7
|
+
options[:translation][:due_date] ||= Date.today + Linguara.configuration.request_valid_for.to_i.days unless Linguara.configuration.request_valid_for.blank?
|
8
|
+
options[:translation][:due_date] ||= Date.today + 1.month
|
10
9
|
options[:return_url] ||= Linguara.configuration.return_url
|
11
10
|
options[:source_language] ||= I18n.locale.to_s
|
12
11
|
self.element = element#.fields_to_send
|
@@ -15,7 +14,7 @@ class Translation
|
|
15
14
|
|
16
15
|
def to_hash
|
17
16
|
ret = {}
|
18
|
-
ret[:
|
17
|
+
ret[:request] = self.translation_hash
|
19
18
|
ret
|
20
19
|
end
|
21
20
|
|
@@ -23,14 +22,14 @@ class Translation
|
|
23
22
|
builder_options[:indent] ||= 2
|
24
23
|
xml = builder_options[:builder] ||= Builder::XmlMarkup.new(:indent => builder_options[:indent])
|
25
24
|
xml.instruct! unless builder_options[:skip_instruct]
|
26
|
-
xml.
|
25
|
+
xml.request do
|
27
26
|
self.translation_hash.merge(options).each_pair do |k, v|
|
28
27
|
next if k.blank? or v.blank?
|
29
28
|
tag_element(xml, k, v)
|
30
29
|
end
|
31
|
-
xml.content :type => '
|
30
|
+
xml.content :type => 'html' do
|
32
31
|
self.element.fields_to_send.each_pair do |k, v|
|
33
|
-
xml.paragraph
|
32
|
+
xml.paragraph(:id => k) {|x| x << v}
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -40,6 +39,7 @@ class Translation
|
|
40
39
|
|
41
40
|
def to_xml_recursive(xml, object)
|
42
41
|
object.each_pair do |k, v|
|
42
|
+
next if k.blank? or v.blank?
|
43
43
|
tag_element(xml, k, v)
|
44
44
|
end
|
45
45
|
end
|
data/lib/linguara/utils.rb
CHANGED
@@ -5,5 +5,37 @@ module Linguara
|
|
5
5
|
data = data.each_pair { |k,v| v.is_a?(Hash) ? (strip_blank_attributes(v)) : (v) }
|
6
6
|
data.delete_if { |k,v| v.blank?}
|
7
7
|
end
|
8
|
+
|
9
|
+
def options_to_xml(options)
|
10
|
+
return '' if options.blank?
|
11
|
+
xml = Builder::XmlMarkup.new
|
12
|
+
xml.request do
|
13
|
+
options.each_pair do |k, v|
|
14
|
+
next if k.blank? or v.blank?
|
15
|
+
tag_element(xml, k, v)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
return xml.target!
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def options_to_xml_recursive(xml, object)
|
24
|
+
object.each_pair do |k, v|
|
25
|
+
next if k.blank? or v.blank?
|
26
|
+
tag_element(xml, k, v)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def tag_element(builder, k, v)
|
31
|
+
if v.kind_of?(Hash)
|
32
|
+
builder.tag!(k) do
|
33
|
+
options_to_xml_recursive(builder, v)
|
34
|
+
end
|
35
|
+
else
|
36
|
+
builder.tag!(k, v)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
8
40
|
end
|
9
41
|
end
|
data/linguara.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{linguara}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aleksander Dabrowski", "Piotr Barczuk"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-24}
|
13
13
|
s.description = %q{Gem to integrate with linguara api}
|
14
14
|
s.email = %q{aleks@kumulator.pl}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/linguara_spec.rb
CHANGED
@@ -18,13 +18,7 @@ describe "Linguara" do
|
|
18
18
|
blog_post.save
|
19
19
|
id = blog_post.id
|
20
20
|
lambda {
|
21
|
-
Linguara.accept_translation(
|
22
|
-
:paragraphs => {
|
23
|
-
"BlogPost_#{id}_0_title" => "Hello World!",
|
24
|
-
"BlogPost_#{id}_1_body" => "Today is great weather, and I am going to EuRuKo."
|
25
|
-
},
|
26
|
-
:source_language =>"pl",
|
27
|
-
:target_language =>"en"
|
21
|
+
Linguara.accept_translation("<translation><completed_translation><content><paragraph id='linguara_BlogPost_#{id}_0_body'>Today is great weather, and I am going to EuRuKo.</paragraph><paragraph id='linguara_BlogPost_#{id}_0_title'>Hello World!</paragraph></content></completed_translation></translation>", {:translation => { :source_language =>"pl", :target_language =>"en"}}
|
28
22
|
)
|
29
23
|
}.should change(BlogPost, :count).by(0)
|
30
24
|
translation = BlogPost.last
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linguara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aleksander Dabrowski
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-08-
|
19
|
+
date: 2010-08-24 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|