lara-sdk 1.8.0 → 1.9.1
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.
- checksums.yaml +4 -4
- data/lib/lara/client.rb +11 -0
- data/lib/lara/images.rb +26 -2
- data/lib/lara/models/glossaries.rb +5 -2
- data/lib/lara/models/images.rb +89 -6
- data/lib/lara/models/memories.rb +5 -2
- data/lib/lara/models/shares.rb +4 -3
- data/lib/lara/models/text.rb +5 -2
- data/lib/lara/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 370e00f8aea75a62aaa75afe314ccdac0917176902accfdeed31742b83cb1fdd
|
|
4
|
+
data.tar.gz: 251d5fb842d8aae2a055fd3705ac1af73def99396b342610accc07224e3f0569
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 006a24cc826bd26ddef6f73ff54f1721d8fa45f21358b51bab6a502c824ac2313f4c2ee38cc2ca8dd83952df8f961d8b9ce082aa6b0fb5e8c93867c9b5e978ce
|
|
7
|
+
data.tar.gz: e48c25fc3d1207010b55051516e1c50b83532127fdc57cbd11752680a973348557e78b5345a70fa856e43913bfca0cd87d437004361611f8b4212a3e8857321d
|
data/lib/lara/client.rb
CHANGED
|
@@ -92,6 +92,15 @@ module Lara
|
|
|
92
92
|
|
|
93
93
|
def request(method, path, body: nil, files: nil, headers: nil, params: nil,
|
|
94
94
|
raw_response: false, &callback)
|
|
95
|
+
file_positions = (files || {}).each_with_object({}) do |(name, file), positions|
|
|
96
|
+
next unless file.respond_to?(:pos) && file.respond_to?(:seek)
|
|
97
|
+
|
|
98
|
+
begin
|
|
99
|
+
positions[name] = file.pos
|
|
100
|
+
rescue IOError, SystemCallError
|
|
101
|
+
# Non-seekable uploads can still be sent once.
|
|
102
|
+
end
|
|
103
|
+
end
|
|
95
104
|
ensure_valid_token
|
|
96
105
|
|
|
97
106
|
make_request(method, path, body: body, files: files, headers: headers, params: params,
|
|
@@ -100,6 +109,8 @@ module Lara
|
|
|
100
109
|
raise unless e.status_code == 401
|
|
101
110
|
|
|
102
111
|
@auth_mutex.synchronize { refresh_or_reauthenticate }
|
|
112
|
+
# Multipart encoding consumed the files; replay their original bytes.
|
|
113
|
+
file_positions.each { |name, position| files[name].seek(position) }
|
|
103
114
|
make_request(method, path, body: body, files: files, headers: headers, params: params,
|
|
104
115
|
raw_response: raw_response, &callback)
|
|
105
116
|
end
|
data/lib/lara/images.rb
CHANGED
|
@@ -46,10 +46,12 @@ module Lara
|
|
|
46
46
|
# @param glossaries [Array<String>, nil] Glossary IDs to apply.
|
|
47
47
|
# @param style [String, nil] Translation style ("faithful", "fluid", "creative").
|
|
48
48
|
# @param verbose [Boolean] If true, includes match details in the response.
|
|
49
|
+
# @param include_layout [Boolean] When true, includes complete geometry and styling on every
|
|
50
|
+
# paragraph independently of verbose.
|
|
49
51
|
# @param no_trace [Boolean] If true, disables request tracing.
|
|
50
52
|
# @return [Lara::Models::ImageTextResult]
|
|
51
53
|
def translate_text(file_path:, target:, source: nil, adapt_to: nil, glossaries: nil,
|
|
52
|
-
style: nil, verbose: false, no_trace: false)
|
|
54
|
+
style: nil, verbose: false, no_trace: false, include_layout: false)
|
|
53
55
|
image_upload = Faraday::Multipart::FilePart.new(file_path, mime_type_for(file_path))
|
|
54
56
|
|
|
55
57
|
body = {
|
|
@@ -58,7 +60,8 @@ module Lara
|
|
|
58
60
|
adapt_to: adapt_to&.to_json,
|
|
59
61
|
glossaries: glossaries&.to_json,
|
|
60
62
|
style: style,
|
|
61
|
-
verbose: verbose.to_s
|
|
63
|
+
verbose: verbose.to_s,
|
|
64
|
+
include_layout: include_layout.to_s
|
|
62
65
|
}.compact
|
|
63
66
|
|
|
64
67
|
headers = {}
|
|
@@ -69,6 +72,27 @@ module Lara
|
|
|
69
72
|
Lara::Models::ImageTextResult.from_hash(result)
|
|
70
73
|
end
|
|
71
74
|
|
|
75
|
+
# Renders supplied translations onto the original image without translating again.
|
|
76
|
+
# Overlay and inpainting require ImageLayoutParagraph instances. Generative models
|
|
77
|
+
# accept either ImageParagraph or ImageLayoutParagraph. An omitted model defaults
|
|
78
|
+
# to generative_fast.
|
|
79
|
+
# @param paragraphs [Array<Lara::Models::ImageParagraph>] Text and translations to render.
|
|
80
|
+
# @return [String] Binary image data.
|
|
81
|
+
def render_translated(file_path:, target:, paragraphs:, source: nil, model: nil, no_trace: false)
|
|
82
|
+
image_upload = Faraday::Multipart::FilePart.new(file_path, mime_type_for(file_path))
|
|
83
|
+
body = {
|
|
84
|
+
source: source,
|
|
85
|
+
target: target,
|
|
86
|
+
paragraphs: paragraphs.map(&:to_render_hash).to_json,
|
|
87
|
+
model: model
|
|
88
|
+
}.compact
|
|
89
|
+
headers = {}
|
|
90
|
+
headers["X-No-Trace"] = "true" if no_trace
|
|
91
|
+
|
|
92
|
+
@client.post("/v2/images/render-translated", body: body, files: { image: image_upload },
|
|
93
|
+
headers: headers, raw_response: true)
|
|
94
|
+
end
|
|
95
|
+
|
|
72
96
|
private
|
|
73
97
|
|
|
74
98
|
def mime_type_for(file_path)
|
|
@@ -5,10 +5,10 @@ require_relative "base"
|
|
|
5
5
|
module Lara
|
|
6
6
|
module Models
|
|
7
7
|
class Glossary < Base
|
|
8
|
-
attr_reader :id, :name, :owner_id, :created_at, :updated_at, :shared_at, :is_personal
|
|
8
|
+
attr_reader :id, :name, :owner_id, :created_at, :updated_at, :shared_at, :is_personal, :permission_mask
|
|
9
9
|
|
|
10
10
|
def initialize(id:, name:, owner_id:, created_at: nil, updated_at: nil, shared_at: nil,
|
|
11
|
-
is_personal: nil, **_kwargs)
|
|
11
|
+
is_personal: nil, permission_mask: nil, **_kwargs)
|
|
12
12
|
super()
|
|
13
13
|
@id = id
|
|
14
14
|
@name = name
|
|
@@ -18,6 +18,9 @@ module Lara
|
|
|
18
18
|
@shared_at = Base.parse_time(shared_at)
|
|
19
19
|
# The API sends is_personal: true and omits the key otherwise; it never sends false or null.
|
|
20
20
|
@is_personal = is_personal || false
|
|
21
|
+
# Effective combined mask in GET list/detail; selected share's stored mask in GET /shares.
|
|
22
|
+
# Nil when omitted, including non-GET responses.
|
|
23
|
+
@permission_mask = permission_mask
|
|
21
24
|
end
|
|
22
25
|
end
|
|
23
26
|
|
data/lib/lara/models/images.rb
CHANGED
|
@@ -18,6 +18,51 @@ module Lara
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
# Four corners, each an [x, y] pair of pixel coordinates.
|
|
22
|
+
class ImageBBox < Base
|
|
23
|
+
attr_reader :top_left, :top_right, :bottom_right, :bottom_left
|
|
24
|
+
|
|
25
|
+
def initialize(top_left:, top_right:, bottom_right:, bottom_left:)
|
|
26
|
+
super()
|
|
27
|
+
@top_left = top_left
|
|
28
|
+
@top_right = top_right
|
|
29
|
+
@bottom_right = bottom_right
|
|
30
|
+
@bottom_left = bottom_left
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.from_hash(hash)
|
|
34
|
+
new(top_left: hash["top_left"] || hash["topLeft"],
|
|
35
|
+
top_right: hash["top_right"] || hash["topRight"],
|
|
36
|
+
bottom_right: hash["bottom_right"] || hash["bottomRight"],
|
|
37
|
+
bottom_left: hash["bottom_left"] || hash["bottomLeft"])
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_render_hash
|
|
41
|
+
{ top_left: top_left, top_right: top_right, bottom_right: bottom_right, bottom_left: bottom_left }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Original text direction (ltr, rtl, or ttb) and colors.
|
|
46
|
+
class ImageTextInfo < Base
|
|
47
|
+
attr_reader :direction, :text_color, :background_color
|
|
48
|
+
|
|
49
|
+
def initialize(direction:, text_color:, background_color:)
|
|
50
|
+
super()
|
|
51
|
+
@direction = direction
|
|
52
|
+
@text_color = text_color
|
|
53
|
+
@background_color = background_color
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def self.from_hash(hash)
|
|
57
|
+
new(direction: hash["direction"], text_color: hash["text_color"] || hash["textColor"],
|
|
58
|
+
background_color: hash["background_color"] || hash["backgroundColor"])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def to_render_hash
|
|
62
|
+
{ direction: direction, text_color: text_color, background_color: background_color }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
21
66
|
class ImageParagraph < Base
|
|
22
67
|
attr_reader :text, :translation, :adapted_to_matches, :glossaries_matches
|
|
23
68
|
|
|
@@ -28,6 +73,29 @@ module Lara
|
|
|
28
73
|
@adapted_to_matches = adapted_to_matches
|
|
29
74
|
@glossaries_matches = glossaries_matches
|
|
30
75
|
end
|
|
76
|
+
|
|
77
|
+
def to_render_hash
|
|
78
|
+
{ text: text, translation: translation }
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class ImageLayoutParagraph < ImageParagraph
|
|
83
|
+
attr_reader :bbox, :lines_bboxes, :text_info, :alignment
|
|
84
|
+
|
|
85
|
+
def initialize(text:, translation:, bbox:, lines_bboxes:, text_info:, alignment:,
|
|
86
|
+
adapted_to_matches: nil, glossaries_matches: nil)
|
|
87
|
+
super(text: text, translation: translation, adapted_to_matches: adapted_to_matches,
|
|
88
|
+
glossaries_matches: glossaries_matches)
|
|
89
|
+
@bbox = bbox
|
|
90
|
+
@lines_bboxes = lines_bboxes
|
|
91
|
+
@text_info = text_info
|
|
92
|
+
@alignment = alignment
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def to_render_hash
|
|
96
|
+
super.merge(bbox: bbox.to_render_hash, lines_bboxes: lines_bboxes.map(&:to_render_hash),
|
|
97
|
+
text_info: text_info.to_render_hash, alignment: alignment)
|
|
98
|
+
end
|
|
31
99
|
end
|
|
32
100
|
|
|
33
101
|
class ImageTextResult < Base
|
|
@@ -39,8 +107,8 @@ module Lara
|
|
|
39
107
|
paragraphs = (hash["paragraphs"] || []).map { |p| build_paragraph(p) }
|
|
40
108
|
|
|
41
109
|
new(
|
|
42
|
-
source_language: hash["sourceLanguage"],
|
|
43
|
-
adapted_to: hash["adaptedTo"],
|
|
110
|
+
source_language: hash["source_language"] || hash["sourceLanguage"],
|
|
111
|
+
adapted_to: hash["adapted_to"] || hash["adaptedTo"],
|
|
44
112
|
glossaries: hash["glossaries"],
|
|
45
113
|
paragraphs: paragraphs
|
|
46
114
|
)
|
|
@@ -50,15 +118,30 @@ module Lara
|
|
|
50
118
|
private
|
|
51
119
|
|
|
52
120
|
def build_paragraph(paragraph_hash)
|
|
53
|
-
adapted_to_matches = convert_matches(
|
|
54
|
-
|
|
121
|
+
adapted_to_matches = convert_matches(
|
|
122
|
+
paragraph_hash["adapted_to_matches"] || paragraph_hash["adaptedToMatches"], NGMemoryMatch
|
|
123
|
+
)
|
|
124
|
+
glossaries_matches = convert_matches(
|
|
125
|
+
paragraph_hash["glossaries_matches"] || paragraph_hash["glossariesMatches"], NGGlossaryMatch
|
|
126
|
+
)
|
|
55
127
|
|
|
56
|
-
|
|
128
|
+
attributes = {
|
|
57
129
|
text: paragraph_hash["text"],
|
|
58
130
|
translation: paragraph_hash["translation"],
|
|
59
131
|
adapted_to_matches: adapted_to_matches,
|
|
60
132
|
glossaries_matches: glossaries_matches
|
|
61
|
-
|
|
133
|
+
}
|
|
134
|
+
bbox = paragraph_hash["bbox"]
|
|
135
|
+
lines_bboxes = paragraph_hash["lines_bboxes"] || paragraph_hash["linesBboxes"]
|
|
136
|
+
text_info = paragraph_hash["text_info"] || paragraph_hash["textInfo"]
|
|
137
|
+
alignment = paragraph_hash["alignment"]
|
|
138
|
+
if bbox && lines_bboxes && text_info && alignment
|
|
139
|
+
ImageLayoutParagraph.new(**attributes, bbox: ImageBBox.from_hash(bbox),
|
|
140
|
+
lines_bboxes: lines_bboxes.map { |box| ImageBBox.from_hash(box) },
|
|
141
|
+
text_info: ImageTextInfo.from_hash(text_info), alignment: alignment)
|
|
142
|
+
else
|
|
143
|
+
ImageParagraph.new(**attributes)
|
|
144
|
+
end
|
|
62
145
|
end
|
|
63
146
|
|
|
64
147
|
def convert_matches(value, klass)
|
data/lib/lara/models/memories.rb
CHANGED
|
@@ -6,11 +6,11 @@ module Lara
|
|
|
6
6
|
module Models
|
|
7
7
|
class Memory < Base
|
|
8
8
|
attr_reader :id, :created_at, :updated_at, :name, :external_id, :secret,
|
|
9
|
-
:owner_id, :collaborators_count, :shared_at, :is_personal
|
|
9
|
+
:owner_id, :collaborators_count, :shared_at, :is_personal, :permission_mask
|
|
10
10
|
|
|
11
11
|
def initialize(id:, name:, owner_id:, created_at: nil, updated_at: nil,
|
|
12
12
|
external_id: nil, secret: nil, collaborators_count: nil, shared_at: nil,
|
|
13
|
-
is_personal: nil, **_kwargs)
|
|
13
|
+
is_personal: nil, permission_mask: nil, **_kwargs)
|
|
14
14
|
super()
|
|
15
15
|
@id = id
|
|
16
16
|
@name = name
|
|
@@ -23,6 +23,9 @@ module Lara
|
|
|
23
23
|
@shared_at = Base.parse_time(shared_at)
|
|
24
24
|
# The API sends is_personal: true and omits the key otherwise; it never sends false or null.
|
|
25
25
|
@is_personal = is_personal || false
|
|
26
|
+
# Effective combined mask in GET list/detail; selected share's stored mask in GET /shares.
|
|
27
|
+
# Nil when omitted, including non-GET responses.
|
|
28
|
+
@permission_mask = permission_mask
|
|
26
29
|
end
|
|
27
30
|
end
|
|
28
31
|
|
data/lib/lara/models/shares.rb
CHANGED
|
@@ -5,15 +5,16 @@ require_relative "base"
|
|
|
5
5
|
module Lara
|
|
6
6
|
module Models
|
|
7
7
|
class ResourceShareEntry < Base
|
|
8
|
-
attr_reader :id, :name, :share_name, :shared_at, :
|
|
8
|
+
attr_reader :id, :name, :share_name, :shared_at, :permission_mask
|
|
9
9
|
|
|
10
|
-
def initialize(id:, name:, share_name:, shared_at:,
|
|
10
|
+
def initialize(id:, name:, share_name:, shared_at:, permission_mask:, **_kwargs)
|
|
11
11
|
super()
|
|
12
12
|
@id = id
|
|
13
13
|
@name = name
|
|
14
14
|
@share_name = share_name
|
|
15
15
|
@shared_at = Base.parse_time(shared_at)
|
|
16
|
-
|
|
16
|
+
# The permissions stored on this share.
|
|
17
|
+
@permission_mask = permission_mask
|
|
17
18
|
end
|
|
18
19
|
end
|
|
19
20
|
|
data/lib/lara/models/text.rb
CHANGED
|
@@ -115,10 +115,10 @@ module Lara
|
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
class Styleguide < Base
|
|
118
|
-
attr_reader :id, :name, :content, :owner_id, :created_at, :updated_at, :shared_at, :is_personal
|
|
118
|
+
attr_reader :id, :name, :content, :owner_id, :created_at, :updated_at, :shared_at, :is_personal, :permission_mask
|
|
119
119
|
|
|
120
120
|
def initialize(id:, name:, content: nil, owner_id: nil, created_at: nil, updated_at: nil,
|
|
121
|
-
shared_at: nil, is_personal: nil, **_kwargs)
|
|
121
|
+
shared_at: nil, is_personal: nil, permission_mask: nil, **_kwargs)
|
|
122
122
|
super()
|
|
123
123
|
@id = id
|
|
124
124
|
@name = name
|
|
@@ -129,6 +129,9 @@ module Lara
|
|
|
129
129
|
@shared_at = Base.parse_time(shared_at)
|
|
130
130
|
# The API sends is_personal: true and omits the key otherwise; it never sends false or null.
|
|
131
131
|
@is_personal = is_personal || false
|
|
132
|
+
# Effective combined mask in GET list/detail; selected share's stored mask in GET /shares.
|
|
133
|
+
# Nil when omitted, including non-GET responses.
|
|
134
|
+
@permission_mask = permission_mask
|
|
132
135
|
end
|
|
133
136
|
|
|
134
137
|
def to_s
|
data/lib/lara/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lara-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.9.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Translated
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-10-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|