fastlane-plugin-translate_gpt 0.1.0 → 0.1.1
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: b7c0d621832f411e542d6c8dad89a1d3014a6d339d2d384d6f1c06af11263804
|
4
|
+
data.tar.gz: 5feaad22d9a7fdc77dc03420276ba2284946b381e760cdb49297634e51f4eb36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82b6bdab41b284e766cb3132e05ac232bcc67699d1f6dd1dca6bdfc944a439148d21d0938802a23fa7cc381ac691c705c077d0a97197b506f78039ab07d968a2
|
7
|
+
data.tar.gz: 90566f6958edcd137faa972a4aa7d3e96ea58ea9cb5fd9d17fa9f2aecf137bf1a3744ae7ee264d1380508aa182aef5be8c02b0532ab5b5825c83da3fa13cf5bf
|
data/README.md
CHANGED
@@ -52,6 +52,34 @@ The following options are available for `translate-gpt`:
|
|
52
52
|
| `target_language` | The target language of the translated strings. Required. | `GPT_TARGET_LANGUAGE` |
|
53
53
|
| `source_file` | The path to the `Localizable.strings` file to be translated. Defaults to `./Resources/Localizable.strings`. | `GPT_SOURCE_FILE` |
|
54
54
|
| `target_file` | The path to the output file for the translated strings. Defaults to `./Resources/Localizable.strings.<target_language>`. | `GPT_TARGET_FILE` |
|
55
|
+
| `context` | Common context for the translation | `GPT_COMMON_CONTEXT` |
|
56
|
+
|
57
|
+
## Providing context
|
58
|
+
|
59
|
+
The `TranslateGptAction` allows you to provide additional context for your translation requests in two ways:
|
60
|
+
|
61
|
+
### 1. Using a common context
|
62
|
+
|
63
|
+
You can provide a common context for your project that will be used in all translation requests. This can be done by setting the `common` property when calling the `TranslateGptAction`. The `common` property should be a string that describes the context of your project.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
translate_gpt(
|
67
|
+
target_language: 'fr',
|
68
|
+
common: "This is a mobile app for ordering food online"
|
69
|
+
)
|
70
|
+
```
|
71
|
+
|
72
|
+
### 2. Adding comments for specific keys
|
73
|
+
|
74
|
+
You can also add comments to your Localizable.strings file for specific keys. These comments will be included in the translation request for that key. To add a comment for a specific key, simply include a comment before the key in your Localizable.strings file.
|
75
|
+
|
76
|
+
```text
|
77
|
+
/* This is a comment for KEY1 */
|
78
|
+
"KEY1" = "Value for KEY1";
|
79
|
+
```
|
80
|
+
|
81
|
+
When you run the `TranslateGptAction`, the comment will be included in the translation request for `KEY1`.
|
82
|
+
|
55
83
|
|
56
84
|
## Authentication
|
57
85
|
|
@@ -20,14 +20,17 @@ module Fastlane
|
|
20
20
|
to_translate = input_hash
|
21
21
|
end
|
22
22
|
|
23
|
-
UI.message "Translating #{
|
23
|
+
UI.message "Translating #{to_translate.size} strings..."
|
24
24
|
|
25
|
-
to_translate.
|
26
|
-
prompt = "Translate the following string from #{params[:source_language]} to #{params[:target_language]}
|
25
|
+
to_translate.each_with_index do |(key, value), index|
|
26
|
+
prompt = "Translate the following string from #{params[:source_language]} to #{params[:target_language]}: #{value}"
|
27
27
|
context = Helper::TranslateGptHelper.get_context(params[:source_file], key)
|
28
28
|
if context && !context.empty?
|
29
29
|
prompt += "\n\nAdditional context:\n#{context}"
|
30
30
|
end
|
31
|
+
if params[:context] && !params[:context].empty?
|
32
|
+
prompt += "\n\nCommon context:\n#{params[:context]}"
|
33
|
+
end
|
31
34
|
# translate the source string to the target language
|
32
35
|
response = client.chat(
|
33
36
|
parameters: {
|
@@ -36,7 +39,6 @@ module Fastlane
|
|
36
39
|
temperature: params[:temperature],
|
37
40
|
}
|
38
41
|
)
|
39
|
-
#puts response
|
40
42
|
# extract the translated string from the response
|
41
43
|
error = response.dig("error", "message")
|
42
44
|
if error
|
@@ -50,7 +52,9 @@ module Fastlane
|
|
50
52
|
UI.warning "Unable to translate #{key} - #{value}"
|
51
53
|
end
|
52
54
|
end
|
53
|
-
|
55
|
+
if index < to_translate.size - 1
|
56
|
+
Helper::TranslateGptHelper.timeout params[:request_timeout]
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
60
|
UI.message "Writing #{output_hash.size} strings to #{params[:target_file]}..."
|
@@ -138,7 +142,14 @@ module Fastlane
|
|
138
142
|
UI.user_error!("Invalid file path: #{value}") unless File.exist?(value)
|
139
143
|
UI.user_error!("Translation file must have .strings extension") unless File.extname(value) == ".strings"
|
140
144
|
end
|
141
|
-
),
|
145
|
+
),
|
146
|
+
FastlaneCore::ConfigItem.new(
|
147
|
+
key: :context,
|
148
|
+
env_name: "GPT_COMMON_CONTEXT",
|
149
|
+
description: "Common context for the translation",
|
150
|
+
optional: true,
|
151
|
+
type: String
|
152
|
+
)
|
142
153
|
]
|
143
154
|
end
|
144
155
|
|
@@ -30,7 +30,7 @@ module Fastlane
|
|
30
30
|
content = File.read(localization_file)
|
31
31
|
|
32
32
|
# search for the comments associated with the localization key
|
33
|
-
regex =
|
33
|
+
regex = /^\/\*(.+)\*\/\n"#{localization_key}"/
|
34
34
|
match = content.match(regex)
|
35
35
|
|
36
36
|
# return the comments, if found
|