fastlane-plugin-translate_gpt 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 162ac503b51db5c9395059702dfeedca75cbcd3bb26f68702059f45eb4540ffc
|
4
|
+
data.tar.gz: d73722901b8e2d68c3287187687761930962e4392e7016847bfc9946d57c3748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b260653373ca72b56e753aad327338559eeb330e64e602f905720b12d8cb6e6c35d0c5750e8be8199169d41cc7549dc19cd4f30a19caf652465ce3a6d10f54b1
|
7
|
+
data.tar.gz: 21df8623e7bce11bf1c3658917dd498bd95929e77236dc32509ca8f3245c8491450cecee1996f2b40147e834aa2a76582facea074dcaa17b8e916a652e964193
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ fastlane add_plugin translate_gpt
|
|
15
15
|
|
16
16
|
## About translate-gpt
|
17
17
|
|
18
|
-
`translate-gpt` is a fastlane plugin that allows you to easily translate your iOS app's strings using the OpenAI GPT API.
|
18
|
+
`translate-gpt` is a fastlane plugin that allows you to easily translate your iOS and Android app's strings using the OpenAI GPT API.
|
19
19
|
|
20
20
|
|
21
21
|
## Features
|
@@ -50,8 +50,8 @@ The following options are available for `translate-gpt`:
|
|
50
50
|
| `skip_translated` | Whether to skip strings that have already been translated. Defaults to `true`. | `GPT_SKIP_TRANSLATED` |
|
51
51
|
| `source_language` | The source language of the strings to be translated. Defaults to auto-detection. | `GPT_SOURCE_LANGUAGE` |
|
52
52
|
| `target_language` | The target language of the translated strings. Required. | `GPT_TARGET_LANGUAGE` |
|
53
|
-
| `source_file` | The path to the `Localizable.strings` file to be translated.
|
54
|
-
| `target_file` | The path to the output file for the translated strings.
|
53
|
+
| `source_file` | The path to the `Localizable.strings` or `strings.xml` file to be translated. | `GPT_SOURCE_FILE` |
|
54
|
+
| `target_file` | The path to the output file for the translated strings. | `GPT_TARGET_FILE` |
|
55
55
|
| `context` | Common context for the translation | `GPT_COMMON_CONTEXT` |
|
56
56
|
|
57
57
|
## Providing context
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'fastlane/action'
|
2
2
|
require 'openai'
|
3
3
|
require_relative '../helper/translate_gpt_helper'
|
4
|
+
require 'loco_strings'
|
4
5
|
|
5
6
|
module Fastlane
|
6
7
|
module Actions
|
@@ -22,20 +23,27 @@ module Fastlane
|
|
22
23
|
|
23
24
|
UI.message "Translating #{to_translate.size} strings..."
|
24
25
|
|
25
|
-
to_translate.each_with_index do |(key,
|
26
|
-
prompt = "
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
26
|
+
to_translate.each_with_index do |(key, string), index|
|
27
|
+
prompt = "I want you to act as a translator for a mobile application strings. " + \
|
28
|
+
"You need to answer only with translation and nothing else. No commentaries. " + \
|
29
|
+
"Try to keep length of the translated text. " + \
|
30
|
+
"I will send you a text and you translate it from #{params[:source_language]} to #{params[:target_language]}. "
|
31
31
|
if params[:context] && !params[:context].empty?
|
32
|
-
prompt += "
|
32
|
+
prompt += "This app is #{params[:context]}. "
|
33
|
+
end
|
34
|
+
context = string.comment
|
35
|
+
if context && !context.empty?
|
36
|
+
prompt += "Additional context is #{context}. "
|
33
37
|
end
|
38
|
+
prompt += "Source text:\n#{string.value}"
|
39
|
+
|
34
40
|
# translate the source string to the target language
|
35
41
|
response = client.chat(
|
36
42
|
parameters: {
|
37
43
|
model: params[:model_name],
|
38
|
-
messages: [
|
44
|
+
messages: [
|
45
|
+
{ role: "user", content: prompt }
|
46
|
+
],
|
39
47
|
temperature: params[:temperature],
|
40
48
|
}
|
41
49
|
)
|
@@ -46,10 +54,11 @@ module Fastlane
|
|
46
54
|
else
|
47
55
|
target_string = response.dig("choices", 0, "message", "content")
|
48
56
|
if target_string && !target_string.empty?
|
49
|
-
UI.message "Translating #{key} - #{value} -> #{target_string}"
|
50
|
-
|
57
|
+
UI.message "Translating #{key} - #{string.value} -> #{target_string}"
|
58
|
+
string.value = target_string
|
59
|
+
output_hash[key] = string
|
51
60
|
else
|
52
|
-
UI.warning "Unable to translate #{key} - #{value}"
|
61
|
+
UI.warning "Unable to translate #{key} - #{string.value}"
|
53
62
|
end
|
54
63
|
end
|
55
64
|
if index < to_translate.size - 1
|
@@ -59,12 +68,12 @@ module Fastlane
|
|
59
68
|
|
60
69
|
UI.message "Writing #{output_hash.size} strings to #{params[:target_file]}..."
|
61
70
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
71
|
+
file = LocoStrings.load(params[:target_file])
|
72
|
+
file.read
|
73
|
+
output_hash.each do |key, value|
|
74
|
+
file.update(key, value.value, value.comment)
|
67
75
|
end
|
76
|
+
file.write
|
68
77
|
end
|
69
78
|
|
70
79
|
#####################################################
|
@@ -95,6 +104,7 @@ module Fastlane
|
|
95
104
|
key: :request_timeout,
|
96
105
|
env_name: "GPT_REQUEST_TIMEOUT",
|
97
106
|
description: "Timeout for the request in seconds",
|
107
|
+
type: Integer,
|
98
108
|
default_value: 30
|
99
109
|
),
|
100
110
|
FastlaneCore::ConfigItem.new(
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fastlane_core/ui/ui'
|
2
|
+
require 'loco_strings'
|
2
3
|
|
3
4
|
module Fastlane
|
4
5
|
UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
|
@@ -9,16 +10,8 @@ module Fastlane
|
|
9
10
|
# @param localization_file [String] The path to the strings file
|
10
11
|
# @return [Hash] The strings file as a hash
|
11
12
|
def self.get_strings(localization_file)
|
12
|
-
|
13
|
-
|
14
|
-
strings_hash = strings_file.split(/\n/).reduce({}) do |hash, line|
|
15
|
-
match = line.match(/^"(.+)" = "(.+)";$/)
|
16
|
-
if match
|
17
|
-
hash[match[1]] = match[2]
|
18
|
-
end
|
19
|
-
hash
|
20
|
-
end
|
21
|
-
return strings_hash
|
13
|
+
file = LocoStrings.load(localization_file)
|
14
|
+
return file.read
|
22
15
|
end
|
23
16
|
|
24
17
|
# Get the context associated with a localization key
|
@@ -26,20 +19,9 @@ module Fastlane
|
|
26
19
|
# @param localization_key [String] The localization key
|
27
20
|
# @return [String] The context associated with the localization key
|
28
21
|
def self.get_context(localization_file, localization_key)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
# search for the comments associated with the localization key
|
33
|
-
regex = /^\/\*(.+)\*\/\n"#{localization_key}"/
|
34
|
-
match = content.match(regex)
|
35
|
-
|
36
|
-
# return the comments, if found
|
37
|
-
if match && match.captures.size > 0
|
38
|
-
comments = match.captures[0].strip
|
39
|
-
return comments.gsub(/\n\s*\*\s?/, "\n").strip
|
40
|
-
else
|
41
|
-
return nil
|
42
|
-
end
|
22
|
+
file = LocoStrings.load(localization_file)
|
23
|
+
string = file.read[localization_key]
|
24
|
+
return string.comment
|
43
25
|
end
|
44
26
|
|
45
27
|
# Sleep for a specified number of seconds, displaying a progress bar
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastlane-plugin-translate_gpt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Cherepanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-openai
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: loco_strings
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.1
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -195,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
209
|
- !ruby/object:Gem::Version
|
196
210
|
version: '0'
|
197
211
|
requirements: []
|
198
|
-
rubygems_version: 3.4.
|
212
|
+
rubygems_version: 3.4.13
|
199
213
|
signing_key:
|
200
214
|
specification_version: 4
|
201
215
|
summary: This fastlane plugin provides an easy way to use the OpenAI GPT language
|